Compare commits

..

No commits in common. "95264cb3dfa27eb9d84056c1c362f0e04d45be7d" and "b5721105b14b1384d2a0f2af0462823db483f4c5" have entirely different histories.

5 changed files with 20 additions and 87 deletions

8
card.c
View File

@ -14,10 +14,6 @@ void draw_card(Card *c, Texture2D *cards_texture, int index) {
Color color = index == 1 ? BLACK : BRICKRED;
if (c->selected) {
DrawRectangleRec((Rectangle) { c->position.x - 6, c->position.y - 6, card_size.x + 12, card_size.y + 12 }, BLUE);
}
if (c->visible) {
DrawTexturePro(
*cards_texture,
@ -31,6 +27,9 @@ void draw_card(Card *c, Texture2D *cards_texture, int index) {
DrawRectangleRec((Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y }, color);
}
if (c->selected) {
DrawCircle(c->position.x + 10, c->position.y + 10, 10, BLUE);
}
}
bool point_within_card(Card *c, Vector2 point) {
@ -77,7 +76,6 @@ void order_deck(Hand *h) {
}
void remove_from_hand(Hand *h, Card *c) {
c->selected = false;
bool card_found = false;
for (int i = 0; i < h->count - 1; i++) {
if (h->cards[i] == c) card_found = true;

View File

@ -24,7 +24,6 @@ void handle_click_shoubu(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->turn_number++;
g->state = GAME_STATE_CHOOSING_FROM_HAND;
@ -143,11 +142,10 @@ void init_dialogs(Game *g) {
end_of_game_dialog->options[1].handle = &handle_click_quit;
Dialog *dekiyaku_end_of_round_dialog = &dialogs[4];
dekiyaku_end_of_round_dialog->text_count = 4;
dekiyaku_end_of_round_dialog->text_count = 3;
dekiyaku_end_of_round_dialog->text[0] = 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[3] = malloc(200);
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[2], "Left score");

85
game.c
View File

@ -339,18 +339,15 @@ void run_frame_initializing(Game *g) {
g->current_play_from_hand = NULL;
g->current_play_target = NULL;
g->first_sage = NULL;
g->deck.count = 0;
for (int i = 0; i < 48; i++) {
Card *c = &g->cards[i];
c->visible = false;
c->selected = false;
add_to_hand(&g->deck, c, g->deal_speed);
}
// shuffle_hand(&g->deck);
order_deck(&g->deck);
shuffle_hand(&g->deck);
// order_deck(&g->deck);
kan_points_string(g, g->player.points, g->player.points_string);
kan_points_string(g, g->right.points, g->right.points_string);
@ -418,14 +415,7 @@ void run_frame_calculating_teyaku(Game *g) {
void run_frame_start_of_turn(Game *g) {
g->turn_number++;
if(g->player.hand.count == 0 && g->right.hand.count == 0 && g->left.hand.count == 0) {
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;
}
g->state = GAME_STATE_CALCULATING_SCORES;
} else {
g->state = GAME_STATE_CHECKING_FOR_CANCEL;
}
@ -468,24 +458,19 @@ void run_frame_choosing_target(Game *g) {
return;
}
Card *selected_card = NULL;
bool no_cards_selected = true;
for (int i = 0; i < g->player.hand.count; i++) {
if (g->player.hand.cards[i]->selected) {
selected_card = g->player.hand.cards[i];
no_cards_selected = false;
break;
}
}
if (!selected_card) {
if (no_cards_selected) {
g->state = GAME_STATE_CHOOSING_FROM_HAND;
return;
}
for (int i = 0; i < g->field.count; i++) {
g->field.cards[i]->selected = g->field.cards[i]->month == selected_card->month;
}
if (g->current_play_from_hand) {
if (g->current_play_target) {
g->current_play_from_hand->selected = false;
@ -507,9 +492,6 @@ void run_frame_choosing_target(Game *g) {
add_to_hand(&g->field, g->current_play_from_hand, g->deal_speed);
g->current_play_from_hand = NULL;
}
for (int i = 0; i < g->player.scored.count; i++) {
g->player.scored.cards[i]->selected = false;
}
g->state = GAME_STATE_SHOWING_CARD_FROM_DECK;
}
}
@ -554,14 +536,7 @@ void run_frame_choosing_target_from_deck(Game *g) {
valid_targets(top_card, &g->field, &targets[0], &target_count);
if (is_player_turn(g)) {
for (int i = 0; i < target_count; i++) {
targets[i]->selected = true;
}
if (g->current_play_target) {
for (int i = 0; i < target_count; i++) {
targets[i]->selected = false;
}
capture_card_from_field(g, top_card, g->current_play_target, &g->deck, to_hand);
g->state = GAME_STATE_CHECKING_FOR_NEW_DEKIYAKU;
g->current_play_from_hand = NULL;
@ -584,7 +559,6 @@ void run_frame_checking_for_new_dekiyaku(Game *g) {
shoubu_dialog(g);
} else {
// TODO: better AI
// TODO: if it can sage, set "first sage" if possible
cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU;
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
}
@ -681,7 +655,7 @@ void run_frame_calculating_scores(Game *g) {
}
}
int calculate_dekiyaku_score(Game *g, Player *p) {
void calculate_dekiyaku_score(Game *g, Player *p) {
Dekiyaku d;
calculate_dekiyaku(&p->scored, &d);
if (p->dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
@ -691,7 +665,6 @@ int calculate_dekiyaku_score(Game *g, Player *p) {
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->left.points, dekiyaku_score(&d));
return dekiyaku_score(&d) * g->kan_value;
} else {
sprintf(g->dialog->text[0], "%s cancels with dekiyaku!", p->name);
dekiyaku_to_string(&d, g->dialog->text[1]);
@ -706,24 +679,9 @@ int 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->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) {
dekiyaku_end_of_round_dialog(g);
if (g->player.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->player.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
@ -733,8 +691,7 @@ void run_frame_calculating_dekiyaku_score(Game *g) {
} else if (g->left.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->left.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) {
calculate_dekiyaku_score(g, &g->left);
} else {
g->dealer = g->first_sage;
calculate_exhausted_dekiyaku_score(g);
// TODO: Hands are exhausted
}
pay_teyaku(g);
}
@ -944,12 +901,12 @@ void draw_frame(Game *g) {
DrawText(g->field_multiplier->explanation, 60, 445, 20, BLACK);
}
DrawText(g->player.points_string, 1000, 650, 20, BLACK);
DrawText(g->player.teyaku_string, 1000, 680, 20, BLACK);
DrawText(g->right.points_string, 1000, 260, 20, BLACK);
DrawText(g->right.teyaku_string, 1100, 260, 20, BLACK);
DrawText(g->left.points_string, 200, 260, 20, BLACK);
DrawText(g->left.teyaku_string, 300, 260, 20, BLACK);
DrawText(g->player.points_string, 40, 650, 20, BLACK);
DrawText(g->player.teyaku_string, 40, 680, 20, BLACK);
DrawText(g->right.points_string, 40, 725, 20, BLACK);
DrawText(g->right.teyaku_string, 40, 755, 20, BLACK);
DrawText(g->left.points_string, 40, 800, 20, BLACK);
DrawText(g->left.teyaku_string, 40, 830, 20, BLACK);
char round_text[40];
if (g->current_round < g->number_of_rounds)
@ -966,21 +923,7 @@ void draw_frame(Game *g) {
break;
case GAME_STATE_CHOOSING_TARGET:
DrawText("Choose a target on the field", 60, 485, 20, BLACK);
Card *selected_card = NULL;
for (int i = 0; i < g->player.hand.count; i++) {
if (g->player.hand.cards[i]->selected) {
selected_card = g->player.hand.cards[i];
break;
}
}
if (!selected_card) break;
bool draw_next_rec = true;
for (int i = 0; i < g->field.count; i++) {
if (g->field.cards[i]->month == selected_card->month) draw_next_rec = false;
}
if (draw_next_rec) DrawRectangleRec(next_card_position(&g->field), BLUE);
DrawRectangleRec(next_card_position(&g->field), BLUE);
break;
default:
break;

1
game.h
View File

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

View File

@ -6,11 +6,9 @@
SetTeyaku calculate_set_teyaku(const Hand h) {
int month_counts[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int month_stands[12] = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1 };
int pawlonia_chaff = 0;
for (int i = 0; i < h.count; i++) {
Card c = *h.cards[i];
month_counts[c.month]++;
if (c.index >= 45) pawlonia_chaff++;
}
int triplets = 0, standing_triplets = 0, pairs = 0, four_of_a_kind = 0;
@ -18,11 +16,8 @@ SetTeyaku calculate_set_teyaku(const Hand h) {
if (month_counts[i] == 4) {
four_of_a_kind++;
} else if (month_counts[i] == 3) {
if (month_stands[i] && (i != 12 || pawlonia_chaff == 3)) {
standing_triplets++;
} else {
triplets++;
}
if (month_stands[i]) standing_triplets++; // TODO Pawlonia is weird
else triplets++;
} else if (month_counts[i] == 2) {
pairs++;
}