diff options
Diffstat (limited to 'api/game')
-rw-r--r-- | api/game/socket.py | 10 | ||||
-rwxr-xr-x | api/game/voerbak | bin | 16592 -> 16624 bytes | |||
-rw-r--r-- | api/game/voerbak.c | 11 | ||||
-rw-r--r-- | api/game/voerbak_connector.py | 3 |
4 files changed, 23 insertions, 1 deletions
diff --git a/api/game/socket.py b/api/game/socket.py index 33fbf1b..f4ea3a5 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -17,6 +17,12 @@ class game: # if not self.board.player_1 == player_1_move: return self.board.drop_fisje(column) self.io.emit("fieldUpdate", { "field": self.board.board }) + self.io.emit("turnUpdate", { "player1": self.board.player_1 }) + if len(self.board.win_positions) > 0 or self.board.board_full: + self.io.emit("finish", { + "winPositions": self.board.win_positions, + "boardFull": self.board.board_full + }) def run(app): io = SocketIO(app, cors_allowed_origins="*") @@ -30,7 +36,9 @@ def run(app): @io.on("newMove") def new_move(data): # json_data = json.loads(data) - games[0].move(data["token"], data["move"]) + game = games[0] + if(len(game.board.win_positions) > 0 or game.board.board_full): return + game.move(data["token"], data["move"]) io.run(app, host="127.0.0.1", port=5000, debug=True) diff --git a/api/game/voerbak b/api/game/voerbak Binary files differindex e7b7a14..e474172 100755 --- a/api/game/voerbak +++ b/api/game/voerbak diff --git a/api/game/voerbak.c b/api/game/voerbak.c index f0ecb4a..5674f5e 100644 --- a/api/game/voerbak.c +++ b/api/game/voerbak.c @@ -60,6 +60,12 @@ bool checkWin(int board[], int width, int height, int pos) { return won; } +bool boardFull(int board[], int width, int height) { + for (int i = 0; i < width * height; i++) + if (board[i] == 0) return false; + return true; +} + bool dropFisje(int board[], int width, int height, int column, int disc) { for (int row = 0; row < height; row++) { int pos = column + row * width; @@ -93,6 +99,11 @@ int main() { printf("m:%s\n", player_1 ? "true" : "false"); fflush(stdout); + if (boardFull(board, width, height)) { + printf("d:full\n"); + fflush(stdout); + } + printBoard(board, width, height); } diff --git a/api/game/voerbak_connector.py b/api/game/voerbak_connector.py index 9627f29..5ccaed8 100644 --- a/api/game/voerbak_connector.py +++ b/api/game/voerbak_connector.py @@ -20,6 +20,7 @@ class bord: self.height = h self.player_1 = True self.board = "0" * (w * h) + self.board_full = False self.win_positions = [] self.process = subprocess.Popen([VOERBAK_LOCATION], stdin=subprocess.PIPE, @@ -42,6 +43,8 @@ class bord: elif buffer.startswith("m:"): substr = buffer[2:] self.player_1 = True if substr == "true" else False + elif buffer.startswith("d:"): + self.board_full = True buffer = self.get_output() self.board = buffer |