[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: computer-go: Sharing Go modules
Well here is number 4 (a variant) :-)
> The coordinate coding method that I use is X,Y converts to X+Y*20. The
> arrays are all 421 long where all te points at 0,Y and X,0 contain special
> values to make it easy to detect the edge of the board. This is a convenient
> coding since it's still fairly easy to see which coordinates they represent
> (for example: 63 is 3,3 and 356 is 16,17). However I do realise that every
> Go programmmer has their own idea of how this should be done and that
> there's little chance that I can convince everyone in the world to use this
> scheme (that would be nice though <grin>) instead of using separate X and Y
> coordinates.
I use the same way of accessing an one-dimensional array except that
I have two layers of border data, because I once thought that i would
need to access a points two spaces away from a given point without
having to check any boundaries.
In practice I almost never do that (I only look at points one space
away) so every array I use in my program spends a lot of memory (and
since all my array big enough to hold 21x21 boards they are rather
large).
The only drawback I have experienced is in patternmatching - because
the way I do it is necessary to work with x,y coordinates, and check
for boundaries.
I also often uses bitmaps to store logical information about points
visited etc. And then you also need to make a conversion from index
to coordinates, using division that is slow. I solved that by table
look up. For each point in the one-dimensional array there is a pair
of integer in a table that tells me which line (32-bit word) a column
(bit) is corresponding bit in the bitmap.
I personally love this way of representing the board since two
variables (x,y) make the code longer and much harder.
One nice thing I do is to keep increments in an array such that I can
jump around in a given pattern from a given point. In Pascal it looks
like this.
--------
var
p: boardoffset;
begin
for u := 0 to 3 do
begin
Inc(p, URDL[u]); // UpRightDownLeft
DoSomething(p);
end;
end;
--------
Best wishes
Magnus
--
Magnus Persson
Department of psychology, Uppsala University
Box 1225, SE-751 42, Sweden
018-471 2141 (work), 018-460264 (home)
070-2987879 (cellular)
MAILTO: magnus.persson@xxxxxxxxxxxxxxxxx
URL: http://www.docs.uu.se/~magnuspe