Due Sep 18, 11:55pm. Submit via eClass submission link on the main eClass
course page.
Late submission (with 20% deduction) Sep 20, 11:55pm.
Submit via separate eClass link for late submissions.
In this assignment, you implement a random player
for the game Ninuki, one of the many Five in a Row games.
You do this by modifying the assignment 1 starter code
which is based on the Go0
program
from class, but modified to make your job easier.
The main steps are:
assignment1
, which contains:
assignment1-public-tests.gtp
with
sample test cases for your program.Ninuki or Five in a Row is played on a Go board. The game starts with an empty board, and players Black and White alternate to place a stone of their color on a grid point. Black goes first. The goal of the game is be the first player to:
For more information on the game, you can see the GoMoku wikipedia page. Many variants of the rules are discussed on that page. Our variant of Ninuki is similar, but not quite identical to, the variants called Ninuki-renju and Pente.
A player can capture two opponent stones by "sandwiching" them between their own stones. For example, if X is to play and there is a pattern "XOO." in any direction on the board, then X can capture the two stones "OO" by playing on the empty point on the other side, resulting in the pattern "X..X". (Here, a dot denotes an empty point.)
It is possible that a single stone captures several pairs of opponent stones. For example, in the pattern "XOO.OOX", a move by X in the center captures four stones, leading to "X..X..X". More examples are given in the public test cases.
There is no "suicide". For example, if the pattern "XO.X" already exists on the board, then O can play to create "XOOX" and is not captured.
After stones have been captured, both players are free to play on those points again in the future.
When implementing your solution based on the starter code, be aware of the commonalities and differences between the two games. The rules of Ninuki are simpler. Checking legality of moves is simpler, there is only one basic capturing pattern, no suicide, and no ko rule to deal with. However, finding out whether the game is over is more complex. In Go, this is defined by consecutive passes. In Ninuki, you need to check if a player has five in a row, or has captured enough stones.
We will test your program using the GTP commands below. These commands are already implemented in the starter code, but the implementation either is for Go or is just a stub that returns "unknown" or similar. You only need to change or implement the commands as indicated below.
boardsize
This command sets the board size (between 5 and 19 in our tests). It also initializes the board (by calling clear_board below). You will not need to change this command.
clear_board
This command re-initializes the board to all empty, throws away all the moves played so far, and resets the captured stone counters. You will not need to change this command.
play color coordinate
Play a move of given color on the given coordinate. You will need to change this command to follow the Ninuki rules instead of the Go rules. Also, you need to implement different error handling. See Details of the play command below.
gogui-analyze_commands,
gogui-rules_game_id,
gogui-rules_board,
gogui-rules_board_size,
gogui-rules_side_to_move
These commands provide support for the game Ninuki in the GoGui 1.5.3 interface. These commands are already implemented and you do not have to change them.
gogui-rules_legal_moves
Produce a list of all legal moves for the current player, in alphabetic order.
Usage example (on empty 3x3 board):
gogui-rules_legal_moves = a1 a2 a3 b1 b2 b3 c1 c2 c3
You will need to change this command to use Ninuki rules instead of Go rules. See Details of the gogui-rules_legal_moves command below.
genmove color
This command generates and plays a random move and gives the move (for example a1) as its response.
This command implements random choice from the list of moves
created by legal_moves
.
You will need to change this command for end of game handling.
See Details for end of game below.
gogui-rules_captured_count
This commands reports the number captured stones by the white player and black player, respectively. There should be an space in between the two numbers.
Usage example (at the beginning):
gogui-rules_captured_count = 0 0
gogui-rules_final_result
This command checks if the game is over and outputs one of the following game results:
black white draw unknown
See Details for the gogui-rules_final_result command below. Also see Details for end of game.
The public test cases are in file assignment1-public-tests.gtp
in the assignment1
directory.
Most tests currently
fail, since the program does not implement those commands correctly yet.
See Testing Procedure below for examples.
Note that our given test cases include only a small number of cases. For evaluation, we will use a more comprehensive set of tests.
All our tests will be on a Ninuki board of size 19x19 or smaller.
As in assignment1-public-tests.gtp
,
test cases are written as text files containing a sequence of GTP commands.
Test cases contain both unnumbered GTP commands to set up a position,
and numbered GTP commands to do the tests.
Each test is followed by the expected correct answer.
Submit a single tgz file called assignment1.tgz
which contains exactly the following (and nothing else):
A single directory assignment1
which contains all the files in your solution, namely:
assignment1
directory,
but with the python code modified to solve the assignment.presubmission.log
file.readme.txt
which lists the names and student IDs of your team. List the designated submitter first.
Follow the steps below on a standard Linux undergraduate machine, and create a text file presubmission.log
that shows a copy of your command line presubmission testing.
assignment1
folder is correct, then create your submission with a command like
tar -cvzf assignment1.tgz assignment1
assignment1.tgz
into a new directorygogui-regress
with your program, using assignment1-public-tests.gtp
as inputscript
logging here with the command exit
presubmission.log
to your assignment1, and compress it again tar -tf
for a final check of your assignment1.tgz
contents. Use the checklist below--exclude=__pycache__
to get rid of them.
There will be total of 5 marks for this assignment.
presubmission.log
which shows the log of your correct test execution on a standard Linux undergraduate machine, and your readme.txt file (see below).Code that does not run, or just hardcodes the public tests case by case, will receive a mark of 0. If your code needs fixes, you need to submit a revised version before the late submission deadline. TA will not attempt to fix your code under any circumstances. Use the discussion forum or consult the teaching team in case of questions.
assignment1
folder.
You may create new files within this folder,
but it might not be necessary for this assignment.
Attempt to play a move of given color on the given coordinate. First check if the move is legal according to the rules of Ninuki. If yes, then play it and update the board according to the rules. If no, then output an error message and do not change the board. The format of an error message is:
illegal move: "copy of the input argument(s)" reason
The possible reasons for error messages are listed below. Check them in the order given and output the first error only:
In the starter code, this command is implemented for Go, not for Ninuki.
If the game is over, return an empty list. Otherwise, return a list of all empty points on the board in sorted order.
In the starter code, this command always returns an empty list.
The Go0/Go1 engine also implements a legal_moves command for the game of Go. You can just ignore that.
Here, one of the first three answers black, white, draw
should only be given if the game is over.
The fourth answer unknown
should always be returned if this command is called for a board where the game is not over yet.
In the starter code, this command just returns unknown
.
There are three different cases which end the game.
First, if a player creates a row of five or more stones, that player wins.
Second, if a player captures a total of 10 or more stones, that player wins.
Third, if the board is completely filled with stones, but no player
has won, then the game is a draw.
The gogui-rules_final_result
command should output either the color of the winner, or draw.
The genmove
command at the end of a game:
Before the end of a game, genmove
will play a random legal move and gives the move as its response.
If the game is over because the opponent just won, the
response of genmove
should be:
resign
If the game is over because the board is full and it is a draw, the response should be
pass
This is the only circumstance in which pass should be generated. The reason for this specification is that we can more easily use the tools for Go in this way.
In the starter code, genmove
is implemented for Go, not for Ninuki.
Last modified: Sep 1, 2023, Martin Müller