A few of the startup utility functions
1 files changed, 53 insertions(+), 11 deletions(-)

M src/panacea_lib/gamestate.ml
M src/panacea_lib/gamestate.ml +53 -11
@@ 14,7 14,7 @@ type role =
   (* - As an action, take any discarded Event card and store it on this card.
    * - When you play the stored Event card, remove it from the game.
    *)
-  | ContingencyPlannner
+  | ContingencyPlanner
 
   (* - Move another player's paw as if it were yours.
    * - As an action, move any pawn to a city with another pawn.

          
@@ 79,6 79,7 @@ type player_card =
 
 type player = {
   role : role;
+  name : string;
   hand : player_card list;
   location : infection_city;
 } [@@deriving show]

          
@@ 95,6 96,10 @@ type board_city = {
 } [@@deriving show]
 
 
+(* This is a bit of a nasty workaround to use a custom ADT as a key for a Base.Map
+ * It appears to work! But figuring this out I was like "yeah, this language is never
+ * taking off lol"
+ *)
 module CityCompare = struct
   module T = struct
     type t = infection_city [@@deriving sexp_of, compare]

          
@@ 102,7 107,6 @@ module CityCompare = struct
   include T
   include Comparable.Make(T)
 end
-
 type board =
   (infection_city, board_city, CityCompare.comparator_witness) Map.t
 

          
@@ 230,6 234,7 @@ let starting_player_deck =
     City Taipei; City Tehran; City Tokyo; City Washington
   ]
 
+
 (** Core Gamestate, unshuffled. *)
 let empty_gamestate = 
   {

          
@@ 254,39 259,76 @@ let empty_gamestate =
   }
 
 
+let rec shuffle = function
+  | [] -> []
+  | [single] -> [single]
+  | lst -> 
+    let (before, after) = List.partition_tf ~f:(fun _elt -> Random.bool ()) lst in 
+    List.rev_append (shuffle before) (shuffle after)
+
+
 (** Returns the Gamestate with the list of _n_ players in the same order we received them in, 
  * each with a random role. *)
-let draw_players gs = gs
+let draw_players player_names gs =
+  let roles = [ContingencyPlanner; Dispatcher; Medic; OperationsExpert; QuarantineSpecialist; Researcher; Scientist] in
+  let shuffled = shuffle roles in
+  let make_player_from (name, role) =
+    {
+      role=role;
+      name=name;
+      hand=[];
+      location=Atlanta
+  }
+  in
+  let drawed_roles = List.take shuffled (List.length player_names) in
+  let player_list = List.zip_exn player_names drawed_roles |> List.map ~f:make_player_from in
+  {gs with players=player_list}
+
 
 (** Returns the gamestate with the infection deck shuffled. *)
-let shuffle_infection_deck gs = gs
+let shuffle_infection_deck gs =
+  {gs with infection_deck=(shuffle gs.infection_deck)}
+
 
 (** Returns the gamestate with the player deck shuffled. *)
-let shuffle_player_deck gs = gs
+let shuffle_player_deck gs =
+  {gs with player_deck=(shuffle gs.player_deck)}
+
 
 (** Gives each player _n_ cards from the Player deck, per the starting rules. *)
 let hand_out_cards gs = gs
 
+
 (** Infects 9 cities with varying severity, per the starting rules. *)
 let infect_cities gs = gs
 
+
 (** Places the outbreak cards in the remaining Player deck, per the difficulty level. *)
-let place_outbreaks gs = gs
+let place_outbreaks _difficulty gs = gs
+
 
 (** Places the first research center in Atlanta. *)
-let place_research_station_in_atlanta gs = gs
+let place_research_station place gs =
+  let {board=b; research_stations_remaining=r;_} = gs in
+  let updated_board =
+    Map.change b place ~f:(fun x -> match x with
+      | None -> None
+      | Some b_city -> Some {b_city with has_research_station=true})
+  in
+  {gs with research_stations_remaining=r-1; board=updated_board}
+
 
 (** Gives us a Gamestate that's ready to play! *)
-let starting_game _player_names _difficulty = 
+let starting_game player_names difficulty = 
   let transformations = 
     [
-      draw_players;
+      draw_players player_names;
       shuffle_infection_deck;
       shuffle_player_deck;
       hand_out_cards;
       infect_cities;
-      place_outbreaks;
-      place_research_station_in_atlanta;
+      place_outbreaks difficulty;
+      place_research_station Atlanta;
     ]
   in
   List.fold_left