Game Play:
Creating: All below either create matrices or arrays
guessBoard – keeps track of user guess spots so they can’t be guessed twice through a matrix
guessBoardcomp – keeps track of computer guesses so a spot can’t be guessed twice through a matrix
posInput – defines the valid inputs the user can have when guessing a spot through an array
Guesses: All below deal with the guesses of the user and computer
guess_x – defines the user’s row guess
guess_y – defines the user’s column guess
compGuess_x – defines the computer’s row guess
compGuess_y – defines the computer’s column guess
Sound Effects: All below deal with creating the sound effects
hitSound – loads and stores the hit sound file
song_HitSound – plays the hit sound
sinkSound – loads and stores the sink sound file
song_SinkSound – plays the sink sound
missSound – loads and stores the miss sound file
song_MissSound – plays the miss sound
applause – loads and stores the applause sound file
song_applause – plays the applause sound
Transitions: All below are used to transition from one form to another (array to singular number or for easier use in a loop)
a – defines the logical value of if the user’s row guess is a valid one
b – defines the logical value of if the user’s column guess is a valid one
connect – defines the array of 1 and 0 to see if the ship is still alive
connect2 – defines the array of 1 and 0 to see if any ship is still alive
connect3 – defines the array of 1 and 0 to see if the user’s ship is still alive
connect4 – defines the array of 1 and 0 to see if any user ships are still alive
Messages: All below are used in the creation of the dialog boxes
error1 – defines the error box pertaining to an invalid row guess from the user
error2 – defines the error box pertaining to an invalid column guess from the user
error3 – defines the error box pertaining to when the user guesses a spot they are already guessed
HitMsg – defines the message box pertaining to when the user hits a ship
SunkMsg – defines the message box pertaining to when the user sinks a ship
MissMsg – defines the message box pertaining to when the user misses a ship
WinMsg – defines the message box pertaining to when the user wins the game
CreepMsg – defines the message box pertaining to when the computer starts its turn
HitMsg2 – defines the message box pertaining to when the computer hits a ship
SunkMsg2 – defines the message box pertaining to when the computer sinks a ship
MissMsg2 – defines the message box pertaining to when the computer misses a ship
WinMsg2 – defines the message box pertaining to when the computer wins the game
child – defines the aspects of any dialog box so the ‘ok’ button can be deleted
AI: All below are needed for the computer AI
Turn – defines what turn the game is on
Prev_lastHit – holds the value of last hit from the previous turn
lastHit – defines whether the shot from the last turn was a hit
newHit – defines whether the hit from last turn was a new hit (0 consecutive hits)
ship_sunk_last_turn – defines if the computer sunk a ship last turn or not
Other: All below don’t belong to a specific category
END – defines when the large while loop should be operating or not
ship – defines which ship was hit by the user
aliveShip – defines whether the ship is sunk (0) or not sunk (1)
end_of_game – defines whether the user sunk all of the computer ships and won the game
ship2 – defines the user’s ship the computer hit
aliveShip2 – defines whether the ship2 is sunk (0) or not (1)
end_of_game2 – defines whether the computer sunk all of the user’s ships and won the game
computerTurn.m – AI Decision Function
Persistent Variables
These variables will hold their states between function runs. This allows the function to have a feedback loop for deciding the next output.
prev_shot: Holds the value of the previous shot output by the function
initial_hit: Holds the value of the initial hit if we find a new first hit
prev_dir: Holds the previous direction fired in (initialized as 0)
prev_hlt_state: Holds the previous state of hit_last_turn. This allows us to find whether we ran off a ship or not.
Input
game_board: Holds the “guess” board for the current game. The game board should be a 10×10 of 0 and 1, with 1 for guess.
turn: Current turn
hit_last_turn: Holds whether we had a hit last turn
new_hit: Holds whether we had a hit last turn that was non-consecutive (0 previous hits)
ship_sunk_last_turn: Holds whether we sunk a ship last turn
Output
final_x, final_y: X and Y variables to output
Setup & Board Display
A – Stored initial input values of the Ship Direction
B – Stored initial input values of the Ship Row
C – Stored initial input values of the Ship Column
h – Input value to indicate horizontal direction
H – Input value to indicate horizontal direction
v – Input value to indicate vertical direction
V – Input value to indicate vertical direction
i – number of ships in loop for initialization process
j – number of ships in loop for picture process
K – Ship type
ShipColumn – C rounded down to nearest whole number
ShipDirection – A rounded down to nearest whole number
ShipRow – B rounded down to nearest whole number
PLoc – Matrix of user’s inputs containing K, ShipColumn, ShipRow, and ShipDirection
OLoc- Matrix created by Setup.m that contains ShipType, ShipOr, row, and column for each.
Occupied – Occupied matrix for player ships
OppOcu – Occupied matrix of opponent ships
column- variable denoting column of the opponent ship
row- variable denoting row of the opponent ship
ShipType – indicates which ship the program is on
ShipLen – Assigns each ship with appropriate length
BodLen – Length of the body of each individual ship
ShipOr – Orientation of each ship
ShipFront – Variable for picture of front of ship
ShipBody – Variable for picture of body of ship
ShipBack – Variable for picture of back of ship
Opponent_Board – image matrix that shows an empty board
Player_Board – image matrix that shows players ships on a board
Boat_FrontBack_1 -image for the back of vertical ships
Boat_FrontBack_1_hit – image for hit marker put on the back of vertical ships
Boat_FrontBack_2 – image for the front of vertical ships
Boat_FrontBack_2_hit – image for hit marker put on the front of vertical ships
Boat_FrontBack_3 – image for the front of horizontal ships
Boat_FrontBack_3_hit – image for hit marker put on the front of horizontal ships
Boat_FrontBack_4 – image for the back of horizontal ships
Boat_FrontBack_4_hit – image for hit marker put on the back of horizontal ships
Boat_Mid_hor – image for the body of horizontal ships
Boat_Mid_hor_hit – image for hit marker put on the body of horizontal ships
Boat_Mid_vert – image for the body of vertical ships
Boat_Mid_vert_hit – image for hit marker put on the body of vertical ships