Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This exercise is to be completed as an individual . Objectives: implementing fun

ID: 674665 • Letter: T

Question

This exercise is to be completed as an individual.

Objectives: implementing functions which accept multiple arguments and return values; creating and accessing one- and two-dimensional arrays; and using static block-scope variables to maintain state within a function.

Battle Ship is a strategy game for two players. To prepare for this exercise, you will need to read the BattleShip game instructions.. For those of you that have not played this game before (and for those that wish to refresh their memory of this game) you may try out an interactive electronic MS Windows version:

Download the Battleship archive file

Extract the executable

Run it.

In part 1 of this exercise, you will be working as individuals in creating one function to interface with an electronic Battle Ship game:

lastNameAttack(int mode, int opponent) is your main driver function used to attack the opponent's ships. This is where much of the strategy for your program goes. (The other function you implement will be described later.) Depending on the mode, you may be starting a new game (BS_MODE_NEW_GAME), or continuing an existing one (BS_MODE_CONTINUE_GAME). It calls the opponent's incomingFire() function just as the opponent will calls yours (initially you will be using an internally defined function, until you complete part 2 of this assignment). Begin writing your attack function using the following code.

The fire() function you will be calling accepts two arguments:

A capital letter (char) in the range of 'A' .. 'A'+BS_GRID_ROWS-1 that indicates the row in your grid to attack.

An integer (int) in the range of 1 .. BS_GRID_COLS that indicates the column of your grid to attack.

The return code will be:

0 if there is only open water.

The bit BS_SHIP_HIT will be set, or both BS_SHIP_HIT and BS_SHIP_SANK will be set. In addition, the ship that was hit will be indicated in the lowest four bits of the return code. You may use BS_SHIP_MASK to help extract the number for the ship type.

In order to interface properly with Battle Ship, you will need create the file battleship.h and store it in the same folder as your .cpp file created above. Do not copy this code into your .cpp file.

Everywhere in your program code, you must use the symbolic constants defined in battleship.h file where possible. Do not "hard-code" any literal values—they might change, e.g the number of rows or columns for this exercise may be adjusted before recompiling and testing your program. Your implementation should work for any reasonable number of rows or columns.

Milestone submission (part 1)

Create the .cpp file above replacing text with your name where required. Implement your attack() function so that no critical errors occur. Non-critical errors are allowed at this time.

Final submission (part 1)

Implement your attack() function so that no critical, nor non-critical errors occur. You must also implement some intelligence to your program that observes the return code of the opponents fire() function and acts accordingly. You will find you will experience two modes of play:

Searching for any ship (unbounded search): you are unaware of any un-sunk ships

Searching for a specific ship (focused search): you have already hit a ship somewhere, it is not sunk yet, and you need to finish sinking it.

Furthermore, challenge yourself to implement a version that does the best against the professor's code that you are linking with. There will also be an opportunity during lab to compete with other student versions of Battle Ship prior to the part 2 submission date.

Testing your implementation

Here is what you need to do:

Write the functions as described above. Make sure all required header files are included at the top of your program file.

Since you will not be submitting the main() function, You will be compiling your program by doing the following:

Type your program code into Code::Blocks

Save the linkable test driver libBattleShip.a to the same folder where your C++ program file is. (Right-click, then Save Link As ... or similar.)

This project also requires a special graphics library. You must also download and save libbssupl.a as you did for libBattleShip.a

In Code::Blocks, go to the Settings menu, and select Compiler to bring up a dialog box

Make sure the Global Compiler Settings is selected on the left, then click on theLinker Settings tab

Just below the Link libraries box, click the Add button, then navigate to where you saved libBattleShip.a. Click Ok to close the library selection dialog box. Repeat forlibbssupl.a. Now click Ok to close the Global Compiler Settings.

You can now Compile and Run your program using the test driver. If your program does not compile, then you probably have not defined your function correctly, or forgot to include all appropriate header files.

When running with the test driver, the program output will tell you if it is working correctly. Your program will be evaluated using the exact same test driver.

Submit only the file containing your functions. You should not provide any test main() that you may have written for your own test purposes. When you submit your program on the class website, you should receive no compiler or linker errors.

Explanation / Answer

CODE :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote