diff options
-rw-r--r-- | readme.md | 0 | ||||
-rw-r--r-- | readme.org | 1447 | ||||
-rw-r--r-- | src/files.rs | 3 | ||||
-rw-r--r-- | src/lib.rs | 2 |
4 files changed, 1450 insertions, 2 deletions
diff --git a/readme.md b/readme.md deleted file mode 100644 index e69de29..0000000 --- a/readme.md +++ /dev/null diff --git a/readme.org b/readme.org new file mode 100644 index 0000000..ff3e319 --- /dev/null +++ b/readme.org @@ -0,0 +1,1447 @@ +* State.json + +#+BEGIN_EXAMPLE +State = {PlayerMap, OpponentMap, GameVersion=String, GameLevel=u16, Round=u16, MapDimension=u16, Phase=u16, Player1Map=null, Player2Map=null} + +PlayerMap = {Cells=[PlayerCell], Owner, MapWidth=u16, MapHeight=u16} + +PlayerCell = {Occupied=bool, Hit=bool, X=u16, Y=u16} + +Owner = {FailedFirstPhaseCommands=u16, Name=String, Ships=[PlayerShip], Points=u16, Killed=bool, IsWinner=bool, ShotsFired=u16, ShotsHit=u16, ShipsRemaining=u16, Key=String} + +PlayerShip = {Cells=[PlayerCell], Destroyed=bool, Placed=bool, ShipType=String, Weapons=[PlayerWeapon], } + +PlayerWeapon = {WeaponType=String} + +OpponentMap = {Ships=[OpponentShip], Alive=bool, Points=u16, Name=String, Cells=[OpponentCell]} + +OpponentShip = {Destroyed=bool, ShipType=String} + +OpponentCell = {Damaged=bool, Missed=bool, X=u16, Y=u16} + +#+END_EXAMPLE + +* State.json example + +#+BEGIN_SRC json +{ + "PlayerMap": { + "Cells": [ + { + "Occupied": false, + "Hit": true, + "X": 0, + "Y": 0 + }, + { + "Occupied": false, + "Hit": false, + "X": 0, + "Y": 1 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 2 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 3 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 0, + "Y": 5 + }, + { + "Occupied": true, + "Hit": true, + "X": 0, + "Y": 6 + }, + { + "Occupied": true, + "Hit": true, + + "X": 0, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 8 + }, + { + "Occupied": false, + "Hit": true, + "X": 0, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 0 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 2 + }, + { + "Occupied": false, + "Hit": true, + "X": 1, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 1, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 1, + "Y": 8 + }, + { + "Occupied": false, + "Hit": true, + "X": 1, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 0 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 3 + }, + { + "Occupied": false, + "Hit": true, + "X": 2, + "Y": 4 + }, + { + "Occupied": false, + "Hit": true, + "X": 2, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 7 + }, + { + "Occupied": true, + "Hit": true, + "X": 2, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 2, + "Y": 9 + }, + { + "Occupied": false, + "Hit": true, + "X": 3, + "Y": 0 + }, + { + "Occupied": false, + "Hit": true, + "X": 3, + "Y": 1 + }, + { + "Occupied": false, + "Hit": true, + "X": 3, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 3, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 3, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 4, + "Y": 0 + }, + { + "Occupied": false, + "Hit": true, + "X": 4, + "Y": 1 + }, + { + "Occupied": false, + "Hit": true, + "X": 4, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 4, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 4, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 4, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 4, + "Y": 6 + }, + { + "Occupied": false, + "Hit": true, + "X": 4, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 4, + "Y": 8 + }, + { + "Occupied": false, + "Hit": true, + "X": 4, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 0 + }, + { + "Occupied": true, + "Hit": true, + "X": 5, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 5, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 5, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 0 + }, + { + "Occupied": true, + "Hit": false, + "X": 6, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 2 + }, + { + "Occupied": false, + "Hit": true, + "X": 6, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 4 + }, + { + "Occupied": false, + "Hit": true, + "X": 6, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 7 + }, + { + "Occupied": false, + "Hit": true, + "X": 6, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 6, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 0 + }, + { + "Occupied": true, + "Hit": true, + "X": 7, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 4 + }, + { + "Occupied": true, + "Hit": false, + "X": 7, + "Y": 5 + }, + { + "Occupied": true, + "Hit": false, + "X": 7, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 7 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 7, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 0 + }, + { + "Occupied": true, + "Hit": false, + "X": 8, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 2 + }, + { + "Occupied": false, + "Hit": true, + "X": 8, + "Y": 3 + }, + { + "Occupied": false, + "Hit": true, + "X": 8, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 7 + }, + { + "Occupied": false, + "Hit": false, + "X": 8, + "Y": 8 + }, + { + "Occupied": false, + "Hit": true, + "X": 8, + "Y": 9 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 0 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 1 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 2 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 3 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 4 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 5 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 6 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 7 + }, + { + "Occupied": false, + "Hit": true, + "X": 9, + "Y": 8 + }, + { + "Occupied": false, + "Hit": false, + "X": 9, + "Y": 9 + } + ], + "Owner": { + "FailedFirstPhaseCommands": 0, + "Name": "Admiral Worthebot", + "Ships": [ + { + "Cells": [ + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 2 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 3 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 4 + } + ], + "Destroyed": false, + "Placed": true, + "ShipType": "Submarine", + "Weapons": [ + { + "WeaponType": "SingleShot" + } + ] + }, + { + "Cells": [ + { + "Occupied": true, + "Hit": false, + "X": 7, + "Y": 6 + }, + { + "Occupied": true, + "Hit": false, + "X": 7, + "Y": 5 + } + ], + "Destroyed": false, + "Placed": true, + "ShipType": "Destroyer", + "Weapons": [ + { + "WeaponType": "SingleShot" + } + ] + }, + { + "Cells": [ + { + "Occupied": true, + "Hit": true, + "X": 5, + "Y": 1 + }, + { + "Occupied": true, + "Hit": false, + "X": 6, + "Y": 1 + }, + { + "Occupied": true, + "Hit": true, + "X": 7, + "Y": 1 + }, + { + "Occupied": true, + "Hit": false, + "X": 8, + "Y": 1 + } + ], + "Destroyed": false, + "Placed": true, + "ShipType": "Battleship", + "Weapons": [ + { + "WeaponType": "SingleShot" + } + ] + }, + { + "Cells": [ + { + "Occupied": true, + "Hit": false, + "X": 5, + "Y": 8 + }, + { + "Occupied": true, + "Hit": false, + "X": 4, + "Y": 8 + }, + { + "Occupied": true, + "Hit": false, + "X": 3, + "Y": 8 + }, + { + "Occupied": true, + "Hit": true, + "X": 2, + "Y": 8 + }, + { + "Occupied": true, + "Hit": false, + "X": 1, + "Y": 8 + } + ], + "Destroyed": false, + "Placed": true, + "ShipType": "Carrier", + "Weapons": [ + { + "WeaponType": "SingleShot" + } + ] + }, + { + "Cells": [ + { + "Occupied": true, + "Hit": true, + "X": 0, + "Y": 6 + }, + { + "Occupied": true, + "Hit": true, + "X": 0, + "Y": 7 + }, + { + "Occupied": true, + "Hit": false, + "X": 0, + "Y": 8 + } + ], + "Destroyed": false, + "Placed": true, + "ShipType": "Cruiser", + "Weapons": [ + { + "WeaponType": "SingleShot" + } + ] + } + ], + "Points": 280, + "Killed": false, + "IsWinner": false, + "ShotsFired": 86, + "ShotsHit": 16, + "ShipsRemaining": 5, + "Key": "B" + }, + "MapWidth": 10, + "MapHeight": 10 + }, + "OpponentMap": { + "Ships": [ + { + "Destroyed": false, + "ShipType": "Submarine" + }, + { + "Destroyed": true, + "ShipType": "Destroyer" + }, + { + "Destroyed": true, + "ShipType": "Battleship" + }, + { + "Destroyed": true, + "ShipType": "Carrier" + }, + { + "Destroyed": true, + "ShipType": "Cruiser" + } + ], + "Alive": true, + "Points": 50, + "Name": "John", + "Cells": [ + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 0 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 2 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 4 + }, + { + "Damaged": false, + "Missed": false, + "X": 0, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 0, + "Y": 9 + }, + { + "Damaged": true, + "Missed": false, + "X": 1, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 1, + "Y": 1 + }, + { + "Damaged": true, + "Missed": false, + "X": 1, + "Y": 2 + }, + { + "Damaged": true, + "Missed": false, + "X": 1, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 1, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 1, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 1, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 1, + "Y": 7 + }, + { + "Damaged": true, + "Missed": false, + "X": 1, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 1, + "Y": 9 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 0 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 2 + }, + { + "Damaged": false, + "Missed": false, + "X": 2, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 7 + }, + { + "Damaged": false, + "Missed": false, + "X": 2, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 2, + "Y": 9 + }, + { + "Damaged": false, + "Missed": false, + "X": 3, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 3, + "Y": 1 + }, + { + "Damaged": false, + "Missed": false, + "X": 3, + "Y": 2 + }, + { + "Damaged": false, + "Missed": false, + "X": 3, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 3, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 3, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 3, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 3, + "Y": 7 + }, + { + "Damaged": true, + "Missed": false, + "X": 3, + "Y": 8 + }, + { + "Damaged": false, + "Missed": false, + "X": 3, + "Y": 9 + }, + { + "Damaged": false, + "Missed": false, + "X": 4, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 4, + "Y": 1 + }, + { + "Damaged": true, + "Missed": false, + "X": 4, + "Y": 2 + }, + { + "Damaged": true, + "Missed": false, + "X": 4, + "Y": 3 + }, + { + "Damaged": true, + "Missed": false, + "X": 4, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 4, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 4, + "Y": 6 + }, + { + "Damaged": false, + "Missed": false, + "X": 4, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 4, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 4, + "Y": 9 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 5, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 2 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 5, + "Y": 8 + }, + { + "Damaged": false, + "Missed": false, + "X": 5, + "Y": 9 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 6, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 2 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 6, + "Y": 8 + }, + { + "Damaged": false, + "Missed": false, + "X": 6, + "Y": 9 + }, + { + "Damaged": false, + "Missed": false, + "X": 7, + "Y": 0 + }, + { + "Damaged": true, + "Missed": false, + "X": 7, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 2 + }, + { + "Damaged": true, + "Missed": false, + "X": 7, + "Y": 3 + }, + { + "Damaged": true, + "Missed": false, + "X": 7, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 7, + "Y": 9 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 0 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 1 + }, + { + "Damaged": false, + "Missed": false, + "X": 8, + "Y": 2 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 7 + }, + { + "Damaged": false, + "Missed": false, + "X": 8, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 8, + "Y": 9 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 0 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 1 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 2 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 3 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 4 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 5 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 6 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 7 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 8 + }, + { + "Damaged": false, + "Missed": true, + "X": 9, + "Y": 9 + } + ] + }, + "GameVersion": "1.0.0", + "GameLevel": 1, + "Round": 87, + "MapDimension": 10, + "Phase": 2, + "Player1Map": null, + "Player2Map": null +} +#+END_SRC diff --git a/src/files.rs b/src/files.rs index 99dca8c..7f3daed 100644 --- a/src/files.rs +++ b/src/files.rs @@ -5,9 +5,10 @@ use std::path::PathBuf; use actions::*; +const STATE_FILE: &'static str = "state.json"; + const COMMAND_FILE: &'static str = "command.txt"; const PLACE_FILE: &'static str = "place.txt"; -const STATE_FILE: &'static str = "state.json"; pub fn read_file(working_dir: &PathBuf) -> Result<json::JsonValue, String> { let state_path = working_dir.join(STATE_FILE); @@ -21,7 +21,7 @@ use std::path::PathBuf; pub fn write_move(working_dir: PathBuf) -> Result<(), String> { let state_json = read_file(&working_dir)?; - println!("{}", state_json); + println!("\n\n{}\n\n", state_json.pretty(2)); let is_place_phase = state_json["Phase"] == 1; let map_size = State::map_size_from_json(&state_json)?; |