Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
PGCert IT: Programming for Industry
This mini project requires you to develop a simple game called Bulls & Cows. There are seven tasks to complete. You are not expected to know how to accomplish all of these immediately, you will develop your solution over 2 weeks with guidance from teaching staff.
Before starting, read through this entire document to gain a better understanding of each of the requirements.
• IMPORTANT: Read the instructions carefully before attempting each task.Introduction
The bulls and cows game is a code-breaking game designed for two or more players. Each player chooses a secret code of 4 digits from 0 – 9. The digits must all be different. The goal of the game is for each player to guess the other player’s secret code.
B. The number of cows, i.e. the number of matching digits but in different positions.
For example, if the computer’s secret code is 4281, the match responses for the following guesses are shown below:
Figure One: Example output from a Bulls & Cows game.
More information about the game itself can be found here.
Requirements
The main goal of this assignment is to develop a bulls and cows game that allows two players to play against each other. One of the players may be a human player interactively providing guesses, but the game may also be played by two computer players against each other.
The game stores a secret code for each player, and then each player attempts to guess the other’s secret code. Players have seven attempts to guess the secret code. If playing interactively, support must be given to ensure that the player enters valid guesses – if the player types an invalid guess, then the game should ask the player to try again.
The game should allow the user to select which types players are involved in a game. The player should be able to choose to play interactively, provide a list of guesses from a file, or have a computer player in one of 3 difficulty levels make guesses. Details of each of these players are described in later sections. In addition, the game should be able to save a log of the game into a text file.
For this project you’ll complete a series of tasks as you work your way towards a fully functional implementation. The tasks do not have to be completed in order, and it is not expected that you will fully complete a task before moving on to other stages. You may choose to complete easier tasks ahead of more difficult ones, and more difficult tasks can be “stubbed out” with placeholder code while you learn new topics or decide on approaches.
In addition to the design requirements, you are also required to demonstrate good usage of git. Ensure that you regularly commit your code, with accompanying descriptive commit messages. ,Further ensure that following the completion of each task you make a clearly labelled commit that indicates to the marker where you completed the task so that these commits can be used for marking.
Unlike previous lab exercises, this project has not been provided to you as a git repository. Before you begin you will need to create a repository on Gitlab for this project inside your lab-exercises group and push the provided project to the newly created repository. To do this:
• Follow the instructions provided by Gitlab for adding existing code
Task Zero: Design
For this assignment, there is very little which is already given to you. Through this project you’ll gain experience in designing and building a complex program from scratch. Before starting to code, don’t forget to design your classes and methods (i.e. create UML class and sequence diagrams)! You should apply the concepts you have learned so far in the course. Don’t have everything in one class and try to promote code reuse as much as possible. You must have at least one use of inheritance in your project.
Using PlantUML, prepare a UML class diagram which shows all the classes and important methods of your Bulls & Cows implementation, along with the appropriate relationships showing how these classes fit together. Store the diagram code in a doc/ folder within the project, in a file called initial-class.puml .
Discuss your design with teaching staff in the labs and listen to the feedback given. Early feedback is important here, and you will find that going through several design iterations early will pay off over the course of the project.
Note: It’s OK if your implementation doesn’t match your initial design 100% - you will likely adjust the design as you work and identify new elements that need to be taken into consideration.
Task One: Beginning with an Easy AI
Begin by implementing a simple computer player that guesses random valid codes with no consideration for strategy. This player should be able to provide a secret code on request (this should be set once, and remain the same throughout the game), and also provide random guesses when required.
Remember that both the secret code and any guesses must be valid codes – 4 digits long with no repeating digits.
Task Two: Starting the battle
Update your code with a game class that pits 2 opponents against each other. This should begin by asking the user which opponents should play in the game – now you only have a single Easy AI player, so you will be playing 2 of these players against each other.
The game should then request each of the players to generate their own secret code – these should be validated to ensure that they are valid codes. The game should then begin, asking the first player for a guess, then testing this against the second player’s secret code, before displaying the result to the screen. The roles will then reverse, with the second player testing their guess against that of the first player. This should continue for 7 rounds, or until a player correctly guesses the opponent’s code, whichever happens first.
The game ends when either side successfully guesses the other’s code (resulting in a win for that side), or when each side has made seven incorrect guesses (resulting in a draw).
Task Three: Player 2 - Medium AI
Modify your code to introduce a second computer player, the Medium AI that is a slight improvement over the Easy AI. This player will also choose guess codes at random, but it should also remember guesses it has made in the past, and it should not reuse a previous guess.
Update your game code to support using this new player, allowing the player to select this as one of the opponents in the game.
Task Four: Interactive play
Computers playing on their own isn’t terribly fun, so update your game to include an interactive human player. This player is controlled by a human and will prompt the user to enter the initial secret code, and also all of the guesses that are made throughout the game. As humans are fallible, you need to ensure that any code the user provides is valid, and if it isn’t, the user should be re-prompted to provide a valid guess as many times as needed before using the code.
Update your game code to allow your new interactive player to be one of the opponents. Unlike with computer players, your game can only have a single human player. You should support computer vs computer or computer vs human, but selecting human vs human should not be
allowed.
Task Five: Hard AI
Update your code to introduce a third AI player – the hard AI. This computer player is more sophisticated than the others and uses a strategy to improve its guesses to approach the solution rather than just randomly guessing. There are several strategies that could be used here, and you are welcome to implement any of them, but we have provided a possible strategy for implementing ,the hard AI below.
Once completed, update your game code so that the Hard AI can be chosen as an opponent in the game.
Possible Strategy
This strategy involves keeping a list of all possible guesses, and then intelligently pruning that list based on the result of each guess made by the AI. In this strategy, the first guess by the computer will be chosen randomly. After this guess, all subsequent guesses will be carefully planned. The computer keeps track of precisely which codes remain consistent with all the information it has received so far. The computer will only choose a guess that has a chance of being the correct one.
For example, let’s assume the computer’s first guess scored 1 bull and 1 cow. Then the only codes that still have a chance to be the correct one, are those which match up 1 bull and 1 cow ,with the first guess. All other codes should be eliminated. The computer will go through its list of all possible codes and test each against its first guess. If a code matches 1 bull and 1 cow with the first guess, then it will remember that the code is still a possible candidate for the secret code. ,If a code does not match 1 bull and 1 cow with the first guess, the code will be eliminated. After this is completed, the computer randomly chooses any of the possible candidates for the second guess.
If the computer’s second guess then scores 2 bulls and 1 cow, the computer checks all the remaining candidates to see which codes match up 2 bulls and 1 cow with the second guess. Those codes that do not match are eliminated. In this manner, each guess is consistent with all the information obtained up until that point in the game.
To illustrate the process, consider the scenario shown in figure two below, in which a simpler version of the game is being played. In this demonstration, secret codes are only two digits in length and may only contain the characters 1 through 4. The player has chosen “2 1” as their secret code, which the AI is trying to guess. Using this process of elimination, the AI is able to quickly guess the player’s code.
Figure Two: Demonstration of “hard-mode” Bulls & Cows AI.
Task Six: Reading Guesses from a File
Further modify your code to introduce a new type of player, one that reads its secret code and guesses from a predefined file.
When selecting this sort of player, the user should be asked to enter a filename. If the player enters an invalid filename, they should be re-prompted until they enter the name of a file that actually exists. This file should then be read and interpreted as a text file, where each line contains a separate code. For example, a sample file input.txt may contain the following text:
Figure Three: Example contents of a text file containing guesses to be used instead of the player entering their guess using a keyboard.
You should not trust that this file only contains valid codes and should check each code that you encounter. The first valid code in this file should be used as the secret code for the player. All subsequent codes should be used as guesses throughout the game.
Once the file has been read, then the game should proceed as normal. When a guess is requested from the player, the next valid code from the file should be supplied. If there are no more presupplied codes (for example, if the player needs to provide their fifth guess but the file only contains four codes), then the additional codes should be randomly generated as the Easy AI does.
Once completed, update your game code so that this new variety of player can be chosen as an opponent.
Task Seven: Saving to a File
• The identity of the winner (or a message stating that the game was a draw)
The data must be readable when opened in a standard text editor. An example results file is given in figure four, though exactly how your file is organized is up to you.
Interactive Player guessed 4281, scoring 4 bulls and 0 cows
Interactive Player wins! :)
Figure Four: Example results text file showing the secret codes, moves, and results of a Bulls & Cows game.