Question: Introduction In this assignment you will be writing an agent to play the game of Nine - Board Tic - Tac - Toe. This game
Introduction
In this assignment you will be writing an agent to play the game of NineBoard TicTacToe. This game is played on a x array of x TicTacToe boards. The first move is made by placing an X in a randomly chosen cell of a randomly chosen board. After that, the two players take turns placing an O or X alternately into an empty cell of the board corresponding to the cell of the previous move. For example, if the previous move was into the upper right corner of a board, the next move must be made into the upper right board.
The game is won by getting threeina row either horizontally, vertically or diagonally in one of the nine boards. If a player is unable to make their move because the relevant board is already full the game ends in a draw.
Getting Started
Copy the archive srczip into your own filespace and unzip it Then type
cd src
make all
servt x o
You should then see something like this:
x
next move for O
You can now play NineBoard TicTacToe against yourself, by typing a number for each move. The cells in each board are numbered as follows:
To play against a computer player, you need to open another terminal window and cd to the src directory
Type this into the first window:
servt p x
This tells the server to use port for communication, and that the moves for X will be chosen by you, the human, typing at the keyboard. If port is busy, choose another digit number.
You should then type this into the second window using the same port number:
randt p
The program randt simply chooses each move randomly among the available legal moves. The Python program agent.py behaves in exactly the same way. You can play against it by typing this into the second window:
python agent.py p
You can play against a somewhat more sophisticated player by typing this into the second window:
lookt p
If you are using a Mac, type looktmac instead of lookt
Writing a Player
Your task is to write a program to play the game of nineboard tictactoe as well as you can. Your program will receive commands from the server init start secondmove thirdmove lastmove win loss draw end and must send back a single digit specifying the chosen move.
the parameters for these commands are explained in the comments of agent.py
Communication between the server and the players is illustrated in this brief example:
Player X Server Player O
init
init
startx
starto
secondmove
thirdmove
nextmove
nextmove
lastmove
wintriple
losstriple
end
end
can you do it in C
This is the starter code
#include
#include
#include
#include
#include "common.h
#include "agent.h
#include "game.h
#define MAXMOVE
int board;
int moveMAXMOVE;
int player;
int m;
Print usage information and exit
void usage char argv
printfUsage: s
argv;
printfp port
; tcp port
printfh host
; tcp host
exit;
Parse commandline arguments
void agentparseargs int argc, char argv
int i;
while i argc
if strcmp argvip
if i argc
usage argv;
port atoiargvi;
i ;
else if strcmp argvih
if i argc
usage argv;
host argvi;
i ;
else
usage argv;
Called at the beginning of a series of games
void agentinit
struct timeval tp;
generate a new random seed each time
gettimeofday &tp NULL ;
srandom unsigned int tptvusec ;
Called at the beginning of each game
void agentstart int thisplayer
resetboard board ;
m ;
movem;
player thisplayer;
Choose second move and return it
int agentsecondmove int boardnum, int prevmove
int thismove;
move boardnum;
move prevmove;
boardboardnumprevmoveplayer;
m ;
do
t
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
