Skip to content

Instantly share code, notes, and snippets.

View jasondown's full-sized avatar

Jason Down jasondown

View GitHub Profile
(* game loop *)
while true do
// previous code
// ignore input for available molecules for wood 2
let _ = readInput()
// more to come
(* game loop *)
while true do
let me = Robot.Create (tokenizeInput()) Player.Me
let enemy = Robot.Create (tokenizeInput()) Player.Enemy
// more to come
let projectCount = readInt()
for i in 0 .. projectCount - 1 do
let _ = readInput()
()
// 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
// 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
| _, sr, _, Module.Laboratory when sr > 0 ->
produce samplesReady.Head
| _, sr, _, _ when sr > 0 ->
goto Module.Laboratory
// more to come
// 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)
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
// 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
// Robot -> SampleData -> bool
let canMakeSample (robot : Robot) (sample : SampleData) =
sample.Molecules.Counts
|> Map.forall (fun mt count -> robot.Molecules.Counts.[mt] >= count)