# HG changeset patch # User Pablo Meier # Date 1584227150 14400 # Sat Mar 14 19:05:50 2020 -0400 # Node ID 69c2f69c0c34bc7e5afe27e644dc926c4f6470db # Parent 8b688f9ba7830ed45275dd06026ca836b881401f Added @@deriving show, some more scaffolding. diff --git a/panacea.opam b/panacea.opam --- a/panacea.opam +++ b/panacea.opam @@ -13,4 +13,5 @@ "core" {= "v0.13.0"} "logs" {= "0.6.3"} "re2" {= "v0.13.0"} + "ppx_deriving" {= "4.4.1"} ] diff --git a/src/dune b/src/dune --- a/src/dune +++ b/src/dune @@ -2,4 +2,4 @@ (name panacea) (libraries panacea_lib) (preprocess - (pps ppx_let ppx_jane))) + (pps ppx_deriving.show ppx_let ppx_jane))) diff --git a/src/panacea_lib/dune b/src/panacea_lib/dune --- a/src/panacea_lib/dune +++ b/src/panacea_lib/dune @@ -3,4 +3,4 @@ (inline_tests) (libraries core re2 logs) (preprocess - (pps ppx_let ppx_jane ppx_inline_test))) + (pps ppx_deriving.show ppx_let ppx_jane ppx_inline_test))) diff --git a/src/panacea_lib/gamestate.ml b/src/panacea_lib/gamestate.ml --- a/src/panacea_lib/gamestate.ml +++ b/src/panacea_lib/gamestate.ml @@ -1,4 +1,5 @@ open Base + (** * The Gamestate contains everything you need to properly model a game in-progress. *) @@ -7,6 +8,7 @@ | Introductory (* 4 Epidemic cards *) | Standard (* 5 Epidemic cards *) | Heroic (* 6 Epidemic cards *) + [@@deriving show] type role = (* - As an action, take any discarded Event card and store it on this card. @@ -45,12 +47,14 @@ (* - You only need 4 cards of the same color to do the Discover a Cure action. *) | Scientist + [@@deriving show] type infection_color = | Black | Blue | Red | Yellow + [@@deriving show] type infection_city = | Algiers | Atlanta | Baghdad | Bangkok | Beijing | Bogota | BuenosAires | Cairo @@ -59,23 +63,25 @@ | LosAngeles | Madrid | Manila | MexicoCity | Miami | Milan | Montreal | Moscow | Mumbai | NewYork | Osaka | Paris | Riyadh | SanFrancisco | Santiago | SaoPaolo | Seoul | Shanghai | StPetersburg | Sydney | Taipei | Tehran | Tokyo | Washington - [@@deriving sexp, compare] + [@@deriving sexp, compare, show] type player_card_event = { name: string; description: string; -} +} [@@deriving show] + type player_card = | Event of player_card_event | Epidemic | City of infection_city + [@@deriving show] type player = { role : role; hand : player_card list; location : infection_city; -} +} [@@deriving show] type board_city = { name : string; @@ -86,7 +92,8 @@ num_yellow : int; has_research_station : bool; neighbors : infection_city list; -} +} [@@deriving show] + module CityCompare = struct module T = struct @@ -96,9 +103,12 @@ include Comparable.Make(T) end -type board = (infection_city, board_city, CityCompare.comparator_witness) Map.t +type board = + (infection_city, board_city, CityCompare.comparator_witness) Map.t -type infection_card = infection_city +let pp_board _ = "Board" + +type infection_card = infection_city [@@deriving show] type gamestate = { players : player list; @@ -121,6 +131,8 @@ is_yellow_cured : bool; } +let pp_gamestate _ = "Gamestate" + let empty_board = let initial = Map.empty (module CityCompare) in @@ -218,16 +230,11 @@ City Taipei; City Tehran; City Tokyo; City Washington ] -let empty_gamestate () = - let players = [ - {role=Dispatcher; hand=[]; location=Atlanta}; - {role=ContingencyPlannner; hand=[]; location=Atlanta}; - {role=Medic; hand=[]; location=Atlanta}; - ] in - let board = empty_board in +(** Core Gamestate, unshuffled. *) +let empty_gamestate = { - players=players; - board=board; + players=[]; + board=empty_board; curr_turn=0; actions_remaining=4; research_stations_remaining=6; @@ -245,3 +252,45 @@ is_black_cured=false; is_yellow_cured=false; } + + +(** 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 + +(** Returns the gamestate with the infection deck shuffled. *) +let shuffle_infection_deck gs = gs + +(** Returns the gamestate with the player deck shuffled. *) +let shuffle_player_deck gs = gs + +(** 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 + +(** Places the first research center in Atlanta. *) +let place_research_station_in_atlanta gs = gs + +(** Gives us a Gamestate that's ready to play! *) +let starting_game _player_names _difficulty = + let transformations = + [ + draw_players; + shuffle_infection_deck; + shuffle_player_deck; + hand_out_cards; + infect_cities; + place_outbreaks; + place_research_station_in_atlanta; + ] + in + List.fold_left + ~init:empty_gamestate + ~f:(fun accum x -> x accum) + transformations +