INFO1112 - Assignment 2 - Tic-Tac-Toe
Tic-Tac-Toe, also known as Noughts and Crosses, is a simple yet engaging two-player game played on
a 3x3 board. The game is typically played by marking the board spaces with ‘X’ and ‘O’, with players
taking turns. The objective of the game is to be the ffrst to align three of your marks—either horizontally,
vertically, or diagonally. More about it on Wikipedia.
Since you have found it quite boring to play alone, you came up with the amazing idea of building a server
that allows people to connect and play with you online. The server has the following features:
Users can log in
Users can create game rooms
Users can join existing game rooms either as players or as viewers
Users can view players’ moves as they are played
The speciffcations are divided into 3 main sections, which dictate:
The protocol used to communicate between the client and the server for running a game.
Server-speciffc runtime details and implementation
Client-speciffc runtime details and implementation
This assignment is due on Sunday, 20 Oct 2024 at 23:59, Sydney local time.
1 Getting Started
To assist you in the implementation of the assignment, the game logic and input handling for tic-tac-toe
has been implemented in 2 ffles in the scaffold: game.py, and tictactoe.py. Your task is to extend the
logic contained in these ffles, and create:
a server program which is responsible for handling many games of tic-tac-toe being run simultaneously,
and,
a client program, which interacts with a game server (like the one you implement), and allows an
end-user to play tic-tac-toe over a network connection.
You are encouraged to run the function tic tac toe in game.py to play the game and understand how it
works. Of course, you are free to modify these ffles as much as you wish for your submission.
2 Sequence Diagrams
Throughout these speciffcations, we will be using simple sequence diagrams in order to visually depict how
protocol messages are sent back and forth between the client and the server. The shapes below outline the
sequence diagrams used in the assignment speciffcations:
Messages from source to recipient are represented as a solid arrow with a solid arrow head. These
will be labelled with the protocol message being sent:
EXAMPLE:MESSAGE →
Return messages from recipient to source are represented as a dashed arrow with a point arrowhead.
This is for cases where a recipient is expected to send a message in response back to the source.
They will also be labelled with the protocol message being sent:
EXAMPLE:MESSAGE:RESPONSE
←
Participants, which in this case, will either be a client or a server, can send and receive messages.
These will be depicted as rectangles with an associated lifeline – a dashed vertical line representing
the lifetime of the participant:
Participant
13 Protocol
In order to support playing the game over the network, your programs will need to implement a custom
application-layer protocol as described here in order to facilitate client and server interactions.
All communications will use TCP, and you should use sockets to communicate over the network. More
details about sockets are available from the documentation of Python’s socket module. A how-to guide
for getting started with using TCP sockets is available on Python’s website, and some material will be
included in the lab content to help explain how to create and interact with TCP sockets.
A couple of general notes about the protocol:
Like many application-layer protocols (e.g. HTTP, SMTP), the protocol is text based, and speciffcally,
uses ASCII encoding for all data.
When sending data over the network, you will need to ensure you encode data into bytes to send
it over a network socket, and when receiving data, you will need to ensure you decode the received
data to interpret this as a string.
– Hint 1: use the str.encode method to encode a string into bytes with a speciffed encoding.
– Hint 2: use the bytes.decode method to decode bytes to a string.