aboutsummaryrefslogtreecommitdiff
path: root/yhtz.c
diff options
context:
space:
mode:
Diffstat (limited to 'yhtz.c')
-rw-r--r--yhtz.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/yhtz.c b/yhtz.c
index d8d3b2c..64b29a2 100644
--- a/yhtz.c
+++ b/yhtz.c
@@ -20,27 +20,51 @@ typedef struct {
uint16_t seed;
} yhtz_state;
+enum Category {
+ ACE = 0,
+ TWO = 1,
+ THREE = 2,
+ FOUR = 3,
+ FIVE = 4,
+ SIX = 5,
+ THREE_OF_A_KIND = 10,
+ FOUR_OF_A_KIND = 11,
+ FULL_HOUSE = 12,
+ SMALL_STRAIGHT = 13,
+ LARGE_STRAIGHT = 14,
+ YAHTZEE = 15,
+ CHANCE = 16
+};
+
+static enum Category CATEGORIES[] = {
+ ACE,
+ TWO,
+ THREE,
+ FOUR,
+ FIVE,
+ SIX,
+ THREE_OF_A_KIND,
+ FOUR_OF_A_KIND,
+ FULL_HOUSE,
+ SMALL_STRAIGHT,
+ LARGE_STRAIGHT,
+ YAHTZEE,
+ CHANCE
+};
+
+static int NUMBER_OF_CATEGORIES = 13;
+
/* Note: all macros take in a yhtz_state* as input 's' */
/* ROLLS */
#define GET_ROLL(s) ((uint8_t)((s->topflag_w_roll & 0xC0) >> 6)) /* top 2 bits */
#define SET_ROLL(s, x) (s->topflag_w_roll = (s->topflag_w_roll & 0x3F | ((uint8_t)x << 6)))
-/* TOP NUMBERS */
-#define GET_NUM(s, x) ((uint8_t)((s & (1 << x)) >> x))
-#define GET_ACE(s) (GET_NUM(s, 0))
-#define GET_TWO(s) (GET_NUM(s, 1))
-#define GET_THREE(s) (GET_NUM(s, 2))
-#define GET_FOUR(s) (GET_NUM(s, 3))
-#define GET_FIVE(s) (GET_NUM(s, 4))
-#define GET_SIX(s) (GET_NUM(s, 5))
-
-#define SET_NUM(s, x) (s | (1 << x))
-#define SET_ACE(s) (SET_NUM(s, 0))
-#define SET_TWO(s) (SET_NUM(s, 1))
-#define SET_THREE(s) (SET_NUM(s, 2))
-#define SET_FOUR(s) (SET_NUM(s, 3))
-#define SET_FIVE(s) (SET_NUM(s, 4))
-#define SET_SIX(s) (SET_NUM(s, 5))
+/* FLAGS -- x is an offset based on Category */
+#define GET_TOPFLAG(s, x) ((uint8_t)((s->topflag_w_roll & (1 << x)) >> x))
+#define SET_TOPFLAG(s, x) (s->topflag_w_roll = (s->topflag_w_roll | (1 << x)))
+#define GET_BOTFLAG(s, x) ((uint8_t)((s->botflag & (1 << x)) >> x))
+#define SET_BOTFLAG(s, x) (s->botflag = (s->botflag | (1 << x)))
+#define GET_FLAG(s, x) (x < 10 ? GET_TOPFLAG(s, x) : GET_BOTFLAG(s, x - 10))
/* DICE -- x is die number (0-4), y is value (1-6) */
#define GET_DIE(s, x) ((uint8_t)((s->dice & (0x07 << (3 * x))) >> (3 * x)))
@@ -121,6 +145,12 @@ void do_roll(yhtz_state* state) {
SET_ROLL(state, ++roll);
}
+void ask_for_category(yhtz_state* state) {
+ char buf[2];
+ printf("what category should this be scored in? ");
+ fgets(buf, sizeof(buf), stdin);
+}
+
void do_turn(yhtz_state* state) {
for (int i = 0; i < 3; i++) {
do_roll(state);
@@ -128,6 +158,14 @@ void do_turn(yhtz_state* state) {
if (i < 2)
ask_for_rerolls(state);
}
+ ask_for_category(state);
+}
+
+int turn_count(yhtz_state* state) {
+ int ret = 1;
+ for (int i = 0; i < NUMBER_OF_CATEGORIES; i++)
+ ret += GET_FLAG(state, CATEGORIES[i]);
+ return ret;
}
void init_yhtz_state(yhtz_state* state) {
@@ -153,6 +191,11 @@ void main() {
*
*/
- do_turn(&y);
+ int tc;
+ while (true) {
+ tc = turn_count(&y);
+ printf("~*~ turn %d ~*~\n", tc);
+ do_turn(&y);
+ }
}