From 15ff00e056a98ab4210dde3d4461a88849d6c1d4 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 23 May 2022 15:23:48 -0700 Subject: move a bunch of general match logic from web to lib --- match.h | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'match.h') diff --git a/match.h b/match.h index ce52717..a699f77 100644 --- a/match.h +++ b/match.h @@ -3,6 +3,18 @@ #include "board.h" +#include + +enum player_type { + PT_USER, + PT_COMP +}; + +struct player { + char *name; + enum player_type type; +}; + struct visit { int points; int rem; @@ -12,17 +24,36 @@ struct visit { }; struct leg { - char *name; - int start; - int rem; - int n_visits, size_visits; + int start, rem; + int n_visits, size_visits, undone_visits; struct visit *visits; }; -struct leg *leg_init(int points, char *name); +struct match { + struct player *players; + int n_players, size_players; + int active_player; + + struct leg **legs; +}; + +struct leg *leg_init(int points); void leg_free(struct leg *l); void leg_grow_visits(struct leg *l); +void leg_undo_visit(struct leg *l); +void leg_redo_visit(struct leg *l); + +struct match *match_init(); +void match_free(struct match *m); +void match_add_player(struct match *m, enum player_type type, char *name, + int start_pts); + +int match_next_player(struct match *m); +int match_prev_player(struct match *m); +int match_last_player_to_throw(struct match *m); +int match_winning_player(struct match *m); + bool is_points_valid(int pts, int rem); #endif -- cgit v1.2.3-70-g09d2