tesuji.games.go.computer.evaluation
Class Influence

java.lang.Object
  |
  +--tesuji.games.go.ByteArrayImpl
        |
        +--tesuji.games.go.computer.evaluation.Influence
All Implemented Interfaces:
BoardChangeListener, ByteArray, java.util.EventListener

public class Influence
extends ByteArrayImpl
implements BoardChangeListener

This class computes influence from black and white stones given a certain board-position.

The basic algorithm is quite simple:

- Each black stone gets a high positive value.

- Each white stone gets a high negative value.

- For several iterative steps, each point that has a positive value adds 1 to the influence of the neighbouring points. Each point that has a negative value subtracts 1 from the influence of the neighbouring points.

This is also called the Zobrist influence algorithm, since I think he was te first to come with this scheme. A possible variation on this is that if an empty point has two stones as its direct neighbours of opposite color facing each other, its influence is always 0. A fair part of the implementation deals with these so called 'dame' points.

A straightforward implementation of this influence algorithm would be to loop over the entire board for each iteration, and update the influence of the neighbouring points depending on whether the influence of the current point is positive or negative. To prevent the newly calculated values to affect the old values, this has to be done in two passes. So for each iteration, two loops over the whole board would be necessary. However, most of the time when a new move is played, the influence of the new position is usually still very similar to that of the previous position. When the board gets full, a new move only affects a handful number of points.

The implementation here is much more efficient than the straightforward approach since it only does the minimal amount of work necessary to compute the influence of the new position, based on its previous computation. This algorithm works even when the new position is completely different from the previous one, although in that case no time is saved compared to the straightforward approach. But if the new position is very similar to the old one, only a very limited amount of work needs to be done. It makes this implementation often a hundred times faster than the straightforward one.

The actual algorithm is not described in detail here, but it's probably the most elegant one I ever designed.



Creation date: (17-May-01 4:05:10 PM)

Product: Tesuji Software Go Library.

Copyright (c) 2001 Tesuji Software B.V.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of a Tesuji Software shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of Tesuji Software.


Field Summary
static byte BLACK_STONE
           
static int MAX_ITERATIONS
           
static byte WHITE_STONE
           
 
Fields inherited from class tesuji.games.go.ByteArrayImpl
array
 
Constructor Summary
Influence(int boardSize)
           
 
Method Summary
 void addBoardChangeListener(BoardChangeListener l)
          Any listener that registers through this method will get notified of all the points where the influence changed.
 void changeBoard(int x, int y, byte value, byte oldValue)
          Mark a point on the board as changed.
 void clear()
           
 ByteArray getPreviousInfluence()
           
 void removeBoardChangeListener(BoardChangeListener l)
           
 void setDameSwitch(boolean flag)
          Switch the 'dame' feature on or off.
 void update()
          Compute the influence based on the changes made to the board (by using changeBoard) since this method was last called.
 
Methods inherited from class tesuji.games.go.ByteArrayImpl
get, get, getBoardSize, getDoubleArray, getSingleArray, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ITERATIONS

public static final int MAX_ITERATIONS

BLACK_STONE

public static final byte BLACK_STONE

WHITE_STONE

public static final byte WHITE_STONE
Constructor Detail

Influence

public Influence(int boardSize)
Method Detail

addBoardChangeListener

public void addBoardChangeListener(BoardChangeListener l)
Any listener that registers through this method will get notified of all the points where the influence changed.

Creation date: (18-May-01 12:01:03 AM)


changeBoard

public void changeBoard(int x,
                        int y,
                        byte value,
                        byte oldValue)
Mark a point on the board as changed. This will cause the influence to be updated taking the new value into consideration the next time the method update is called.

Creation date: (17-May-01 4:33:51 PM)

Specified by:
changeBoard in interface BoardChangeListener

clear

public void clear()

getPreviousInfluence

public ByteArray getPreviousInfluence()

removeBoardChangeListener

public void removeBoardChangeListener(BoardChangeListener l)

setDameSwitch

public void setDameSwitch(boolean flag)
Switch the 'dame' feature on or off.

Creation date: (19-May-01 4:18:35 PM)


update

public void update()
Compute the influence based on the changes made to the board (by using changeBoard) since this method was last called.

Creation date: (17-May-01 4:41:41 PM)