This assignment can be performed in groups of 4. The code for this assignment
will be written by the team; however, each student must turn in their own homework write-up.
C++ Starter Code
The C++ starter code includes the following key functions:
- To create a Board object, use
Board * b = new Board();
The board has integer entires, with -1 indicating the white player, +1 indicating the black player, and zero indicating blank.
- to represent a board as a string for output, use:
string boardStr = b->toString()
- to change a Board to play a value (-1 or 1) at a given row and column, use the following
b->play_square(row,col,value)
where #row and col are 1 indexed(!).
- to receive moves from outside your code, following function will be called. This function will return your algorithm's move in row and col variables, passed by reference.
b->play_square(&row,&col)
where #row and col are 1 indexed(!).
- to check if a value can be played at a given row and column, use the following
b->move_is_valid(row,col,value)
where #row and col are 1 indexed.
- to get a square value, use:
int sq = b->get_square(row,col)
where where #row and col are 1 indexed.
- to get the score (the difference between black player's score and white player's score), use:
int score = b->score()
- to see if the board is full (all squares played), use:
bool full = b->full_board()
- to see if a given player value (-1 or 1) has some valid move, use:
bool moveExists = b->has_valid_move(value)
- Finally, you can fire up a simple run with a unintelligent computer player as:
play()
As with Tic Tac Toe, you'll want to change the play() function, e.g. swap out the make_simple_cpu_move() function, to use a computer player that makes intelligent moves.
(note, there is also another "check or flip path" function in the C++ code, but you shouldn't need it).
Python Starter Code
The TeamA.py includes the basic functionality of Othello.
Each function in the code includes comment that describes its purpose, inputs, and outputs.
The Python code board is 0-indexed, so 0,0 is the upper-left corner of the board.
Key Requirements
Note that following requirements are very important for the tournament. Please try your best to stick to them.
- Since your programs will be facing each other in this assignment, you should modify the class Board to be a unique "TeamName" of your choice
- Name your files after your class name, i.e. TeamName.py or TeamName.cpp. For C++, also turn in a .h file along with your .cpp.
- Which program starts the game will be determined with a simulated coin toss, so your program must be able to play the game as either the starting or second player.
In the C++ code, the first player is always black. In the Python code, either color can move first (you are told which color to move in the play_square input).
- At each step in the game, matchmaking code will call your
play_square()
function. When you receive a call to this function, you should make the move (for your opponent)
dictated by given inputs, then determine the move for your player and return that move. In the C++ code, you return the move in the row, col variables which are
passed by reference. In the Python code, you return the move in the return value as (row, col). There is an example of
how to return a Python move in TeamA.py.
- Your
play_square()
function must return in less than 15 seconds. Otherwise, it will forfeit the game.
- If there is no valid move, your function must return -1, -1 in row and col variables
- If the C++
play_square()
function is called with values 0, 0, then it means your program is making the first move.
- The Python
play_square()
function takes arguments saying which player is to move next, so you always make the next move for that player.
- If your programs produces an invalid move, it will automatically forfeit the game.
To test your play_square()
works properly, you can use the MatchMaking.cpp code (if you run into problems with
the timing functions, you can edit time.h as in this version).
You'll want to change the names of the referenced players (team1 and team2 in the cpp linked above) to be two copies of your player.
For the Python code, you should try our Matchmaker.py
code using the players in TeamA.py and TeamB.py
What to turn in
- Extend your tic-tac-toe program to play Othello.
Turn in the following:
- (3 points) Your code
- (1/2 point) Describe who within your group performed which piece of the design/programming
effort.
- Answer the following questions regarding your program. These answers can be brief (about two or three sentences for a-c).
- (3/2 points) What did you do to try to make your Othello player good?
- (1/2 point) Describe your evaluation function.
- (1/2 point) How did you alter your code to execute moves within the time limit?
- (2 points) Provide three example boards, one in which the white player has
an advantage, one in which the black player has an advantage, and another in which
it's fairly even. Give the evaluation function value for each case, and a one sentence explanation why the value makes sense.