HW 3: Tower Blaster DSA 8101: Fundamental Computing Concepts HW deadline 12th August 2022. This homework (HW) deals with the following topics: · Lists · tuples In this HW, we will be implementing the...

Tower Blaster


HW 3: Tower Blaster DSA 8101: Fundamental Computing Concepts HW deadline 12th August 2022. This homework (HW) deals with the following topics: · Lists · tuples In this HW, we will be implementing the game Tower Blaster, which is a game that involves re-arranging a group of bricks to have an increasing sequence. About the Game Tower Blaster is often played with 2 human players, but we will keep this simple and just play the user versus the computer. The user’s moves are decided by the user playing the game, by asking for input, and the computer’s moves are decided by the program. There is NO right answer for the section that asks you to program a strategy for the computer. All we want you to do is come up with a reasonable enough strategy that ensures a human user does not always beat the computer. So, unlike your previous assignments, this one has a creative component to it. You must use Python lists and tuples for this assignment. Some of you might have seen a package called numpy. You are NOT allowed to use numpy at all. For an online version of Tower Blaster, go here: https://yaksgames.com/games/tower-blaster/G9991E56CC ( 1 | P a g e ) Try to get a feel for the game. Our game will be similar, but read our specifications. Most importantly, we won’t have levels. Playing the game while developing your code can be helpful. A Tower Blaster game starts with a main pile of 60 bricks, each numbered from 1 to 60. Think of the numbers on the bricks as the width of the bricks. The objective is to be the first player to arrange 10 bricks in your own tower from lowest to highest (from the top down), because the tower will be unstable otherwise. The bricks in the main pile are shuffled at the start and both the user and the computer are dealt 10 bricks from the main pile. As a player receives each brick, they must place it on top of their current tower in the order it is received. Yes, initially your tower is likely to be unstable. After the first 10 bricks are dealt to the user and the computer, there will be 40 remaining in the main pile. The top brick of the main pile is turned over to begin the discarded brick pile. On each player’s turn, the player chooses to pick up the top brick from the discard pile or to pick up the top brick from the main pile. The top brick from the discard pile is known. In other words, the discard pile is ‘face up’ and everyone knows how wide the top brick is. The main pile is ‘face down’. Choosing the top brick from the main pile can be risky, because the player does not know what the brick is. Once a player chooses a brick, either from the discard pile or from the main pile, the player decides where in the tower to put the brick. The tower is always 10 bricks high, so placing a brick means that an existing brick in the tower is removed and replaced with the new brick. If the player takes a brick from the main pile (the one that is ‘face down’), the player can reject it and place it in the discard pile. This means that nothing in that player’s tower changes during that turn. If the player takes a brick from the discard pile (the one that is ‘face up’), the player MUST place it into the tower. The first player to get their 10 bricks in order wins. If, at any point, all of the cards have been removed from the main pile of bricks, then all of the cards in the discard pile are shuffled and moved to the main pile. Then the top card is turned over to start the new discard pile. The Actual Program Below you will find explanations of the functions that need to be written. We are expecting to see these functions with these names and method signatures exactly. Do not change the names of these functions, as we will be running automated tests against each individual function. You will also have to write some functions by yourself, in addition to the ones listed below. Feel free to name those functions whatever you want, as long as they happen to reflect what the function does. Note that we will make heavy use of lists in this assignment. Since a tower looks more like a vertically oriented structure, we need to have some convention. Our convention is that the tower in the picture to the right is going to be represented as [2, 13, 3, 32, 22, 17, 20, 10, 33, 46] We know this is a somewhat awkward way to represent the data, but we are deliberately asking you to do it this way in order for you to do more list exercises. The main pile and discard pile are also going to be represented as lists. Note that in both the main pile and the discard pile, you should only have access to the top. So, to add/remove bricks, consider the top of the brick pile or tower to be the beginning of the list. You will have to use the pop function, the append function, and the insert function, in some manner. Required Functions Be sure to add docstrings to all of your functions and comments to your code. setup_bricks(): · You’ll run this function once at the beginning of the game. · Creates a main pile of 60 bricks, represented as a list containing the integers 1 – 60. · Creates a discard pile of 0 bricks, represented as an empty list. · This function returns both lists. · The method of returning 2 things from a function is to make a tuple out of the return values. For an example of this, refer to the lecture slides/code where we return both the maximum and minimum in a list. shuffle_bricks (bricks): · Shuffle the given bricks (represented as a list). (You’ll do this to start the game.) · This function does not return anything. · You are allowed to import the random module and just use random.shuffle. check_bricks(main_pile, discard): · Check if there are any cards left in the given main pile of bricks. · If not, shuffle the discard pile (using the shuffle function) and move those bricks to the main pile. · Then turn over the top card to be the start of the new discard pile. check_tower_blaster(tower): · Given a tower (the user’s or the computer’s list), determine if stability has been achieved. · Remember, stability means that the bricks are in ascending order. · This function returns a boolean value. get_top_brick(brick_pile): · Remove and return the top brick from any given pile of bricks. This can be the main_pile, the discard pile, or your tower or the computer's tower. In short, remove and return the first element of any given list. · It is used at the start of game play for dealing bricks. This function will also be used during each player’s turn to take the top brick from either the discarded brick pile or from the main pile. · Note: Brick piles are vertically oriented structures, with the top having index 0. · This function must return an integer. deal_initial_bricks(main_pile): · Start the game by dealing two sets of 10 bricks each, from the given main_pile. · Make sure that you follow the normal conventions of dealing. So, you have to deal one brick to the computer, one to the user, one to the computer, one to the user, and so on. · The computer is always the first person that gets dealt to and always plays first. · Remember that the rules dictate that you have to place your bricks one on top of the other. In the earlier picture, this would mean that someone was dealt 46, 33, 10, ..., in that order. ·
Aug 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here