M Makefile +2 -1
@@ 3,8 3,9 @@ OUTPUT=panacea
run: build
./_build/default/src/$(OUTPUT).exe
+.PHONY: test
test:
- dune runtest
+ dune runtest -f
build:
dune build src/$(OUTPUT).exe
M src/panacea.ml +1 -1
@@ 1,3 1,3 @@
(* open Core *)
-let () = Panacea_lib.execute ()
+let () = Panacea_lib.Main.execute ()
M src/panacea_lib/dune +1 -0
@@ 1,6 1,7 @@
(library
(name panacea_lib)
(inline_tests)
+ (modules (:standard gameplay gamestate))
(libraries core re2 logs alcotest)
(preprocess
(pps ppx_deriving.show ppx_let ppx_jane ppx_inline_test)))
M src/panacea_lib/gamestate.ml +8 -0
@@ 432,6 432,14 @@ let starting_game ~player_names ~difficu
transformations
+let player_at {curr_turn; players; _} =
+ let {location;_} = List.nth_exn players curr_turn in
+ location
+
+
+let remaining_actions {actions_remaining;_} = actions_remaining
+
+
let update_location city player = {player with location=city}
let lose_card card player =
M src/panacea_lib/gamestate.mli +18 -3
@@ 37,12 37,21 @@ type player_card =
| City of infection_city
-(** Printable representation of a Gamestate. *)
-val show_gamestate : t -> string
-
(** Gives us a Gamestate that's ready to play! *)
val starting_game : player_names:string list -> difficulty:difficulty -> t
+
+(* Access functions *)
+
+(** Where is the current player located? *)
+val player_at : t -> infection_city
+
+(** How many actions do we have remaining? *)
+val remaining_actions : t -> int
+
+
+(* Update functions *)
+
(** Places the current active player to the location. *)
val move_player_to : player:string -> city:infection_city -> t -> t
@@ 72,3 81,9 @@ val give_current_city_card : from_player
(** Get the name of the player who's turn it is. *)
val active_player : t -> string
+
+
+(* Util/debug *)
+
+(** Printable representation of a Gamestate. *)
+val show_gamestate : t -> string
A => src/panacea_lib/main.ml +6 -0
@@ 0,0 1,6 @@
+open Core
+
+let execute () =
+ Gamestate.starting_game ~player_names:["Pablo"; "Karen"; "Sapo"] ~difficulty:Gamestate.Standard
+ |> Gamestate.show_gamestate
+ |> print_endline
M src/panacea_lib/test/gameplay.ml +22 -5
@@ 1,10 1,27 @@
+(* Gameplay functions *)
+open Base
-let check msg x = Alcotest.(check bool) msg true x
+
+let original_state = Panacea_lib.Gamestate.starting_game
+ ~player_names:["Pablo";"Karen";"Sapo"]
+ ~difficulty:Panacea_lib.Gamestate.Standard
+
+let actions_on =
+ List.fold_left ~init:original_state ~f:Panacea_lib.Gameplay.apply_action
+
-let test_unit () =
- check "Give it a shot" true;
- check "Another" false
+let test_apply_action () =
+ let open Panacea_lib.Gameplay in
+ let open Panacea_lib.Gamestate in
+ Alcotest.(check bool)
+ "4 Drives"
+ true
+ (phys_equal
+ (player_at (actions_on [Drive Chicago; Drive Montreal; Drive Washington; Drive NewYork]))
+ NewYork);
+ Alcotest.(check bool) "Mario voice" true true
+
let tests = [
- "time", `Quick, test_unit;
+ "time", `Quick, test_apply_action;
]
M test/run_tests.ml +0 -2
@@ 1,5 1,3 @@
-(* Gameplay functions *)
-
let test_suites: unit Alcotest.test list = [
"Gameplay Tests", Test_panacea.Gameplay.tests;
]