Answered step by step
Verified Expert Solution
Link Copied!

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 2d 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.shuffle(pieces) once, for each set of pieces.
For the red player, place them at the top of the board, starting at position (0,0) and going to (0, width -1) then go to the next line (1,0) 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 -1,0) going up to (length -1, width -1) before resetting to (length -2,0) 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 (4) 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 tactego(pieces_file, length, width):
You must import random in order to use shuffle.
Your main block should be:
if __name__=='__main__':
random.seed(input('What is seed? '))
file_name = input('What is the filename for the pieces? ')
length = int(input('What is the length? '))
width = int(input('What is the width? '))
tactego(file_name, 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 4 additional functions. Keep in mind that my solution has approximately 8 functions, so you shouldn't be afraid to create far more than 5 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 strength][number of pieces] for example 73 means that there are 3 pieces with strength 7.
F [number of flags] for instance F 1 or F 2[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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago