Skip to content

Instantly share code, notes, and snippets.

View jasondown's full-sized avatar

Jason Down jasondown

View GitHub Profile
// SampleData -> string
let collect:Collect = fun s -> sprintf "CONNECT %i" <| s.Id
// MoleculeType -> string
let gather:Gather = fun m -> sprintf "CONNECT %s" <| m.ToString()
// SampleData -> string
let produce:Produce = fun s -> sprintf "CONNECT %i" s.Id
// Module -> string
// Robot -> SampleData -> bool
let canMakeSample (robot : Robot) (sample : SampleData) =
sample.Molecules.Counts
|> Map.forall (fun mt count -> robot.Molecules.Counts.[mt] >= count)
// Robot -> SampleData -> MoleculeType
let getRequiredMolecule (robot : Robot) (sample : SampleData) =
let ms =
sample.Molecules.Counts
|> Map.filter (fun mt count -> robot.Molecules.Counts.[mt] < count)
|> Seq.head
ms.Key
let getMove (gs : GameState) =
let me = gs.Robots |> List.find (fun r -> r.Player = Player.Me)
let mySamples = gs.Samples |> List.filter (fun s -> s.CarriedBy = Player.Me)
let samplesReady = mySamples |> List.filter (canMakeSample me)
let cloudSamples =
gs.Samples
|> List.filter (fun s -> s.CarriedBy = Player.Cloud)
|> List.sortByDescending (fun s -> s.HealthPoints)
match mySamples.Length, samplesReady.Length, cloudSamples.Length, me.Location with
// GameState -> String
let getMove (gs : GameState) =
let me = gs.Robots |> List.find (fun r -> r.Player = Player.Me)
let mySamples = gs.Samples |> List.filter (fun s -> s.CarriedBy = Player.Me)
let samplesReady = mySamples |> List.filter (canMakeSample me)
let cloudSamples =
gs.Samples
|> List.filter (fun s -> s.CarriedBy = Player.Cloud)
|> List.sortByDescending (fun s -> s.HealthPoints)
// previous getMove code above
match mySamples.Length, samplesReady.Length, cloudSamples.Length, me.Location with
| _, sr, _, Module.Laboratory when sr > 0 ->
produce samplesReady.Head
| _, sr, _, _ when sr > 0 ->
goto Module.Laboratory
// more to come
// previous GetMove code above
match mySamples.Length, samplesReady.Length, cloudSamples.Length, me.Location with
// previous match expressions here
| ms, _, cs, Module.Diagnosis when ms = 0 && cs > 0 ->
collect cloudSamples.Head
| ms, _, cs, _ when ms = 0 && cs > 0 ->
goto Module.Diagnosis
// previous GetMove code above
match mySamples.Length, samplesReady.Length, cloudSamples.Length, me.Location with
// previous match expressions here
| _, _, _, Module.Molecules ->
gather (getRequiredMolecule me mySamples.Head)
| _, _, _, _ ->
goto Module.Molecules
let projectCount = readInt()
for i in 0 .. projectCount - 1 do
let _ = readInput()
()
(* game loop *)
while true do
let me = Robot.Create (tokenizeInput()) Player.Me
let enemy = Robot.Create (tokenizeInput()) Player.Enemy
// more to come