First, make sure you do the activities to set up Python, GoGui,
and download the go.tgz
file with the code.
Go into directory go
.
It contains a set of Python 3 files,
which implement the Go0
and Go1
programs
from the lecture.
You can run programs either from the command line,
or with a GUI such as GoGui,
which understands
GTP.
Change into the go
directory and start the program with either
./Go1.pyor
python3 Go1.py
If ./Go1.py
gives you trouble, check
Permissions and Python Path
below.
Then execute the following GTP commands and observe the answers,
which all start with a string "= ".
For example,
boardsize
has no output (other than the "= " at the start of each reply), but it sets up the size of the program's board.
showboard
prints a (primitive) image of the board with the usual encoding.
play
needs a color argument 'b' or 'w' followed by the coordinates of your move.
legal_moves
needs a color argument 'b' or 'w', and returns the list of legal moves in sorted order.
boardsize 3 = showboard = [[0 0 0] [0 0 0] [0 0 0]] play b a2 = showboard = [[0 0 0] [1 0 0] [0 0 0]] play w a1 = showboard = [[2 0 0] [1 0 0] [0 0 0]] legal_moves b = a3 b1 b2 b3 c1 c2 c3 quit = %
To avoid typing, you can also download all these commands in a text file sample-session.gtp and pipe them into the program. But you will not see the results step by step.
./Go1.py < sample-session.gtp
chmod u+x Go1.py
which python3If the answer is /usr/bin/python3, as e.g. on the lab machines, all is well. If not, work is needed.
Go1.py
.
One problem is that if you then submit such a file in the assignment,
it will not run on our test machines. Also, you will have to do it
again for every program.While it is not strictly necessary to use a graphical user interface to a GTP-based Go program, it is more intuitive.
mydirectoryname/go/Go1.py
crazypythonlocation/python3 mydirectoryname/go/Go1.py
If this succeeds, you have now connected your program to GoGui, and are ready to play, analyze, etc. If this fails, you should check the error message. Then you can edit your command in "Program" - "Edit Programs...".
You can add as many programs as you like, for example Go1, Go2, ..., or any free Go programs you find on the internet that speak GTP.