Question: use ATELIER B . . . GIVE THE WHOLE CODE WITHOUT MISTAKES PLZZZ ( attached here is a code for ur ease but there are
use ATELIER BGIVE THE WHOLE CODE WITHOUT MISTAKES PLZZZ attached here is a code for ur ease but there are some errors here, adjust the code and run it in atelier B and pro b and give the working code ps
code shud compulsorily have these code lines,
report deployFleetplayerpositions
report playerShootstarget
shipsquares shipLocationsplayer
shipCounts shipsLeft
shotCount shotsTakenplayer
report gameStatus
This system is to be developed using the B tools Atelier B and ProB.
A grid size of x squares, with the grid square representing the square at column & row
Each player has warships in their fleet.
Each warship occupies a single grid square on the grid.
The warships must be on different grid squares, ie at most warship per square.
The game starts by each player placing their ships on their own grid, each player's ships in different grid squares.
Player has the first turn.
Player shoots at Player s ships, by selecting a target square on Player s grid. If there is a ship in the target square it is a hit and the ship is deleted from Player s fleet, otherwise it is a miss and there is no change to Player s fleet.
It is then Player s turn.
Player shoots at Player s ships, by selecting a target square on Player s grid. Registering a hit or miss, as above.
The players continue to take turns until all of one player's ships have been sunk, at this point the other player is the winner.
MACHINE battlecw
SETS
ROWS; COLS; PLAYER
CONSTANTS
ROWSSET, COLSSET, PLAYERSET, SHIPSCOUNT
PROPERTIES
ROWSSET &
COLSSET &
PLAYERSET &
SHIPSCOUNT
VARIABLES
grid grid Grid for player and player
shipsleft shipsleft Ships left for player and player
currentplayer, The current player
gamestatus Game status TRUE for ongoing, FALSE for ended
INVARIANT
grid : ROWS COLS BOOL & Grid contains boolean values
grid : ROWS COLS BOOL & Grid contains boolean values
shipsleft : NAT & shipsleft SHIPSCOUNT &
shipsleft : NAT & shipsleft SHIPSCOUNT &
currentplayer : PLAYER &
gamestatus : BOOL
INITIALISATION
grid :ROWS COLS FALSE Initially no ships on grid
grid :ROWS COLS FALSE Initially no ships on grid
shipsleft : SHIPSCOUNT
shipsleft : SHIPSCOUNT
currentplayer :
gamestatus : TRUE
OPERATIONS
Deploy fleet operation
report deployFleetplayer positions
PRE
player : PLAYER &
positions : ROWS COLS &
cardpositions SHIPSCOUNT &
pos. pos : positions player gridpos FALSE & player gridpos FALSE
THEN
IF player THEN
grid : grid positions TRUE
ELSE
grid : grid positions TRUE
END;
report : "Success"
ELSE
report : "Error: Invalid positions"
END;
Player shoots operation
report playerShootstarget
PRE
target : ROWS COLS &
gamestatus TRUE
THEN
IF currentplayer THEN
IF gridtarget TRUE THEN
gridtarget : FALSE;
shipsleft : shipsleft;
IF shipsleft THEN
gamestatus : FALSE;
report : "Player Wins!"
ELSE
report : "Hit!"
END
ELSE
report : "Miss!"
END;
currentplayer :
ELSE
IF gridtarget TRUE THEN
gridtarget : FALSE;
shipsleft : shipsleft;
IF shipsleft THEN
gamestatus : FALSE;
report : "Player Wins!"
ELSE
report : "Hit!"
END
ELSE
report : "Miss!"
END;
currentplayer :
END
ELSE
report : "Error: Invalid target"
END;
Get ship locations
shipsquares shipLocationsplayer
PRE
player : PLAYER
THEN
IF player THEN
shipsquares :pos pos : ROWS COLS & gridpos TRUE
ELSE
shipsquares :pos pos : ROWS COLS & gridpos TRUE
END
END;
Get ships left
shipCounts shipsLeft
BEGIN
shipCounts :shipsleft shipsleft
END;
Get game status
report gameStatus
BEGIN
IF gamestatus THEN
report : "Ongoing"
ELSE
IF shipsleft THEN
report : "Player Wins!"
ELSE
report : "Player Wins!"
END
END
END;
END
battlecw.mch
player : PLAYER &
positions : ROWS COLS &
cardpositions SHIPSCOUNT &
pos. pos : positions player gridpos FALSE & player gridpos
FALSE
THEN
IF player THEN
gridl : gridl positions TRUE
ELSE
grid : grid positions TRUE
END;
report : "Success"
ELSE
report : "Error: Invalid positions"
END;
Player shoots operation
report playerShootstarget
PRE
target : ROWS COLS &
gamestatus TRUE
THEN
IF currentplayer THEN
IF gridtarget TRUE THEN
gridtarget : FALSE;
shins left : shins left:
batleow.mch
player : PLAYER &
positions : ROWS COLS &
cardpositions SHIPSCOUNT &
pos. pos : positions player gridpos FALSE & player gridpos
FALSE
THEN
IF player THEN
gridl : gridl positions
ELSE
grid : grid positions TRUE
END;
report : "Success"
ELSE
report : "Error: Invalid positions"
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
