From c0a53356ae806eba4e5cfa3ecf2a25a3dafd15c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gast=C3=A9?= <adrien.gaste@insa-rennes.fr> Date: Mon, 9 Nov 2015 11:20:22 +0100 Subject: [PATCH] Implemented play function --- src/game/morpion.cpp | 11 ++++++++++- src/game/morpion.hpp | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/game/morpion.cpp b/src/game/morpion.cpp index e3445ce..0934698 100644 --- a/src/game/morpion.cpp +++ b/src/game/morpion.cpp @@ -121,7 +121,16 @@ namespace game void morpion::play(uint16_t m) { - uint16_t bitboard = state.cross_bitboard | state.circle_bitboard; + uint16_t position = (state.possible_moves >> 4*m) & 15; //15 is the mask to get only one move + if (current_player() == CROSS) + state.cross_bitboard += 1 << position; + else + state.circle_bitboard += 1 << position; + + //State update + state.total_moves++; + update_win(); + update_moves(); return; } diff --git a/src/game/morpion.hpp b/src/game/morpion.hpp index 327f1b5..f8c7cc7 100644 --- a/src/game/morpion.hpp +++ b/src/game/morpion.hpp @@ -14,6 +14,7 @@ namespace game uint16_t cross_bitboard = 0; //bitboard with the played moves of the cross uint16_t circle_bitboard = 0; //bitboard with the played moves of the circle uint8_t total_moves = 0; //Total played moves (<= 9) + uint64_t possible_moves = 0x876543210; //List of possible moves left bool first_player_win = false; //First player is always the cross bool second_player_win = false; //Second player is always the circle }; -- GitLab