Question: MACHINE BattleShipGame SETS Players = { Player 1 , Player 2 } ; Results = { Success , Failure } ; GameStates = { Deploying

MACHINE BattleShipGame
SETS
Players ={Player1, Player2};
Results ={Success, Failure};
GameStates ={Deploying, Ongoing, Player1Win, Player2Win};
Reports ={Hit, Miss, InvalidMove};
CONSTANTS
Grid
FleetSize
PROPERTIES
Grid =(1..10)*(1..10) & /*10x10 grid */
FleetSize =3/* Each player has 3 ships */
VARIABLES
player1Ships, player2Ships, /* Positions of Player1's and Player2's ships */
player1Shots, player2Shots, /* Shots taken by Player1 and Player2*/
currentPlayer, /* Whose turn it is */
gameState /* Current state of the game */
INVARIANT
player1Ships <: Grid &
player2Ships <: Grid &
card(player1Ships)<= FleetSize &
card(player2Ships)<= FleetSize &
player1Ships /\ player2Ships ={} & /* No overlapping ships */
player1Shots <: Grid &
player2Shots <: Grid &
currentPlayer : Players &
gameState : GameStates
INITIALISATION
player1Ships :={}||
player2Ships :={}||
player1Shots :={}||
player2Shots :={}||
currentPlayer := Player1||
gameState := Deploying
OPERATIONS
/* Deploy Fleet Operation */
report <-- deployFleet(player, positions)=
PRE
player : Players &
positions <: Grid &
card(positions)= FleetSize &
((player = Player1=> player1Ships ={}) &
(player = Player2=> player2Ships ={})) &
((player = Player1=> positions /\ player2Ships ={}) &
(player = Player2=> positions /\ player1Ships ={}))
THEN
IF player = Player1 THEN
player1Ships := positions
ELSE
player2Ships := positions
END ||
IF player1Ships /={} & player2Ships /={} THEN
gameState := Ongoing
END ||
report := Success
END;
/* Player Shoots Operation */
report <-- playerShoots(target)=
PRE
target : Grid &
gameState = Ongoing
THEN
IF currentPlayer = Player1 THEN
IF target : player2Ships THEN
player2Ships := player2Ships -{target}||
report := Hit ||
IF card(player2Ships)=0 THEN
gameState := Player1Win
ELSE
currentPlayer := Player2
END
ELSE
report := Miss ||
currentPlayer := Player2
END ||
player1Shots := player1Shots \/{target}
ELSE
IF target : player1Ships THEN
player1Ships := player1Ships -{target}||
report := Hit ||
IF card(player1Ships)=0 THEN
gameState := Player2Win
ELSE
currentPlayer := Player1
END
ELSE
report := Miss ||
currentPlayer := Player1
END ||
player2Shots := player2Shots \/{target}
END
END;
/* Enquiry Operation: shipLocations */
shipsquares <-- shipLocations(player)=
PRE
player : Players
THEN
IF player = Player1 THEN
shipsquares := player1Ships
ELSE
shipsquares := player2Ships
END
END;
/* Enquiry Operation: shipsLeft */
shipCounts <-- shipsLeft =
BEGIN
shipCounts :={Player1|-> card(player1Ships), Player2|-> card(player2Ships)}
END;
/* Enquiry Operation: shotsTaken */
shotCount <-- shotsTaken(player)=
PRE
player : Players
THEN
IF player = Player1 THEN
shotCount := card(player1Shots)
ELSE
shotCount := card(player2Shots)
END
END;
/* Enquiry Operation: gameStatus */
report <-- gameStatus =
BEGIN
report := gameState
END;
END
when I try to run this code on Atelier B or Pro B an error is constantly appearing at line 8(CONSTANTS) stating;
- Error occurred: parse_error
Reason: expecting: identifier literal
- Expected value(s): SET name
- unexpected token: CONCRETE_CONSTANTS
can I please get the corrected code that you have tested and can run the project
thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!