Choose the dealer correctly
This commit is contained in:
parent
5ad8fa1534
commit
21adb38b00
61
game.c
61
game.c
@ -100,6 +100,18 @@ void initialize_game(Game *g) {
|
||||
|
||||
strcpy(teyaku_calculation, "");
|
||||
|
||||
int dealer = rand() % 3;
|
||||
switch (dealer) {
|
||||
case PLAYER:
|
||||
g->dealer = &g->player;
|
||||
break;
|
||||
case RIGHT:
|
||||
g->dealer = &g->right;
|
||||
break;
|
||||
case LEFT:
|
||||
g->dealer = &g->left;
|
||||
break;
|
||||
}
|
||||
g->state = GAME_STATE_INITIALIZING;
|
||||
}
|
||||
|
||||
@ -236,8 +248,7 @@ void run_frame_ai_playing(Game *g) {
|
||||
}
|
||||
|
||||
void run_frame_initializing(Game *g) {
|
||||
// TODO: choose the dealer in a more effective manner
|
||||
g->turn_number = -1;
|
||||
g->turn_number = g->dealer->seat;
|
||||
|
||||
g->player.hand.count = 0;
|
||||
g->right.hand.count = 0;
|
||||
@ -286,20 +297,14 @@ bool misdeal(Game *g) {
|
||||
}
|
||||
|
||||
void run_frame_dealing(Game *g) {
|
||||
if (g->player.hand.count < 4) {
|
||||
deal(&g->deck, &g->player.hand, 4, true);
|
||||
} else if (g->left.hand.count < 4) {
|
||||
deal(&g->deck, &g->left.hand, 4, false);
|
||||
} else if (g->right.hand.count < 4) {
|
||||
deal(&g->deck, &g->right.hand, 4, false);
|
||||
if (current_player(g)->hand.count < 4) {
|
||||
deal(&g->deck, ¤t_player(g)->hand, 4, true);
|
||||
g->turn_number++;
|
||||
} else if (g->field.count < 3) {
|
||||
deal(&g->deck, &g->field, 3, true);
|
||||
} else if (g->player.hand.count < 7) {
|
||||
deal(&g->deck, &g->player.hand, 3, true);
|
||||
} else if (g->left.hand.count < 7) {
|
||||
deal(&g->deck, &g->left.hand, 3, false);
|
||||
} else if (g->right.hand.count < 7) {
|
||||
deal(&g->deck, &g->right.hand, 3, false);
|
||||
} else if (current_player(g)->hand.count < 7) {
|
||||
deal(&g->deck, ¤t_player(g)->hand, 3, true);
|
||||
g->turn_number++;
|
||||
} else if (g->field.count < 6) {
|
||||
deal(&g->deck, &g->field, 3, true);
|
||||
} else {
|
||||
@ -307,6 +312,7 @@ void run_frame_dealing(Game *g) {
|
||||
printf("misdeal\n");
|
||||
g->state = GAME_STATE_INITIALIZING;
|
||||
} else {
|
||||
g->turn_number++;
|
||||
g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER;
|
||||
}
|
||||
}
|
||||
@ -463,12 +469,19 @@ void run_frame_selecting_dekiyaku_action(Game *g) {
|
||||
}
|
||||
|
||||
void run_frame_calculating_scores(Game *g) {
|
||||
printf("Hand scores: %d %d %d\n", hand_points(&g->player.scored), hand_points(&g->right.scored), hand_points(&g->left.scored));
|
||||
int hp[3];
|
||||
hp[0] = hand_points(&g->player.scored);
|
||||
hp[1] = hand_points(&g->right.scored);
|
||||
hp[2] = hand_points(&g->left.scored);
|
||||
printf("Hand scores: %d %d %d\n", hp[0], hp[1], hp[2]);
|
||||
|
||||
SpecialCase special_case = calculate_special_case(g);
|
||||
switch(special_case.type) {
|
||||
case SPECIAL_CASE_ALL_EIGHTS:
|
||||
printf("All eights! Dealer gets %d kan\n", special_case.score);
|
||||
transfer_kan(g, &g->dealer->points, &g->player.points, special_case.score);
|
||||
transfer_kan(g, &g->dealer->points, &g->right.points, special_case.score);
|
||||
transfer_kan(g, &g->dealer->points, &g->left.points, special_case.score);
|
||||
break;
|
||||
case SPECIAL_CASE_DOUBLE_EIGHTS:
|
||||
case SPECIAL_CASE_SIXTEEN_CHAFF:
|
||||
@ -477,21 +490,33 @@ void run_frame_calculating_scores(Game *g) {
|
||||
case SPECIAL_CASE_TARGET_PLAYER:
|
||||
transfer_kan(g, &g->player.points, &g->right.points, special_case.score);
|
||||
transfer_kan(g, &g->player.points, &g->left.points, special_case.score);
|
||||
g->dealer = &g->player;
|
||||
break;
|
||||
case SPECIAL_CASE_TARGET_RIGHT:
|
||||
transfer_kan(g, &g->right.points, &g->player.points, special_case.score);
|
||||
transfer_kan(g, &g->right.points, &g->left.points, special_case.score);
|
||||
g->dealer = &g->right;
|
||||
break;
|
||||
case SPECIAL_CASE_TARGET_LEFT:
|
||||
transfer_kan(g, &g->left.points, &g->right.points, special_case.score);
|
||||
transfer_kan(g, &g->left.points, &g->player.points, special_case.score);
|
||||
g->dealer = &g->left;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
transfer_points(g, &g->player.points, &g->temp_points, hand_points(&g->player.scored));
|
||||
transfer_points(g, &g->right.points, &g->temp_points, hand_points(&g->right.scored));
|
||||
transfer_points(g, &g->left.points, &g->temp_points, hand_points(&g->left.scored));
|
||||
transfer_points(g, &g->player.points, &g->temp_points, hp[0]);
|
||||
transfer_points(g, &g->right.points, &g->temp_points, hp[1]);
|
||||
transfer_points(g, &g->left.points, &g->temp_points, hp[2]);
|
||||
if (hp[0] > hp[1]) {
|
||||
if (hp[0] > hp[2]) g->dealer = &g->player;
|
||||
else
|
||||
if (hp[2] > hp[1]) g->dealer = &g->left;
|
||||
else g->dealer = &g->right;
|
||||
} else {
|
||||
if (hp[1] > hp[2]) g->dealer = &g->right;
|
||||
else g->dealer = &g->left;
|
||||
}
|
||||
break;
|
||||
}
|
||||
g->state = GAME_STATE_INITIALIZING;
|
||||
|
Loading…
Reference in New Issue
Block a user