Skip to content

Instantly share code, notes, and snippets.

View jasondown's full-sized avatar

Jason Down jasondown

View GitHub Profile
// 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 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])
}
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 Module =
| StartPos
| Samples // <------------------- New Union Case
| Diagnosis
| Molecules
| Laboratory
static member Create moduleName =
match moduleName with
| "START_POS" -> Module.StartPos
| "SAMPLES" -> Module.Samples // <------------------- New Union Case
(* 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
let gameState =
{ Robots = [me; enemy]
Samples = samples }
(* game loop *)
while true do
// previous code
let samples =
readInt()
|> readNLines
|> Array.map (tokenize >> SampleData.Create)
|> Array.toList