Contents

Cmput 455 Assignment 1

Due Sep 16, 11:55pm. Submit via eClass submission link on the main eClass course page. The link will open about a week before the deadline.
Late submission (with 20% deduction) Sep 18, 11:55pm. Submit via separate eClass link for late submissions. This link will open after the regular deadline.

In this assignment, you implement the rules and a random player for Binary Game, a two player game inspired by the single player Binary Puzzle. All later assignments in this course will also use this game. You implement your solution by modifying the assignment 1 starter code in file a1.py (see below). The main steps are:

  1. Implement the rules of Binary Game, including creating an empty board, checking which moves are legal, detecting a win, and playing a given move.
  2. Write a random Binary Game player based on the starter code.
  3. Test your program on the public test cases, and on more tests of your own design.

Setup

  1. First, make sure you have completed your Activities up to and including 3c. In these activities you set up Python 3 and NumPy.
  2. Download and expand assignment1.tgz . Go to the directory assignment1, which contains:

Rules of Binary Game

Binary Game is played on a rectangular grid of width n and height m. The game starts with an empty grid. Two players called 1 and 2 alternate to fill one of the empty cells in the grid with a binary digit, 0 or 1, subject to the constraints below. Player 1 goes first. The player who makes the last move wins. In other words, a player who does not have any legal move loses. This will happen sooner or later as the grid fills.

The constraints on a move are:

To determine whether a move is legal, you have to consider both the row and the column for that move, and check that all constraints are satisfied.

Differences between Binary Game and Binary Puzzle

If you have never heard of Binary Puzzle, you can ignore this section. The main difference is that in the single player puzzle, you must fill the board completely in order to solve the puzzle and "win". However, in the two player game, you try to play in a way such that the opponent will run out of moves first. Usually, this will happen before the whole board is full, because there will often be "illegal" cells where neither playing a 0 nor a 1 is legal. An example is the middle cell on the 00.11 board.

Text Commands and Answers

We will test your program using the text commands below. The commands are already outlined in the starter code, as a stub that does nothing useful. You need to implement these commands as indicated below. Commands and answers use the following format:

command
output (0 or more lines, depending on command)
= 1

Here, the last line = 1 after output is the command status, which indicates that the command was successfully executed. If there is an error, then write a command status

= -1

instead, which indicates failure. See details and examples below.

Public Test Cases

The public test cases are in file assignment1-public-tests.txt in the assignment1 directory. Most tests currently fail, since our starter program does not implement the game-specific functions. 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.

Testing Procedure

All our tests will be on grids of size 20x20 or smaller. As in assignment1-public-tests.txt, test cases are written as text files containing a sequence of commands. Each command is followed by the expected correct answer on the next line.

What to Submit

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:

  1. All the files from the original assignment1 directory, but with the python code in a1.py modified to solve the assignment.
  2. Your presubmission.log file.
  3. A file readme.txt which lists the names and student IDs of your team. List the designated submitter first.

Do Your Own Pre-submission Test

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.

  1. Make sure the content of your assignment1 folder is correct, then create your submission with a command like tar -cvzf assignment1.tgz assignment1
  2. Use the Linux script command to log your testing session
  3. Copy your assignment1.tgz into a new directory
  4. Unpack it
  5. Changed Sep 12 Run python3 ./a1test.py with your program, using assignment1-public-tests.txt as input:
    python3 a1test.py a1.py assignment1-public-tests.txt
    
  6. Stop script logging here with the command exit
  7. Add file presubmission.log to your assignment1, and compress it again
  8. Use tar -tf for a final check of your assignment1.tgz contents. Use the checklist below
  9. If you see extra files included in your tgz file that do not belong:
  10. Fix any problems, then submit on eClass when you're ready

Marking

There will be total of 5 marks for this assignment.

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.

Details - Read Them All!

Details of the play command

Attempt to play a given digit at the given coordinate. First check if the move is legal according to the rules of Binary Game. If it is, then play the move, update the board according to the rules, and print the default reply. If the move is not legal, 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:

Examples

These are some examples. More examples are in the public tests file.

game 5 1
= 1

play 0 0 1
= 1

play -1 9 a 1
= illegal move: -1 9 a 1 wrong number of arguments

game 2 2
= 1

play 0 0 0
= 1

play 1 0 0
= illegal move: 1 0 0 too many 0

game 1 1
= 1

show
.
= 1

play 0 0 1
= 1

show
1
= 1

winner
1
= 1


Last modified: Sep 5, 2024, Martin Müller