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
let me = Robot.Create (tokenizeInput()) Player.Me
let enemy = Robot.Create (tokenizeInput()) Player.Enemy
// ignore input for available molecules for wood 2
let _ = readInput()
let samples =
readInt()
(* game loop *)
while true do
// previous code
// ignore input for available molecules for wood 2
let _ = readInput()
// more to come
// 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
// Remains unchanged
// Module ->string
let goto : Goto = fun m -> sprintf "GOTO %s" <| m.ToString()
// Replaced by next two (new) moves
// SampleData -> string
//let collect:Collect = fun s -> sprintf "CONNECT %i" <| s.Id
// New move
// Rank -> String
// <--- 2nd parameter was (sample : SampleData)
let canMakeSample (robot : Robot) (sample : DiagnosedSampleData) =
sample.Molecules.Counts
|> Map.forall (fun mt count -> robot.Molecules.Counts.[mt] >= count)
// <--- 2nd parameter was (sample : SampleData)
let getRequiredMolecule (robot : Robot) (sample : DiagnosedSampleData) =
let ms =
sample.Molecules.Counts
|> Map.filter (fun mt count -> robot.Molecules.Counts.[mt] < count)
type Goto = Module -> string // <--- Remains unchanged
// type Collect = SampleData -> string // <--- Replaced by next two
type CollectNewSample = Rank -> string
type CollectCloudSample = DiagnosedSampleData -> string
type Analyze = UndiagnosedSampleData -> string // <--- New type of move
type Gather = MoleculeType -> string // <--- Remains unchanged
type Produce = DiagnosedSampleData -> string // <--- Change SampleData to DiagnosedSampleData
type Rank = int // <------------------- new type alias
type DiagnosedSampleData =
{ Id : Id
CarriedBy : Player
Rank : Rank // <------------------- New field
HealthPoints : HealthPoints
Molecules : MoleculeStorage }
static member Create (token : Token) =
{ Id = (int <| token.[0])
type SampleData =
| Diagnosed of DiagnosedSampleData
| Undiagnosed of UndiagnosedSampleData
static member Create (token : Token) =
if token.[4] |> int = -1 then
SampleData.Undiagnosed <| UndiagnosedSampleData.Create token
else
SampleData.Diagnosed <| DiagnosedSampleData.Create token
type UndiagnosedSampleData =
{ Id : Id
CarriedBy : Player
Rank : Rank }
static member Create (token : Token) =
{ Id = (int <| token.[0])
CarriedBy = Player.Create (int <| token.[1])
Rank = (int <| token.[2])
}