Class board

java.lang.Object
  |
  +--board

public class board
extends java.lang.Object

a board contains the current game situation: where the stones are, what color they have and who should move. It also contains a history so moves can be undone.


Field Summary
 int[] A
          the array A contains the stones.
static int FREE
           
static int OUT
           
static int P1
           
static int P2
           
 
Constructor Summary
board()
           
 
Method Summary
 boolean canmove(int c)
          returns whether the current player is allowed to place a stone at c.
 void clear()
          resetup the board to the initial situation.
 board copy()
          returns an exact copy of this board.
 void domove(int c)
          do the given move on this board.
 boolean finished()
          returns true iff the game is finished.
 int get(int i)
          get the value of the given field
 int get(int i, int j)
          get the value of the field indicated in 2dimensional coordinates.
 int getcoverage()
          return the number of visible fields that are not free.
 int[] getevalvector(int[] out)
          returns a certain set of number that will be used to evaluate the situation.
 int getflips(int c)
          return the number of stones that would flip when playing c.
 int getplayer()
          get the player currently moving: P1 or P2.
 boolean P1wins()
          returns true if player 1 won the game.
 boolean P2wins()
          returns true if player 2 won the game.
 void set(int i, int value)
          set the given field with the given value
 java.lang.String statusmessage()
          returns a line of text describing the situation.
 void undomove()
          undo the last move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A

public int[] A
the array A contains the stones. You would expect A to be a 2-dimensional array, but it turns out that it is faster to make it a one-dimensional array. A is larger than the nulber of fields, because this prevents bounds tracking. If you start on a valid field, and you start walking in any direction, you will first encounter a field with the value OUT before you cross a border.

because A is onedimensional, you just need one integer to indicate a field. So instead of an object move all methods dealing with moves just use int's (note the huge speed improvement).


OUT

public static int OUT

P1

public static int P1

P2

public static int P2

FREE

public static int FREE
Constructor Detail

board

public board()
Method Detail

copy

public board copy()
returns an exact copy of this board.

getplayer

public int getplayer()
get the player currently moving: P1 or P2.

set

public void set(int i,
                int value)
set the given field with the given value

get

public int get(int i)
get the value of the given field

get

public int get(int i,
               int j)
get the value of the field indicated in 2dimensional coordinates.

clear

public void clear()
resetup the board to the initial situation. Chooses randomly between the two possible openings.

domove

public void domove(int c)
do the given move on this board.

canmove

public boolean canmove(int c)
returns whether the current player is allowed to place a stone at c.

finished

public boolean finished()
returns true iff the game is finished.

P1wins

public boolean P1wins()
returns true if player 1 won the game.

P2wins

public boolean P2wins()
returns true if player 2 won the game.

getflips

public int getflips(int c)
return the number of stones that would flip when playing c.

getcoverage

public int getcoverage()
return the number of visible fields that are not free.

getevalvector

public int[] getevalvector(int[] out)
returns a certain set of number that will be used to evaluate the situation. Currently, it returns 13 numbers: the first 10 numbers returns the number of counters in a certain kind of field. There are ten kind of fields due to symmetries. The kinds are in the kind table. This table looks like this
       0   1   3   6   6   3   1   0
       1   2   4   7   7   4   2   1
       3   4   5   8   8   5   4   3
       6   7   8   9   9   8   7   6
       6   7   8   9   9   8   7   6
       3   4   5   8   8   5   4   3
       1   2   4   7   7   4   2   1
       0   1   3   6   6   3   1   0
But you should not care about how this table looks: What is important is that we value counters regarding their position, but using symmetries to limit the number of situations. the 11th number (that is out[10] or out[kinds]) return how many counters you are ahead (negative if behind) the twelth number return the number of moves you can do the last number tells you the number of counters you can flip in total.

If you add a certain feature that you think is important for winning chances, do it here and change evalvectorlength. The genetictrain and weightvectorclasses will automatically adjust if you recompile them. you must retrain before you use the applet, beacuse the standard weigth vector in the player class will then be too short.

Parameters:
out - an optional array you want the result in (reusing memory improves the speed) You can make it null if you do not have such array.
Returns:
returns an evalvector. It will be out if that was not null.

undomove

public void undomove()
undo the last move. The board remembers what move that was, so you do not have to give it.

statusmessage

public java.lang.String statusmessage()
returns a line of text describing the situation.