-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhumanPlayer.xc
42 lines (41 loc) · 1.31 KB
/
humanPlayer.xc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <state.xh>
#include <driver.xh>
#include <players.xh>
#include <stdlib.h>
#include <stdbool.h>
Player makeHumanPlayer() {
return (Player){"human", lambda (State s, const Hand h, const Hand hands[], const Hand discard, const unsigned handSizes[], TurnInfo turn, vector<Action> actions) -> unsigned {
PlayerId p = turn.player;
printf("Hand: %s\n", showHand(h).text);
if (hands) {
for (PlayerId p1 = 0; p1 < numPlayers(s); p1++) {
if (p != p1) {
printf("Player %d's hand: %s\n", p1, showHand(hands[p1]).text);
}
}
}
printf("%s", showActions(actions, p, partner(numPlayers(s), p)).text);
if (actions.size > 1) {
unsigned result;
bool success = false;
printf("Enter a move #: ");
fflush(stdout);
while (!success) {
success = scanf("%u", &result) && result < actions.size;
if (!success) {
printf("Invalid move, please try again: ");
fflush(stdout);
}
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
return result;
} else {
printf("(Press Enter)");
fflush(stdout);
while (getchar() != '\n');
return 0;
}
}, lambda (State s, TurnInfo turn, Action action) -> void {}
};
}