Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Auto-generated code below aims at helping you parse *)
- (* the standard input according to the problem statement. *)
- open System
- open System.Collections.Generic
- type EntityId = int
- type Orientation =
- | Right = 0
- | RightTop = 1
- | LeftTop = 2
- | Left = 3
- | LeftBottom = 4
- | RightBottom = 5
- type Coord = {x : int; y :int}
- type Speed = None = 0 | slow = 1 | Fast = 2
- type Ownership = Own = 1 | Ennemy = 0
- type RhumQuantity = int
- type Ship = {id:EntityId; position:Coord; orientation:Orientation; speed:Speed; rhum:RhumQuantity; owner:Ownership}
- type Barrel = {id: EntityId; position: Coord; rhum:RhumQuantity}
- type Entity =
- | Ship of Ship
- | Barrel of Barrel
- type GameInfos = {myShips:Ship list; ennemies:Ship list; barrels:Barrel list}
- let createShip (values:string[]) =
- let coord = { x = int(values.[2]); y = int(values.[3]) }
- {id=int(values.[0]);
- position=coord;
- orientation=enum<Orientation>(int(values.[4]));
- speed=enum<Speed>(int(values.[5]));
- rhum= int(values.[6]);
- owner= enum<Ownership>(int(values.[7]))}
- let createBarrel (values:string[]) =
- let coord = { x = int(values.[2]); y = int(values.[3]) }
- {id= int(values.[0]);
- position = coord;
- rhum = int(values.[4])}
- let createEntity (values:string[]) =
- match values.[1] with
- | "SHIP" -> Entity.Ship(createShip values)
- | "BARREL" -> Entity.Barrel(createBarrel values)
- | _ -> failwith "WTF is this type ?"
- let noShip = createShip [|"-1";"SHIP";"-1";"-1";"0";"0";"0"|]
- (* game loop *)
- while true do
- let myShipCount = int(Console.In.ReadLine()) (* the number of remaining ships *)
- let entityCount = int(Console.In.ReadLine()) (* the number of entities (e.g. ships, mines or cannonballs) *)
- let game = {myShips= []; ennemies= []; barrels = []}
- let mutable myShip = noShip
- let mutable ennemyShip = noShip
- let barrels:SortedList<Coord,Barrel> = SortedList<Coord,Barrel>()
- let entities =
- seq { for i in 0 .. entityCount - 1 -> i}
- |> Seq.map (fun _ -> Console.In.ReadLine().Split [|' '|])
- |> Seq.map createEntity
- |> Seq.fold (fun acc entity ->
- match entity with
- | Ship ship -> match ship.owner with
- | Ownership.Own -> myShip <- ship
- | Ownership.Ennemy -> ennemyShip <- ennemyShip
- | Barrel barrel -> barrels.Add(barrel)
- ) game
- for i in 0 .. entityCount - 1 do
- let token = (Console.In.ReadLine()).Split [|' '|]
- let entityId = int(token.[0])
- let entityType = token.[1]
- let x = int(token.[2])
- let y = int(token.[3])
- let arg1 = int(token.[4])
- let arg2 = int(token.[5])
- let arg3 = int(token.[6])
- let arg4 = int(token.[7])
- ()
- for i in 0 .. myShipCount - 1 do
- (* Write an action using printfn *)
- (* To debug: Console.Error.WriteLine("Debug message") *)
- printfn "MOVE 11 10" (* Any valid action, such as "WAIT" or "MOVE x y" *)
- ()
- ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement