From 4edef40cef37e79292496218be822e6b301c000c Mon Sep 17 00:00:00 2001 From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr> Date: Mon, 9 Nov 2015 12:13:49 +0100 Subject: [PATCH] Misc. error correction --- src/game/morpion.cpp | 19 ++++++++++--------- src/game/morpion.hpp | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/game/morpion.cpp b/src/game/morpion.cpp index 9235c8c..dcb0fab 100644 --- a/src/game/morpion.cpp +++ b/src/game/morpion.cpp @@ -103,11 +103,11 @@ namespace game bool morpion::has_won(uint16_t bitboard) { - if(bitboard == ROW0_MASK || bitboard == ROW1_MASK || bitboard == ROW2_MASK) // Check vertical | + if(((bitboard | ROW0_MASK) == ALL_ONES) || ((bitboard | ROW1_MASK) == ALL_ONES) || ((bitboard | ROW2_MASK) == ALL_ONES)) // Check horizontal --- return true; - if(bitboard == COL0_MASK || bitboard == COL1_MASK || bitboard == COL2_MASK) // Check horizontal _ + if(((bitboard | COL0_MASK) == ALL_ONES) || ((bitboard | COL1_MASK) == ALL_ONES) || ((bitboard | COL2_MASK) == ALL_ONES)) // Check vertical | return true; - if(bitboard == DIA0_MASK || bitboard == DIA1_MASK) // Chack diagonal \ / + if(((bitboard | DIA0_MASK) == ALL_ONES) || ((bitboard | DIA1_MASK) == ALL_ONES)) // Chack diagonal \ / return true; return false; } @@ -116,6 +116,7 @@ namespace game void morpion::update_moves() { uint16_t free_bitboard = ~(state.cross_bitboard | state.circle_bitboard); + state.possible_moves = 0; for(int i = 0; i <=8; i++) { if(free_bitboard & 1) @@ -129,11 +130,10 @@ namespace game void morpion::play(uint16_t m) { - 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; + state.cross_bitboard += (1 << m); else - state.circle_bitboard += 1 << position; + state.circle_bitboard += (1 << m); //State update state.total_moves++; @@ -179,9 +179,9 @@ namespace game result += "|"; for (int col = 2; col >= 0; col--) { - if(((state.cross_bitboard >> 3*row) >> col) & 1) + if(((state.cross_bitboard >> (3*row)) >> col) & 1) result += player_to_string(CROSS)+"|"; - else if (((state.circle_bitboard >> 3*row) >> col) & 1) + else if (((state.circle_bitboard >> (3*row)) >> col) & 1) result += player_to_string(CIRCLE)+"|"; else result += " |"; @@ -197,7 +197,8 @@ namespace game { uniform_int_distribution<uint16_t> distribution(0, 8-state.total_moves); uint16_t move = distribution(engine); - play(move); + uint16_t position = (state.possible_moves >> 4*move) & 15; //15 is the mask to get only one move + play(position); } } diff --git a/src/game/morpion.hpp b/src/game/morpion.hpp index 052f505..0b74afd 100644 --- a/src/game/morpion.hpp +++ b/src/game/morpion.hpp @@ -66,6 +66,7 @@ namespace game const uint16_t COL2_MASK = 219; const uint16_t DIA0_MASK = 238; const uint16_t DIA1_MASK = 427; + const uint16_t ALL_ONES = 511; static std::vector<std::vector<uint64_t>> cross_hash_values; static std::vector<std::vector<uint64_t>> circle_hash_values; -- GitLab