Question: debug this code and check whether the following works successfully or not? deployFleet operation, playerShoots operation, shipLocations operation, shipsLeft operation, shotsTaken operation, gameStatus operation MACHINE
debug this code
and check whether the following works successfully or not?
deployFleet operation, playerShoots operation, shipLocations operation, shipsLeft operation, shotsTaken operation, gameStatus operation
MACHINE Battleship
SETS
Players Player Player;
Results Success Failure;
GameStates Deploying Ongoing, PlayerWin, PlayerWin;
Reports Hit Miss, InvalidMove;
CONSTANTS
Grid, FleetSize
PROPERTIES
Grid & x grid
FleetSize Each player has ships
VARIABLES
playerShips, playerShips, Positions of Players and Players ships
playerShots, playerShots, Shots taken by Player and Player
currentPlayer, Whose turn it is
gameState Current state of the game
INVARIANT
playerShips : Grid and
playerShips : Grid &
cardplayerShips FleetSize &
cardplayerShips FleetSize &
playerShips playerShips & No overlapping ships
playerShots : Grid &
playerShots : Grid &
currentPlayer : Players &
gameState : GameStates
INITIALISATION
playerShips :
playerShips :
playerShots :
playerShots :
currentPlayer : Player
gameState : Deploying
OPERATIONS
Deploy Fleet Operation
report deployFleetplayer positions
PRE
player : Players &
positions : Grid &
cardpositions FleetSize &
player Player playerShips &
player Player playerShips &
player Player positions playerShips &
player Player positions playerShips
THEN
IF player Player THEN
playerShips : positions
ELSE
playerShips : positions
END
IF playerShips & playerShips THEN
gameState : Ongoing
END
report : Success
END;
Player Shoots Operation
report playerShootstarget
PRE
target : Grid &
gameState Ongoing
THEN
IF currentPlayer Player THEN
IF target : playerShips THEN
playerShips : playerShips target
report : Hit
IF cardplayerShips THEN
gameState : PlayerWin
ELSE
currentPlayer : Player
END
ELSE
report : Miss
currentPlayer : Player
END
playerShots : playerShots target
ELSE
IF target : playerShips THEN
playerShips : playerShips target
report : Hit
IF card playerShips THEN
gameState : PlayerWin
ELSE
currentPlayer : Player
END
ELSE
report : Miss
currentPlayer : Player
END
playerShots : playerShots target
END
END;
Enquiry Operation: shipLocations
shipsquares shipLocationsplayer
PRE
player : Players
THEN
IF player Player THEN
shipsquares : playerShips
ELSE
shipsquares : playerShips
END
END;
Enquiry Operation: shipsLeft
shipCounts shipsLeft
BEGIN
shipCounts :Player cardplayerShips Player cardplayerShips
END;
Enquiry Operation: shotsTaken
shotCount shotsTakenplayer
PRE
player : Players
THEN
IF player Player THEN
shotCount : cardplayerShots
ELSE
shotCount : cardplayerShots
END
END;
Enquiry Operation: gameStatus
report gameStatus
BEGIN
report : gameState
END;
END
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
