Skip to content
Snippets Groups Projects
Commit 4edef40c authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Misc. error correction

parent e8ebd880
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment