diff --git a/src/game/morpion.cpp b/src/game/morpion.cpp index a2dd622888123bc350d720fe8d0c044f7144f44e..7a9316b7920e7d6b2fe0b1924d0a6d653eca2e6e 100644 --- a/src/game/morpion.cpp +++ b/src/game/morpion.cpp @@ -138,14 +138,18 @@ namespace game //cout << "Possible moves: " << state.possible_moves << endl; } - //Play the move m. m is the position on the board of where you want to play + //Play the mth move in the possible moves list. void morpion::play(uint16_t m) { - //cout << "You choose move " << m << endl; + uint64_t possible_moves = state.possible_moves; + possible_moves = possible_moves >> 4*m; //A move is coded with 4 bit + uint16_t move = possible_moves & 15; //15 = 1111 + //cout << "You choose the possible move number " << m << endl; + //cout << "You choose move " << move << endl; if (current_player() == CROSS) - state.cross_bitboard |= (((uint16_t) 1) << m); + state.cross_bitboard |= (((uint16_t) 1) << move); else - state.circle_bitboard |= (((uint16_t) 1) << m); + state.circle_bitboard |= (((uint16_t) 1) << move); //State update state.total_moves++; @@ -207,8 +211,7 @@ namespace game { uniform_int_distribution<uint16_t> distribution(0, 8-state.total_moves); uint16_t move = distribution(engine); - uint16_t position = (state.possible_moves >> 4*move) & 15; //15 is the mask to get only one move - play(position); + play(move); } } diff --git a/src/game/test_morpion.cpp b/src/game/test_morpion.cpp index 36796714aaefd887eb9d952e745feb5ba8edace4..78360007bf0bc683a05ecdf9b13b1fa9aa5b6350 100644 --- a/src/game/test_morpion.cpp +++ b/src/game/test_morpion.cpp @@ -31,7 +31,7 @@ namespace game { uint16_t move = possible_moves & ((uint64_t) 15); //15 = 1111 (a move is on 4 bits) cout << "Possible move: " << mor.move_to_string(move) << endl; - movesMap[mor.move_to_string(move)] = move; //In the map: the move as seen by the player and its representation for the computer + movesMap[mor.move_to_string(move)] = i; //In the map: the move as seen by the player and its representation for the computer possible_moves = possible_moves >> 4; } string move; @@ -51,7 +51,7 @@ namespace game void test_morpion::playout() { morpion mor; - auto mctsPlayer = mcts::make_mcts_two_players(mor, 5000, 0.3, 4); + auto mctsPlayer = mcts::make_mcts_two_players(mor, 5000, 0.3, 4); // creation du player a partir du morpion. 5000: ms de reflexion 0.3 fateur d'exploration 4: nb_visit_before_expansion on attend d'etre arrive 4 fois sur un noeud avant de le developper cout << "Player vs Computer game!" << endl; cout << "Who's first? (Player)" << endl; while(!mor.end_of_game()) @@ -60,7 +60,8 @@ namespace game if(mor.current_player() == 1) //It's circle turn (computer is circle) { uint16_t move = mctsPlayer.select_move(); - cout << "Computer wants to play " << mor.move_to_string(move); + //cout << "Computer played " << mor.move_to_string(move) << endl; + mor.play(move); } else //Human turn to play { @@ -72,7 +73,7 @@ namespace game { uint16_t move = possible_moves & ((uint64_t) 15); //15 = 1111 (a move is on 4 bits) cout << "Possible move: " << mor.move_to_string(move) << endl; - movesMap[mor.move_to_string(move)] = move; //In the map: the move as seen by the player and its representation for the computer + movesMap[mor.move_to_string(move)] = i; //In the map: the move as seen by the player and possible_moves = possible_moves >> 4; } string move;