state machine WIP

This commit is contained in:
Eenae 2019-04-13 20:28:19 +03:00
parent 92b2b6f9ce
commit 53b322b8c8
2 changed files with 22 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.a
*.o
*.sw*
*.dylib
*.ll
@ -24,5 +25,6 @@ tags
node_modules/
build/
data/
.idea/
.eos-dev/
wallet.pass

View File

@ -7,19 +7,31 @@ struct pub_key_type {
struct Game {
bool new_game(int n) {
if (state != STATE_NOT_STARTED)
return false;
len = 0;
players = (char**)malloc(sizeof(char*) * n);
stakes = (int*)malloc(sizeof(int) * n);
state = STATE_GATHERING_STAKES;
return true;
}
bool add_stake(int stake, pub_key_type pub_key) {
if (state != STATE_GATHERING_STAKES)
return false;
stakes[len] = stake;
players[len] = pub_key.data;
++len;
return true;
}
int get_stake(pub_key_type pub_key) {
if (state == STATE_NOT_STARTED)
return false;
for (int i = 0; i < len; i++) {
if (compare(players[i], pub_key.data, pub_key.len))
return stakes[i];
@ -41,9 +53,17 @@ struct Game {
}
char** get_participants() {
if (state == STATE_NOT_STARTED)
return 0;
return players;
}
private:
static const int STATE_NOT_STARTED = 0;
static const int STATE_GATHERING_STAKES = 1;
static const int STATE_REVEALING = 2;
int state;
int *stakes;
char **players;
int len;