summaryrefslogtreecommitdiff
path: root/match.h
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-23 15:23:48 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-23 15:25:07 -0700
commit15ff00e056a98ab4210dde3d4461a88849d6c1d4 (patch)
tree280b8d248baee5d2ae0dcc2117e3f2b309d128ec /match.h
parentc93897ed2013f20d6ece33815971d206fd0d056e (diff)
downloaddartboat-15ff00e056a98ab4210dde3d4461a88849d6c1d4.tar.gz
dartboat-15ff00e056a98ab4210dde3d4461a88849d6c1d4.tar.xz
move a bunch of general match logic from web to lib
Diffstat (limited to 'match.h')
-rw-r--r--match.h41
1 files changed, 36 insertions, 5 deletions
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 <stdbool.h>
+
+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