Question: this is the code i came up with edit this according to the example code given below the battlecw machine. the error i get is
this is the code i came up with edit this according to the example code given below the battlecw machine.
the error i get is also attached here as a snippet
MACHINE battlecw
SETS
Players Player Player;
Results Success Failure
CONSTANTS
Grid, FleetSize
PROPERTIES
Grid & A x grid
FleetSize Each player has ships
VARIABLES
playerShips, playerShips, Positions of Player s and Player s ships
playerShots, playerShots, Shots taken by Player and Player
currentPlayer, Whose turn it is
gameState Current state of the game
INVARIANT
playerShips : Grid &
playerShips : Grid &
cardplayerShips FleetSize &
cardplayerShips FleetSize &
playerShips playerShips & No overlapping ships
playerShots : Grid &
playerShots : Grid &
currentPlayer : Players &
gameState : Deploying Ongoing, PlayerWin, PlayerWin
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
ELSE
report : Failure
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 cardplayerShips THEN
gameState : PlayerWin
ELSE
currentPlayer : Player
END
ELSE
report : "Miss";
currentPlayer : Player
END;
playerShots : playerShots target
END
ELSE
report : "Invalid move"
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
example code for the code writing
MACHINE
NoughtsCrosses
SETS
Players Noughts Crosses;
Results Success Failure
CONSTANTS
Grid, winningSubsets
PROPERTIES
Grid &
winningSubsets : POWGrid &
winningSubsets
id
VARIABLES
noughts, crosses
INVARIANT
noughts : Grid & crosses : Grid & noughts crosses
INITIALISATION
noughts : crosses :
OPERATIONS
res placeNoughtpp
PRE
pp : Grid
THEN
IF
pp : noughts crosses
THEN
res : Failure
ELSE
noughts : noughts pp
res : Success
END
END;
res placeCrosspp
PRE
pp : Grid
THEN
IF
pp : noughts crosses
THEN
res : Failure
ELSE
crosses : crosses pp
res : Success
END
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
