Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rules of the Game The game of tactego is set up on a board which is a 2 d grid of size length x width
Rules of the Game
The game of tactego is set up on a board which is a d grid of size length x width which will be specified at the start of the game.
The pieces will be specified in a file, which will have lines indicating the strength of the piece and the number of pieces with that strength.
Players alternate by taking turns.
A player selects a piece and then moves that piece.
The position the player selects must be one of their pieces, you must test for this.
The position that you select as the destination must be at most one place away up down, left, right, or diagonally from the original position.
The position must not contain one of the player's own pieces.
If the destination contains an enemy's piece, then combat ensues.
Flags cannot move.
Combat is determined by strength.
If a higher strength piece attacks a lower or equal strength piece then it wins.
If a lower strength piece attacks a higher strength piece, then it loses.
If any piece that can move attacks a flag, then it captures that flag.
The winner of the combat takes the position that the piece was moving into.
Victory for a player is when the other player has lost all of their flags.
Design Details and Flow
This is a specification for how the project should be implemented.
Get the size of the board.
Get the filename with the pieces.
Create the board and the pieces, and place them onto the board randomly as specified here:
Use the random.shuffle method on the pieces inputted from the file in order to randomize placement of the pieces.
If you have a pieces list you can simply do random.shufflepieces once, for each set of pieces.
For the red player, place them at the top of the board, starting at position and going to width then go to the next line and scan across the row. Keep going in that fashion until all of the pieces have been placed.
For the blue player, place them on the bottom of the board starting at length going up to length width before resetting to length and scanning across that row. Keep going until all pieces have been placed.
The reason we're specifying this so carefully is so that we can all use a seed and generate the same placements of pieces. It will help both you and the graders to be able to test.
Enter the main game loop. Stay in the game loop until one of the players wins.
Draw the board.
Get the player's move.
A starting position should have two coordinates separated by a space.
Check that the starting position is valid, return to a if not.
Then get the ending position also two coordinates separated by a space.
Check if the ending position is valid, return to c if not.
Move the piece.
Determine the result of any combat
Return to until there is a winning player.
Report the player who won and end the game.
Implementation Requirements
You must have a main function called tactego:
def tactegopiecesfile, length, width:
You must import random in order to use shuffle.
Your main block should be:
if namemain:
random.seedinputWhat is seed?
filename inputWhat is the filename for the pieces?
length intinputWhat is the length?
width intinputWhat is the width?
tactegofilename, length, width
This will ensure that we can all have the same placement of pieces with different random seeds, which determines the output of the shuffles.
Other than tactego, you should implement at least additional functions. Keep in mind that my solution has approximately functions, so you shouldn't be afraid to create far more than total. You won't be rewarded for smashing too much functionality into each function so think about what the job of each function is and try to have it do that one job.
The only global variables that you have should be constants and technically the inputs in main at the beginning of the program that you send into the tactego function The game board, pieces, and all of the other things that you create for this project should be local to the tactego function. This will force you to pass them as parameters to the functions that need that data.
Load the pieces from the file in the order that they are given there, don't sort them or do anything before you run the shuffle on them. Run shuffle twice, once on the red pieces then once on the blue pieces in that order.
Output the board at least once per turn so that the player can see what they're doing.
Ask for the starting and ending positions in separate input statements, so that we can maintain consistency for testing.The pieces file format will be like this, each line will take one of these forms:
piece strengthnumber of pieces for example means that there are pieces with strength
F number of flags for instance F or F there is a space between them
Extra Credit: M number of mines
Extra Credit: S number of sappers
Extra Credit: A number of assassins
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started