21S2-A3-Connect-N.md
Assignment 3: Connect-N Game
In this assignment, you will implement a Connect-N game. Connect-N is an extension of the popular Connect-Four game.
Connect-Four is a two-player connection board game in which the players first choose a colour and then take turns dropping coloured
discs from the top into a seven-column, six-row vertically suspended grid. The pieces fall straight down, occupying the lowest available
space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own
discs. If you have never played Connect-Four, you can explore the rules and also try the game here
https://www.mathsisfun.com/games/connect4.html
Connect-N is a variation of the above Connect-Four game where the grid expands to N+3 rows and N+2 columns. The winning condition
becomes the first to form horizontal, vertical or diagonal line of N of one's own discs. Here N will be a positive integer number greater or
equals to 3, i.e., 3, 4, 5, 6, etc.
You need to submit 3 files (where X is replaced with your student ID):
aXXXXXXX-a3-text.py with text-based version of the game (Part 1)
aXXXXXXX-a3-gui.py with GUI-based version of the game (Part 2)
aXXXXXXX-a3.pdf or aXXXXXXX-a3.jpg with the sketch of your GUI (Part 2)
The maximum mark is 100. Marks below add up to 110, and your mark will be capped at 100.
Part 0: Comments for Your Code (10 marks)
You need to provide appropriate comments in your code. The comments should clearly state the purpose of every code block that you
have. Comments need to be provided for all parts below.
Part 1: Text-based Connect-N (50 marks)
Implement a text-version of the Connect-N game.
You MUST build your Connect-N game based on the provided .py template file. You can add new functions, variables etc, but you have
to implement the functions provided. Please read the comments inside the file carefully.
You need to implement the following features.
Board (10 marks)
you must use the board stored in the dictionary game (see the provided source code)
should handle different N
should be able to display itself using unicode
Winning Condition (15 marks)
determine if a player has won the game
Game Play (15 marks)
allow players to drop white and black disk in turn at the specific column
prevent users from committing illegal move (e.g. drop disk the the column is full)
Move history (5 marks)
allow the display of all previous moves in the game
Save / Load the game (5 marks)
allow the game to be saved and loaded to file
Upon completion, save your program as aXXXXXXX-a3-text.py. This is one of the files you need to submit.
(Bonus Challenge) Simple AI (10 marks)
Create a simple artificial intelligence (AI) engine that plays with a human player. For example, the AI can follow one of the following
strategies.
dropping the discs randomly
always copying the human
dropping the disc in the column that results in the longest line of connected discs (either vertically, horizontally or diagonally)
feel free to come up with your own rules. Please describe your rules in comments
Part 2: GUI-based Connect-N (40 marks)
Create a new file aXXXXXXX-a3-gui.py, and implement a GUI-based Connect-N in this file. Re-use as much code as possible from your
program in Part 1. In addition, don't forget to submit your sketch as aXXXXXXX-a3.pdf or aXXXXXXX-a3.jpg.
You need to implement the following.
Design Sketch (5 marks)
before you start coding, use paper and pen to sketch the GUI prototype (similar to what you did for Assignment 2). You should
provide a paragraph of text or annotations describing the functions of your GUI
Basics (15 marks)
show the board
show move history
add a reset button that restarts the game
Game Process (20 marks)
your app must let the players drop the discs (you do not need to show the animation). You need to decide how to enter the
desired column, e.g., by using buttons or a text field
the players should take turns to drop the discs, and the app should indicate whose turn it is
a dialogue when a player wins the game
You need to submit 3 files (where X is replaced with your student ID):
aXXXXXXX-a3-text.py with text-based version of the game (Part 1)
aXXXXXXX-a3-gui.py with GUI-based version of the game (Part 2)
aXXXXXXX-a3.pdf or aXXXXXXX-a3.jpg with the sketch of your GUI (Part 2)
学霸联盟