M src/panacea_lib/gameplay.ml +11 -2
@@ 1,3 1,4 @@
+open Base
open Gamestate
(**
@@ 26,7 27,7 @@ type action =
| TreatDisease of infection_city * infection_color (* Remove cubes *)
| TakeShareKnowledge (* Take card from another player who has the city card you're in. *)
| GiveShareKnowledge of string (* Give city card you're in to specified player. *)
- | DiscoverCure of infection_color * infection_card list
+ | DiscoverCure of infection_color * player_card list
type move = (action * action * action * action)
@@ 71,7 72,15 @@ let apply_action gs action =
gs
|> Gamestate.take_current_city_card_from_another_player
|> Gamestate.decrement_actions_remaining
- | _ -> gs
+ | GiveShareKnowledge other_player ->
+ gs
+ |> Gamestate.give_current_city_card ~from_player:active_player ~to_player:other_player
+ |> Gamestate.decrement_actions_remaining
+ | DiscoverCure (color, cards) ->
+ cards
+ |> List.fold_left ~init:gs ~f:(fun accum card -> Gamestate.discard_player_card ~player:active_player ~card:card accum)
+ |> Gamestate.set_disease_cured ~color
+ |> Gamestate.decrement_actions_remaining
let generate_moves _gs = [5]
M src/panacea_lib/gamestate.ml +19 -0
@@ 499,6 499,25 @@ let take_current_city_card_from_another_
{gs with players=final_players}
+let give_current_city_card ~from_player ~to_player gs =
+ let my_turn = List.nth_exn gs.players gs.curr_turn in
+ let the_card = City my_turn.location in
+ let lose_one = List.map ~f:(update_player_named from_player (lose_card the_card)) gs.players in
+ let updated_players = List.map ~f:(update_player_named to_player (gain_card the_card)) lose_one in
+ {gs with players=updated_players}
+
+
+let set_disease_cured ~color gs =
+ match color with
+ | Black ->
+ {gs with is_black_cured=true}
+ | Blue ->
+ {gs with is_blue_cured=true}
+ | Red ->
+ {gs with is_red_cured=true}
+ | Yellow ->
+ {gs with is_yellow_cured=true}
+
let decrement_actions_remaining gs =
{gs with actions_remaining=gs.actions_remaining - 1}
M src/panacea_lib/gamestate.mli +7 -1
@@ 46,9 46,12 @@ val starting_game : player_names:string
(** Places the current active player to the location. *)
val move_player_to : player:string -> city:infection_city -> t -> t
-(** Places the current active player to the location. *)
+(** Removes the card for this player. *)
val discard_player_card : player:string -> card:player_card -> t -> t
+(** Removes the card for the active player. *)
+val set_disease_cured : color:infection_color -> t -> t
+
(** Places the current active player to the location. *)
val discard_player_card_at_location : player:string -> t -> t
@@ 64,5 67,8 @@ val place_research_station : city:infect
(** Take a card for the current player's city from another player in that city who has it. *)
val take_current_city_card_from_another_player : t -> t
+(** Take a card for the current player's city from another player in that city who has it. *)
+val give_current_city_card : from_player:string -> to_player:string -> t -> t
+
(** Get the name of the player who's turn it is. *)
val active_player : t -> string