Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. (* Auto-generated code below aims at helping you parse *)
  2. (* the standard input according to the problem statement. *)
  3. open System
  4. open System.Collections.Generic
  5.  
  6. type EntityId = int
  7. type Orientation =
  8. | Right = 0
  9. | RightTop = 1
  10. | LeftTop = 2
  11. | Left = 3
  12. | LeftBottom = 4
  13. | RightBottom = 5
  14.  
  15. type Coord = {x : int; y :int}
  16. type Speed = None = 0 | slow = 1 | Fast = 2
  17. type Ownership = Own = 1 | Ennemy = 0
  18. type RhumQuantity = int
  19.  
  20. type Ship = {id:EntityId; position:Coord; orientation:Orientation; speed:Speed; rhum:RhumQuantity; owner:Ownership}
  21. type Barrel = {id: EntityId; position: Coord; rhum:RhumQuantity}
  22.  
  23. type Entity =
  24. | Ship of Ship
  25. | Barrel of Barrel
  26.  
  27. type GameInfos = {myShips:Ship list; ennemies:Ship list; barrels:Barrel list}
  28.  
  29. let createShip (values:string[]) =
  30. let coord = { x = int(values.[2]); y = int(values.[3]) }
  31. {id=int(values.[0]);
  32. position=coord;
  33. orientation=enum<Orientation>(int(values.[4]));
  34. speed=enum<Speed>(int(values.[5]));
  35. rhum= int(values.[6]);
  36. owner= enum<Ownership>(int(values.[7]))}
  37.  
  38. let createBarrel (values:string[]) =
  39. let coord = { x = int(values.[2]); y = int(values.[3]) }
  40. {id= int(values.[0]);
  41. position = coord;
  42. rhum = int(values.[4])}
  43.  
  44.  
  45. let createEntity (values:string[]) =
  46. match values.[1] with
  47. | "SHIP" -> Entity.Ship(createShip values)
  48. | "BARREL" -> Entity.Barrel(createBarrel values)
  49. | _ -> failwith "WTF is this type ?"
  50.  
  51.  
  52. let noShip = createShip [|"-1";"SHIP";"-1";"-1";"0";"0";"0"|]
  53.  
  54.  
  55.  
  56. (* game loop *)
  57. while true do
  58. let myShipCount = int(Console.In.ReadLine()) (* the number of remaining ships *)
  59. let entityCount = int(Console.In.ReadLine()) (* the number of entities (e.g. ships, mines or cannonballs) *)
  60. let game = {myShips= []; ennemies= []; barrels = []}
  61. let mutable myShip = noShip
  62. let mutable ennemyShip = noShip
  63. let barrels:SortedList<Coord,Barrel> = SortedList<Coord,Barrel>()
  64. let entities =
  65. seq { for i in 0 .. entityCount - 1 -> i}
  66. |> Seq.map (fun _ -> Console.In.ReadLine().Split [|' '|])
  67. |> Seq.map createEntity
  68. |> Seq.fold (fun acc entity ->
  69. match entity with
  70. | Ship ship -> match ship.owner with
  71. | Ownership.Own -> myShip <- ship
  72. | Ownership.Ennemy -> ennemyShip <- ennemyShip
  73. | Barrel barrel -> barrels.Add(barrel)
  74. ) game
  75.  
  76.  
  77.  
  78. for i in 0 .. entityCount - 1 do
  79. let token = (Console.In.ReadLine()).Split [|' '|]
  80. let entityId = int(token.[0])
  81. let entityType = token.[1]
  82. let x = int(token.[2])
  83. let y = int(token.[3])
  84. let arg1 = int(token.[4])
  85. let arg2 = int(token.[5])
  86. let arg3 = int(token.[6])
  87. let arg4 = int(token.[7])
  88. ()
  89.  
  90. for i in 0 .. myShipCount - 1 do
  91.  
  92. (* Write an action using printfn *)
  93. (* To debug: Console.Error.WriteLine("Debug message") *)
  94.  
  95. printfn "MOVE 11 10" (* Any valid action, such as "WAIT" or "MOVE x y" *)
  96. ()
  97.  
  98. ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement