[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: computer-go: Languages for programming go are?



> >   (c) What would you provide as primitives of the language? E.g. the
> > GoBoard class in SmartGo provides a function IsLibertyOfBlock(Point p,
> > Point block) that returns whether the empty point 'p' is a liberty of
> > 'block'. This could easily be coded in terms of more basic functions,
but
> > inside the GoBoard class this can be implemented more efficiently.
>
> In Many Faces, there is no special function for this.  It would be coded
as:
>
> point p;
> group block;
> bool result = inlist(p, grlbp[block]);  // grlbp is the array by
> group[block] of liberty list pointers.  inlist() tests if a value is in a
list

Note that this implementation is linear in the number of liberties of the
block. The current implementation in SmartGo looks at the (at most) four
adjacent points and checks whether any of them contain the block in
question. No doubt the same could easily be done in Many Faces.

> Many Faces is C, not C++, and I wouldn't create new iterators in my inner
> loops, because it seems too slow.  All of the loops in the example would
> just be walking linked lists, so they are very simple and fast.

The iterators are mostly syntactic sugar that gets inlined without loss of
efficiency. The LibertyIterator essentially boils down to iteration through
an array; the NeighborBlockIterator has to call a function to compute the
neighboring blocks first, eliminating duplicates. One advantage of using
iterator classes is that I can change the implementation (e.g. from list to
array) without having to change any of the client code.

> I don't have any code like yours since my move generator assigns values to
> moves as it generates them, then sorts and selects at the end.  I iterate
> once the liberties of the group and generate all of the moves relevant to
> that liberty, so your inner loops are intertwined with generating moves
> of other types.  The code is less clear, but faster :)

Right, that's the way to do it.

> I only test legality for moves as I try them.  That way I don't waste time
> testing for legality on moves that are cutoff, or otherwise never tried.

Thanks for replying with actual code, David. One slight issue: the legality
tests in the routine are not primarily to test whether the generated move is
legal, but to make sure that the played move is not in atari after the move
and that the opponent can't approach without getting into atari. Can you
please let us know how that would look in Many Faces?

> David Fotland

Anders Kierulf
www.smartgo.com