Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I do not know if this is the optimal solution but what I would do is create a new class of board the board would be a collection of "cells" each cell would contain a pointer to each of it's neighboring cell (or null if the cell is on a edge). You could implement some iterators on the board class that would walk the cells.</p> <p>You would have to treat it more like a List instead of a vector. But it is at least a start.</p> <hr> <p>Another solution is set you board up like this <a href="http://img833.imageshack.us/img833/4739/hexgame11x11.gif" rel="nofollow noreferrer">alt text http://img833.imageshack.us/img833/4739/hexgame11x11.gif</a></p> <p>and still just use the [,] to access each cell but it will take a little more math to figure out if you are traversing cells (Up Right is [+1,-1], Right is [+1,0], Down Right is [0,+1], Down Left is [-1,+1], Left is [-1,0], Up Left is [0,-1])</p> <p><strong>EDIT</strong></p> <p>If you want vertical walls instead of a slant just take make your width(X) equal X + Y*2 then on each row make the current row number (y) and make the cells 0 to Y-y and X-y to X off limits.</p> <p>Example:</p> <pre><code>const int X = 10; const int Y = 10; int grid[,] = new int[X+(2*Y), Y]; bool IsCellOffLimits(int x, int y) { return (x &lt; Y-y || x &gt; X-y || y &lt; 0 || y &gt; Y); } </code></pre> <p>you waste a little memory space but it gives you a board like this <a href="http://img192.imageshack.us/img192/5580/gridw.png" rel="nofollow noreferrer">alt text http://img192.imageshack.us/img192/5580/gridw.png</a></p> <p>If you are Very Clever© you can just use the normal space but just have your code have anything in that Y-y or X-y range be on the opposite side of the board. But ill leave that code up to the reader.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload