编程代写|Programming with Python Coursework 2022 Gomoku with a Computer Opponent

Overview

The aim of this coursework is to code a Python 3 module that implements the famous Gomoku game.

This project is worth 70% of the final mark for MATH20621 Programming with Python.

Gomoku (also called Five in a Row) is a game in which two players take turns marking the spaces on a regular grid (usually using black and white pieces). There are different versions of this game with different grid sizes. In this project, our Gomoku will be played on a 8-by-8 grid. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of five of one’s own pieces.

The Python module (= a collection of functions) should allow the game to be played either by two humans, a human against a computer, or by the computer against itself. The module should also allow for a game to be loaded from a file and continued.

In this project you are required to use the data structures and functions specified in the tasks below.

These tasks are ordered logically and in approximately increasing level of difficulty; it is recommended to follow the tasks in that order.

Frequently asked questions

What can and cannot be used for this coursework?

The Python knowledge contained in the course notes is sufficient to complete this project. While you are allowed to consult the web for getting ideas about how to solve a specific problem, the most straightforward solution may already be in the course notes. It is not allowed to copy-and-paste several lines of computer code from an online source without clearly indicating their origin. If you really need to use an online source, you must indicate this like so:

# the following 3 lines follow a similar code on

# http://webaddress.org/somecode.htm as retrieved on 27/11/2022

Let’s be clear about what is not allowed:

You are NOT allowed to send/give/receive Python code to/from classmates and others.

This project is the equivalent of a standard exam and it counts 70% towards your final mark.

Consequently, the standard examination rules apply to this project.

Once your Python module is submitted via the Blackboard system, it will undergo plagiarism tests:

1.) The Turnitin system automatically checks for similarities in the codes among all students (without syntactical comparisons).

2.) Your lecturer compares the syntax of all submitted codes using specialized software able to detect several forms of plagiarism. Hence, refrain from communicating any code with others.

WARNING: Even if you are the originator of the work (and not the one who copied), the University Guidelines require that you will be equally responsible for academic malpractice and may lose all marks on the coursework (or even be assigned 0 marks for the overall course).

How is this coursework assessed?

It will be checked whether you have followed the tasks and format specified below, using the prescribed function names, variable names, and data structures.

All module functions will be tested automatically by another Python program (so-called unittesting). This is why it is important that your module “does not do anything” when it is imported into another program, and that you strictly follow the format of the functions specified in the tasks below (otherwise, some of the tests may fail and you may lose marks).

It will be checked whether each function/line of code is free of bugs and the program runs without crashing. Functionality will be one of the main factors in the assessment.

It will be tested if your code reacts to exceptional (user) inputs in an appropriate manner, making use of Exceptions whenever indicated. It should be impossible to crash the code.

It will be checked if your module is properly documented and if the main program and all functions have meaningful docstrings. In particular, each function must fully explain its own inputs, its return values, and possible exceptions. There should be no room for misinterpretation. Also check that print(functionname.__doc__) returns the docstring.

Further marks will be given on code efficiency.

The rough split (subject to scaling) between the total marks is 65% for unit testing and manual inspection and 35% for documentation and code efficiency.

When and how to submit the coursework?

The complete coursework can be completed and submitted as a single Python file named

“gomoku_yourname.py”. Replace yourname with your actual name. The submission will be via Blackboard and the strict deadline is Friday, December 16th, at 1pm. You can resubmit your coursework as often as you like, but only the last submission counts.

Below are the Tasks 0-11 of the coursework

Task 0. Prepare the module and understand the game dictionary

The tasks in this project specify the various functions to be implemented in your module. The main function of your module is called play() and it will initiate and control the game flow (i.e., starting by asking for the users’ names and then, in turn, performing the users’ moves). We do not need to worry about this play() function until later in Task 10. For now, simply prepare your Python project by copying the below code into a fresh “gomoku_yourname.py” file.

“””

A Python module for the Gomoku game.

TODO: Add a description of the module.

Full name: Peter Pan

StudentId: 123456

Email: peter.pan@student.manchester.ac.uk

“””

from copy import deepcopy # you may use this for copying a board

def newGame(player1, player2):

“””

TODO in Task 1. Write meaningful docstring!

“””

game = {}

# TODO: Initialize dictionary for a new game

return game

# TODO: All the other functions of Tasks 2-11 go here.

# USE EXACTLY THE PROVIDED FUNCTION NAMES AND VARIABLES!

# ——————- Main function ——————–

def play():

“””

TODO in Task 10. Write meaningful docstring!

“””

print(“*”*55)

print(“***”+” “*8+”WELCOME TO STEFAN’S GOMOKU!”+” “*8+”***”)

print(“*”*55,”\n“)

print(“Enter the players’ names, or type ‘C’ or ‘L’.\n”)

# TODO: Game flow control starts here

# the following allows your module to be run as a program

if __name__ == ‘__main__’ or __name__ == ‘builtins’:

Your whole coursework project can be completed using this single file. You just need to replace the TODO comments with the actual code. Make sure that all code is contained in functions so your module “does not do anything” when it is imported into another Python program.

So how can we “make the Gomoku game play?”

We first have to clarify what constitutes a “state” of this game, and then we need to implement the transitions of one state into another. Note that at any stage of playing, the current game situation is completely described by the factors:

– Who are the two players (i.e., a player’s name or if it is a computer player)?

– Which positions on the 8-by-8 board are occupied by which player?

– Whose turn is next?