Calculate dekiyaku correctly probably

This commit is contained in:
Bill Rossi 2025-02-25 20:35:50 -05:00
parent e0e4013b1f
commit 95264cb3df
3 changed files with 36 additions and 6 deletions

View File

@ -24,6 +24,7 @@ void handle_click_shoubu(Game *g) {
} }
void handle_click_sage(Game *g) { void handle_click_sage(Game *g) {
if (!g->first_sage) g->first_sage = &g->player;
g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE; g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE;
g->turn_number++; g->turn_number++;
g->state = GAME_STATE_CHOOSING_FROM_HAND; g->state = GAME_STATE_CHOOSING_FROM_HAND;
@ -142,10 +143,11 @@ void init_dialogs(Game *g) {
end_of_game_dialog->options[1].handle = &handle_click_quit; end_of_game_dialog->options[1].handle = &handle_click_quit;
Dialog *dekiyaku_end_of_round_dialog = &dialogs[4]; Dialog *dekiyaku_end_of_round_dialog = &dialogs[4];
dekiyaku_end_of_round_dialog->text_count = 3; dekiyaku_end_of_round_dialog->text_count = 4;
dekiyaku_end_of_round_dialog->text[0] = malloc(200); dekiyaku_end_of_round_dialog->text[0] = malloc(200);
dekiyaku_end_of_round_dialog->text[1] = malloc(200); dekiyaku_end_of_round_dialog->text[1] = malloc(200);
dekiyaku_end_of_round_dialog->text[2] = malloc(200); dekiyaku_end_of_round_dialog->text[2] = malloc(200);
dekiyaku_end_of_round_dialog->text[3] = malloc(200);
strcpy(dekiyaku_end_of_round_dialog->text[0], "Player score"); strcpy(dekiyaku_end_of_round_dialog->text[0], "Player score");
strcpy(dekiyaku_end_of_round_dialog->text[1], "Right score"); strcpy(dekiyaku_end_of_round_dialog->text[1], "Right score");
strcpy(dekiyaku_end_of_round_dialog->text[2], "Left score"); strcpy(dekiyaku_end_of_round_dialog->text[2], "Left score");

37
game.c
View File

@ -339,6 +339,8 @@ void run_frame_initializing(Game *g) {
g->current_play_from_hand = NULL; g->current_play_from_hand = NULL;
g->current_play_target = NULL; g->current_play_target = NULL;
g->first_sage = NULL;
g->deck.count = 0; g->deck.count = 0;
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
Card *c = &g->cards[i]; Card *c = &g->cards[i];
@ -347,8 +349,8 @@ void run_frame_initializing(Game *g) {
add_to_hand(&g->deck, c, g->deal_speed); add_to_hand(&g->deck, c, g->deal_speed);
} }
shuffle_hand(&g->deck); // shuffle_hand(&g->deck);
// order_deck(&g->deck); order_deck(&g->deck);
kan_points_string(g, g->player.points, g->player.points_string); kan_points_string(g, g->player.points, g->player.points_string);
kan_points_string(g, g->right.points, g->right.points_string); kan_points_string(g, g->right.points, g->right.points_string);
@ -416,7 +418,14 @@ void run_frame_calculating_teyaku(Game *g) {
void run_frame_start_of_turn(Game *g) { void run_frame_start_of_turn(Game *g) {
g->turn_number++; g->turn_number++;
if(g->player.hand.count == 0 && g->right.hand.count == 0 && g->left.hand.count == 0) { if(g->player.hand.count == 0 && g->right.hand.count == 0 && g->left.hand.count == 0) {
g->state = GAME_STATE_CALCULATING_SCORES; if (
g->player.dekiyaku_action == DEKIYAKU_ACTION_NONE &&
g->left.dekiyaku_action == DEKIYAKU_ACTION_NONE &&
g->right.dekiyaku_action == DEKIYAKU_ACTION_NONE) {
g->state = GAME_STATE_CALCULATING_SCORES;
} else {
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
}
} else { } else {
g->state = GAME_STATE_CHECKING_FOR_CANCEL; g->state = GAME_STATE_CHECKING_FOR_CANCEL;
} }
@ -575,6 +584,7 @@ void run_frame_checking_for_new_dekiyaku(Game *g) {
shoubu_dialog(g); shoubu_dialog(g);
} else { } else {
// TODO: better AI // TODO: better AI
// TODO: if it can sage, set "first sage" if possible
cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU; cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU;
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
} }
@ -671,7 +681,7 @@ void run_frame_calculating_scores(Game *g) {
} }
} }
void calculate_dekiyaku_score(Game *g, Player *p) { int calculate_dekiyaku_score(Game *g, Player *p) {
Dekiyaku d; Dekiyaku d;
calculate_dekiyaku(&p->scored, &d); calculate_dekiyaku(&p->scored, &d);
if (p->dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { if (p->dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
@ -681,6 +691,7 @@ void calculate_dekiyaku_score(Game *g, Player *p) {
transfer_kan(g, &p->points, &g->player.points, dekiyaku_score(&d)); transfer_kan(g, &p->points, &g->player.points, dekiyaku_score(&d));
transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d)); transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d));
transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d)); transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d));
return dekiyaku_score(&d) * g->kan_value;
} else { } else {
sprintf(g->dialog->text[0], "%s cancels with dekiyaku!", p->name); sprintf(g->dialog->text[0], "%s cancels with dekiyaku!", p->name);
dekiyaku_to_string(&d, g->dialog->text[1]); dekiyaku_to_string(&d, g->dialog->text[1]);
@ -695,9 +706,24 @@ void calculate_dekiyaku_score(Game *g, Player *p) {
transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d) / 2); transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d) / 2);
transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d) / 2); transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d) / 2);
} }
return (dekiyaku_score(&d) * g->kan_value) / 2;
} }
} }
void calculate_exhausted_dekiyaku_score(Game *g) {
g->player.dekiyaku_action = DEKIYAKU_ACTION_CANCEL;
int p_score = calculate_dekiyaku_score(g, &g->player);
g->right.dekiyaku_action = DEKIYAKU_ACTION_CANCEL;
int r_score = calculate_dekiyaku_score(g, &g->right);
g->left.dekiyaku_action = DEKIYAKU_ACTION_CANCEL;
int l_score = calculate_dekiyaku_score(g, &g->left);
printf("%d %d %d\n", p_score, r_score, l_score);
sprintf(g->dialog->text[0], "Hands are exhausted (half dekiyaku scores)");
sprintf(g->dialog->text[1], "Player scores %d points", p_score);
sprintf(g->dialog->text[2], "Right scores %d points", r_score);
sprintf(g->dialog->text[3], "Left scores %d points", l_score);
}
void run_frame_calculating_dekiyaku_score(Game *g) { void run_frame_calculating_dekiyaku_score(Game *g) {
dekiyaku_end_of_round_dialog(g); dekiyaku_end_of_round_dialog(g);
if (g->player.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->player.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { if (g->player.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->player.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
@ -707,7 +733,8 @@ void run_frame_calculating_dekiyaku_score(Game *g) {
} else if (g->left.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->left.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { } else if (g->left.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->left.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
calculate_dekiyaku_score(g, &g->left); calculate_dekiyaku_score(g, &g->left);
} else { } else {
// TODO: Hands are exhausted g->dealer = g->first_sage;
calculate_exhausted_dekiyaku_score(g);
} }
pay_teyaku(g); pay_teyaku(g);
} }

1
game.h
View File

@ -47,6 +47,7 @@ struct Game {
FieldMultiplier *field_multiplier; FieldMultiplier *field_multiplier;
Card *current_play_from_hand, *current_play_target; Card *current_play_from_hand, *current_play_target;
Player player, right, left; Player player, right, left;
Player *first_sage;
int temp_points; int temp_points;
int turn_number; int turn_number;
Dialog *dialog; Dialog *dialog;