This assignment can be performed in pairs. The code for this assignment
will be written by the team; however, each student must turn in their own homework write-up, so each team member is responsible for understanding all key pieces of the code and producing the example boards
(question 2).
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 Python starter code includes the basic functionality of Othello.
Each function in the code includes comment that describes its purpose, inputs, and outputs.
IMPORTANT: This Othello.py starter code changed on 6/6/2013 to standardize the order of the row and
col arguments in each function. If you do not want to move to the new starter code, that is okay
but you MUST update the play_square function to the proper argument order so that
our matchmaker will call your code correctly. The order should be play_square(self, row, col, player, opp).
Also, the Python code board is 0-indexed, so 0,0 is the upper-left corner of the board.
The above Othello.py player was distributed initially, but does not include the functionality to
return its move as a return value. An example of a player that does include that
functionality can be found in TeamA.py.
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 "TeamMember1LastName_TeamMember2LastName" (If you are doing it by yourself, FirstName_LastName)
- Name your files after your class name, i.e. TeamMember1LastName_TeamMember2LastName.py or TeamMember1LastName_TeamMember2LastName.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 (black) or second (white) player.
- At each step in the game, matchmaking code will call your
play_square()
function. After calling this function, your program must make the move dictated by given inputs, and determine the output
depending on your algorithm and return the 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.
Hint: To test your play_square()
works properly, create two instances of the game in the main function and have two instances of your program play against each other, by wiring them with a loop.
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).
- (1/2 point) 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.