Question: use ATELIER B . . . GIVE THE WHOLE CODE WITHOUT MISTAKES PLZZZ ( attached here is a code for ur ease but there are

use ATELIER B...GIVE 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 --deployFleet(player,positions)
report --playerShoots(target)
shipsquares --shipLocations(player)
shipCounts --shipsLeft
shotCount --shotsTaken(player)
report --gameStatus
This system is to be developed using the B tools Atelier B and ProB.
A grid size of 10 x 10 squares, with the grid square (6,8) representing the square at column 6 & row 8.
Each player has 3 warships in their fleet.
Each warship occupies a single grid square on the grid.
The warships must be on different grid squares, i.e. at most 1 warship per square.
1. The game starts by each player placing their 3 ships on their own grid, each player's ships in different grid squares.
2. Player 1 has the first turn.
3. Player 1 shoots at Player 2's ships, by selecting a target square on Player 2's grid. If there is a ship in the target square it is a hit and the ship is deleted from Player 2's fleet, otherwise it is a miss and there is no change to Player 2's fleet.
4. It is then Player 2's turn.
5. Player 2 shoots at Player 1's ships, by selecting a target square on Player 1's grid. Registering a hit or miss, as above.
6. 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
ROWS_SET, COLS_SET, PLAYER_SET, SHIPS_COUNT
PROPERTIES
ROWS_SET ={1,2,3,4,5,6,7,8,9,10} &
COLS_SET ={1,2,3,4,5,6,7,8,9,10} &
PLAYER_SET ={1,2} &
SHIPS_COUNT =3
VARIABLES
grid1, grid2,// Grid for player 1 and player 2
ships_left1, ships_left2,// Ships left for player 1 and player 2
current_player, // The current player
game_status // Game status (TRUE for ongoing, FALSE for ended)
INVARIANT
grid1 : ROWS * COLS --> BOOL & // Grid 1 contains boolean values
grid2 : ROWS * COLS --> BOOL & // Grid 2 contains boolean values
ships_left1 : NAT & ships_left1= SHIPS_COUNT &
ships_left2 : NAT & ships_left2= SHIPS_COUNT &
current_player : PLAYER &
game_status : BOOL
INITIALISATION
grid1 :=(ROWS * COLS)| FALSE ||// Initially no ships on grid 1
grid2 :=(ROWS * COLS)| FALSE ||// Initially no ships on grid 2
ships_left1 := SHIPS_COUNT ||
ships_left2 := SHIPS_COUNT ||
current_player :=1||
game_status := TRUE
OPERATIONS
// Deploy fleet operation
report -- deployFleet(player, positions)=
PRE
player : PLAYER &
positions : ROWS * COLS &
card(positions)= SHIPS_COUNT &
!pos. (pos : positions =>(player =1=> grid1(pos)= FALSE) & (player =2=> grid2(pos)= FALSE))
THEN
IF player =1 THEN
grid1 := grid1+ positions | TRUE
ELSE
grid2 := grid2+ positions | TRUE
END;
report := "Success"
ELSE
report := "Error: Invalid positions"
END;
// Player shoots operation
report -- playerShoots(target)=
PRE
target : ROWS * COLS &
game_status = TRUE
THEN
IF current_player =1 THEN
IF grid2(target)= TRUE THEN
grid2(target) := FALSE;
ships_left2 := ships_left2-1;
IF ships_left2=0 THEN
game_status := FALSE;
report := "Player 1 Wins!"
ELSE
report := "Hit!"
END
ELSE
report := "Miss!"
END;
current_player :=2
ELSE
IF grid1(target)= TRUE THEN
grid1(target) := FALSE;
ships_left1 := ships_left1-1;
IF ships_left1=0 THEN
game_status := FALSE;
report := "Player 2 Wins!"
ELSE
report := "Hit!"
END
ELSE
report := "Miss!"
END;
current_player :=1
END
ELSE
report := "Error: Invalid target"
END;
// Get ship locations
shipsquares -- shipLocations(player)=
PRE
player : PLAYER
THEN
IF player =1 THEN
shipsquares :={pos | pos : ROWS * COLS & grid1(pos)= TRUE}
ELSE
shipsquares :={pos | pos : ROWS * COLS & grid2(pos)= TRUE}
END
END;
// Get ships left
shipCounts -- shipsLeft =
BEGIN
shipCounts :=(ships_left1, ships_left2)
END;
// Get game status
report -- gameStatus =
BEGIN
IF game_status THEN
report := "Ongoing"
ELSE
IF ships_left1=0 THEN
report := "Player 2 Wins!"
ELSE
report := "Player 1 Wins!"
END
END
END;
END
battlecw.mch
player : PLAYER &
positions : ROWS * COLS &
card(positions)= SHIPS_COUNT &
!pos. (pos : positions =>(player =1=> grid1(pos)= FALSE) & (player =2=> grid2(pos)=
FALSE))
THEN
IF player =1 THEN
gridl := gridl + positions | TRUE
ELSE
grid2 := grid2+ positions | TRUE
END;
report := "Success"
ELSE
report := "Error: Invalid positions"
END;
// Player shoots operation
report -- playerShoots(target)=
PRE
target : ROWS * COLS &
game_status = TRUE
THEN
IF current_player =1 THEN
IF grid2(target)= TRUE THEN
grid2(target) := FALSE;
shins left.2 := shins left.2-1:
batleow.mch
player : PLAYER &
positions : ROWS * COLS &
card(positions)= SHIPS_COUNT &
!pos. (pos : positions =>(player =1=> grid1(pos)= FALSE) & (player =2=> grid2(pos)=
FALSE))
THEN
IF player =1 THEN
gridl := gridl + positions
ELSE
grid2 := grid2+ 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 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!