代做数据结构语言程序、数据库编程调试、调试SQL语言程序、Matlab编程调试

Files to submit: battleship.pyRestrictions:• You may only import the random module• You cannot use global variablesRequirements• Your solution must contain at least 5 user defined functions that you useDescriptionFor your final project you will be implementing a one player version of battleship that allows the user to play against an AI. Here is a link to a version of the game you can try playing online.The differences between this version and ours, is that in our version we will announce when a ship is destroyed, our board size is configurable, and the number and size of the ships is variable. 1. Setup1. Your program should ask the user for the following information in this order. You must make sure to validate that the input is correct before accepting it. If it isnt your program should request the user to enter the input again.2. The seed: An integer used to seed the random number generator.1. To seed the random number generator do random.seed(seed)1. Seed needs to be an integer3. The width of the board: An integer greater than 04. The height of the board: An integer greater than 05. The name of the file containing the users ship placements1. The file is structured as follows1. Symbol_for_ship1 row1_index column1_index row2_index column2_index2. Symbol_for_ship2 row1_index column1_index row2_index column2_index3. Symbol_for_ship3 row1_index column1_index row2_index column2_index4. …2. All ship placement files will be structured correctly but you must verify that1. The user did not choose either x,X, o, O, or * for their ship as those are symbols reserved for hits, misses, and, unfired upon spaces2. The user did not choose the same symbol for multiple ships3. The user placed all of their ships on the board4. The user did not try to place their ships diagonally5. The user did not place their ships on top of each other3. If the user violated any of the above constraints, an appropriate message should be displayed to the screen and the program should terminate1. You will find exit helpful for terminating the program. Make sure to put a 0 in it for the status though or else tester will think your program crashed.6. The number of the AI they would like to play against.1. 1 is for the Random AI2. 2 is for the “Smart” AI3. 3 is for the Cheating AI4. AIs will be explained in a later section7. After receiving the setup information, your program should1. Seed the random number generator with the provided seed2. Construct the users board3. Construct the AIs board1. The AI will have the same ships that the user has but will position its ships randomlythroughout the board2. The AI should place ships in sorted order based on the symbol used for each ship1. The AI should first select a direction for the ship they wish to place, either vertical or horizontal.1. Use the following code to do this: random.choice([vert, horz])2. Next select a valid starting point based on the direction that was previously selected1. If horz was selected we will be placing the ship from left to right1. For example, if the ship we want to place is length 3 and the the board is 10 wide then our ship could start in columns 0 – 7 and be placed in any row.2. If vert was selected we will be placing the ship from top to bottom1. For example, if the ship we want to place is length 5 and the board is 7 tall then our ship could start in rows 0,1, or 2 but be placed in any column3. When selecting the starting of the position first select the row and then select the column1. Use random.randint to generate the row and column values2. It is very important that you first generate then row and then the column or otherwise your answers will not match mine.3. If the ship does not overlap with any other ships it should be placed at the chosenlocation and the location should be printed out (we are only displaying the location so that you can more easily check to see if you are placing the ships at the same location my code does)1. If the ship cannot be placed at the location repeat steps 1 – 3 until it is successfully placed4. Randomly select a number between 0 and 11. If 0 is selected the player goes first. If 1 is selected the AI go代做数据结构语言程序、数据库编程作业调试、调试SQL语言程序、Matlab编程调试es first.1. Use random.randint to generate the turn2. Gameplay1. Each turn either the player or the AI selects a location to fire upon1. If the location does not contain an opposing ship a miss is announced1. Misses are marked with O2. If the location does contain an opposing ship a hit is announced unless that is the last hit on the ship and then it is announced that you destroyed that ship1. Hits are marked with X2. The player and the AI alternate taking turns until one of them has destroyed all of their opponents ships3. The player will input their choice as a row column pair on one line separated by a space. 1. Examples:1. 5 82. 3 92. Your program must validate that the user enters correct input and if they do not continues to ask them for more input until a valid location is chosen1. For input to be valid it must be a row column pair that is on the board and hasnt been fired upon before3. AIs1. You will be developing three different Ais2. Random AI1. This AI randomly chooses a location to fire upon that it hasnt fired upon before2. In terms of implementing this you should have a list of locations the AI hasnt fired uponand then use random.choice to select one of them to shoot at. After selecting this location it should be removed from the list of unfired upon locations.1. This list of locations should be generated be ordered by row. For example if the board was a 2 X 2 the list of unfired upon locations would be [(0,0), (0,1), (1,0), (1,1)] at the beginning of the game. 3. Smarter AI1. The Smarter AI has 2 modes: Hunt and Destroy2. In Hunt mode the AI behaves like the Random AI in that it randomly chooses a location to fire upon that it hasnt fired upon before. If the AI scores a hit it switches to Destroy Mode3. In Destroy mode the AI fires above, below, to the left of, then to the right of the location it hit, excluding spaces it has already checked. If any hits are scored while in Destroy mode the positions above, below, to the left and to the right of the hit are added to the list of spots to check on subsequent turns1. The AI returns to Hunt mode after all spaces added to check that were added by Destroy mode were exhausted. 4. As an example consider the following board. (Player moves are not being shown.)0 1 20 * * *1 * S *2 * S *3 * S *4 * * *The AI starts in Hunt mode. Lets say it chooses location 1,1 to fireupon0 1 20 * * *1 * X *2 * S *3 * S *4 * * *Since the AI scored a hit it will now switch to destroy mode. The next locations it should fire upon are (0,1), (2,1), (1,0), and (1,2) 0 1 20 * O *1 * X *2 * S *3 * S *4 * * *(0,1) was a miss so we then move on to (2,1).0 1 20 * O *1 * X *2 * X *3 * S *4 * * *We have another hit so now our list of targets to fire upon is (1,0), (1,2) , (3,1), (2,0), (2,2). Notice we did not add (1,1) to the list as we have already fired upon this location.Now that the list of elements has been exhausted, the AI returns to Hunt mode.4. Cheating AI1. This AI cheats and uses the location of the player ships to play a perfect game.1. The AI should go through the board row by row firing on all ships in one row beforepreceding to the next row that contains a ship4. Some Notes on Random1. It is super important that you follow the same procedures I did when using the random module or else your answers wont match mine. You might logically be doing the correct thing but if you dont make calls to the random module in the same order I did our results will differ so be careful.2. The only functions you will need from the random module are seed, randint, and choice.1. Make sure that you call random.seed before you make any other calls to functions inthe random module2. Random.randint is useful for placing the ships and choosing the starting turn3. Random.choice is useful for the random and smart ai (in hunt mode) to choose a location to fire on.Enter row and column to fire on separated by a space: bob Enter row and column to fire on separated by a space: 0 1 3Enter row and column to fire on separated by a space: 0 0Miss!The AI fires at location (2, 0)Miss转自:http://ass.3daixie.com/2018060769869961.html

你可能感兴趣的:(代做数据结构语言程序、数据库编程调试、调试SQL语言程序、Matlab编程调试)