The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Games::Go::Player - plays a game of Go.

SYNOPSIS

This program generates a move on a Go board according to patterns that it learns from game records in SGF.

It puts patterns into a database (called pattern<colour><size>). Which databases are updated depends on $self->{_veclengths}. Pattern information is stored in a hash, where the key is the pattern, (compressed using vec) and the value contains a score for each point on the pattern from 0 to 255. A pattern point is either empty, black, white, or 'not on the board'

For an example script that instructs Player to learn from a particular directory, see pluserdir.pl in the scripts folder.

To play a move:

  my $move = $player->chooselegalmove($colour, $referee);
  $referee->play($colour, $move);
  $player->update($colour, $referee);

There are scripts in the examples folder for connecting this 'bot' to KGS or CGOS.

Before learning, the following parts of the 'new' method can (and in some cases, should) be edited:

$self->{_maxmove} For example, its probably not worth looking beyond move 10 when matching whole board 19x19 games.

The function loadratings can be tweaked as you see fit. For example, at the moment it gives a higher score to a move close to the centre of a pattern than one on the edge.

Options

path

Set to whichever pattern directory you wish to use. Default is the current directory.

  $player->path('path_to_my_pattern_directory');

teacher

When learning patterns from an sgf file, you can use this to ignore moves by players whose grade is too low. Default is '30k'

  $player->teacher('30k'); # learn from all players, even if no grade information is present
  $player->teacher('10k'); # learn from all players of grade 10kyu and better

increment

When learning, the default is to add 1 to the frequency data associated with a pattern everytime that pattern is found. If you want it to add more than 1, if for example you are feeding in a joseki file, use this method.

  $player->increment(50); # learn from all players, even if no grade information is present

incrementbygrade

Similar to increment, but will increase the frequency data by however many grades the player is above teacher

  $player->teacher('10k');
  $player->incrementbygrade(1); # a 4kyu move now increases the frequency data by 6

Debugging

The tiestats method can be called on a particular pattern file. It counts the number of patterns in the file, and how many are 'maxxed' ie Have a point in them that has been matched 255 times (and so are not updated again).

The retrieve method examines a pattern file for a particular pattern. The pattern is expressed as a string of 'o', 'x', '.' and '-' Where 'o' represents a white stone, 'x' a black one, '.' an empty point and '-' the edge of the board. eg '-----...-...-..x' represents the top left corner pattern -

---- -... -... -..x

For example:

use File::Basename; use Games::Go::Player;

my ($pathname, $pattern) = @_; my $player = new Player; my ($filename, $dirname) = fileparse($pathname); $filename =~ /(\d+)/; $player->size($1); $player->path($dirname); $player->tiestats($filename); $player->retrieve($pathname, $pattern) if defined $pattern;

Maintenance

The symmetrise method can be used to give a symmetrical pattern a symmetrical rating pattern. I suggest using it on databases when a large proportion of their patterns are maxxed.

BUGS/CAVEATS

There is a memory leak (?) in learn mode that gobbles up about 1Mb/minute on a 1.86GHz machine (which processes about 10 sgf files every 5 minutes). If you ask it to play on a boardsize that it has not learnt any patterns for, and it is Black in a handicap game, it will pass as its handicap moves(!). KGS doesn't seem to handle this situation well, and neither does this program.

Ideas

When learning, information on the closest move (in terms of the sequence of the game) could be stored. Have an additional piece of information in a pattern's ratings - how often this pattern has occurred after both players pass in a scored game. Have a maximum frequency higher than 255, then when a pattern hits that number, all updating of patterns of that size ends.

AUTHOR (version 0.01)

DG