From 53b322b8c84232a773a5a2b0ef47e82dc5664339 Mon Sep 17 00:00:00 2001 From: Eenae Date: Sat, 13 Apr 2019 20:28:19 +0300 Subject: [PATCH] state machine WIP --- .gitignore | 2 ++ main.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.gitignore b/.gitignore index c763c32..163dd8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.a +*.o *.sw* *.dylib *.ll @@ -24,5 +25,6 @@ tags node_modules/ build/ data/ +.idea/ .eos-dev/ wallet.pass diff --git a/main.cpp b/main.cpp index a25b4fa..0daa29d 100644 --- a/main.cpp +++ b/main.cpp @@ -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;