Commit e01569e1 authored by Emil's avatar Emil

Test simple moves passes

parent 3db3c94a
......@@ -132,7 +132,7 @@ namespace std {
struct hash<gameengine::Move> {
size_t operator()(const gameengine::Move& move) const
{
return std::hash<gameengine::BitPieces>{}(move.start_pos) ^ std::hash<gameengine::BitPieces>{}(move.Cap_piecs) ^std::hash<gameengine::BitPieces>{}(move.Valid_moves.back());
return std::hash<gameengine::BitPieces>{}(move.start_pos) ^std::hash<gameengine::BitPieces>{}(move.Cap_piecs) ^std::hash<gameengine::BitPieces>{}(move.Valid_moves.back());
}
};
}
......
......@@ -111,19 +111,19 @@ namespace gameengine::utility
// Masks for player One (simple moves and jumps)
if (player_id == PlayerId::One) {
East = (unoccupied & MaskEast)>>9 & occupiedPosition(board,player_id);
East_jump = ((unoccupied & MaskEast)>>9 & occupiedPosition(board,PlayerId::Two)) & ((unoccupied & MaskEast)>>9 & occupiedPosition(board,player_id));
East_jump = ((unoccupied & MaskEast)>>9 & occupiedPosition(board,PlayerId::Two)) & (((((unoccupied & MaskEast)>>9) & occupiedPosition(board,PlayerId::Two))>>9) & occupiedPosition(board,player_id));
West = (unoccupied & MaskWest)>>7 & occupiedPosition(board,player_id);
West_jump = ((unoccupied & MaskWest)>>7 & occupiedPosition(board,PlayerId::Two)) & ((unoccupied & MaskWest)>>7 & occupiedPosition(board,player_id));
West_jump = ((unoccupied & MaskWest)>>7 & occupiedPosition(board,PlayerId::Two)) & (((((unoccupied & MaskWest)>>7) & occupiedPosition(board,PlayerId::Two))>>7) & occupiedPosition(board,player_id));
}
// Masks for player Two (simple moves and jumps)
else {
East = (unoccupied & MaskEast)<<7 & occupiedPosition(board,player_id);
East_jump = ((unoccupied & MaskEast)<<7 & occupiedPosition(board,PlayerId::One)) & ((unoccupied & MaskEast)<<7 & occupiedPosition(board,player_id));
East_jump = ((unoccupied & MaskEast)<<7 & occupiedPosition(board,PlayerId::One)) & (((((unoccupied & MaskEast)<<7) & occupiedPosition(board,PlayerId::One))<<7) & occupiedPosition(board,player_id));
West = (unoccupied & MaskWest)<<9 & occupiedPosition(board,player_id);
West_jump = ((unoccupied & MaskWest)<<9 & occupiedPosition(board,PlayerId::One)) & ((unoccupied & MaskWest)<<9 & occupiedPosition(board,player_id));
West_jump = ((unoccupied & MaskWest)<<9 & occupiedPosition(board,PlayerId::One)) & (((((unoccupied & MaskWest)<<9) & occupiedPosition(board,PlayerId::One))<<9) & occupiedPosition(board,player_id));
}
// if there is no jumps, then simple moves are legal
if (East_jump.none()||West_jump.none()){
if (East_jump.none() && West_jump.none()){
//oder all legal simple moves for player 1
if (player_id == PlayerId::One){
while (!mask.none()) {
......@@ -164,8 +164,8 @@ namespace gameengine::utility
//jumps for player one
if (player_id == PlayerId::One){
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
BitPieces EastMove = East_jump & mask;
BitPieces WestMove = West_jump & mask;
if (!WestMove.none()){
new_jumps.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove<<14},BitPieces(WestMove<<7)});
......@@ -181,8 +181,8 @@ namespace gameengine::utility
//jumps for player two
else {
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
BitPieces EastMove = East_jump & mask;
BitPieces WestMove = West_jump & mask;
if (!WestMove.none()){
new_jumps.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove>>18},BitPieces(WestMove>>9)});
......
......@@ -10,6 +10,7 @@ find_package(Threads REQUIRED)
# Test sources
set(TESTS
utility_unittests
utility_unittests_moves
)
......
// gtest
#include <gtest/gtest.h> // googletest header file
// engine
#include <engine/gameengine.h>
#include <engine/monkeyai.h>
// stl
#include <variant>
using namespace gameengine;
/////////////////
/// Legal Moves
static BitPieces P1 ("00000000"
"00000000"
"00000000"
"00000000"
"00000000"
"00000100"
"00000000"
"00000000");
static BitPieces P2 ("00000000"
"01000000"
"00000000"
"00000000"
"00000000"
"00000000"
"00000000"
"00000000");
static BitPieces P2_jump ("00000000"
"00000000"
"00000000"
"00000000"
"00000010"
"00000000"
"00000000"
"00000000");
static Move legal_moves_east(P1,
{BitPieces("00000000"
"00000000"
"00000000"
"00000000"
"00000010"
"00000000"
"00000000"
"00000000")},
{});
static Move legal_moves_west(P1,
{BitPieces("00000000"
"00000000"
"00000000"
"00000000"
"00001000"
"00000000"
"00000000"
"00000000")},
{});
static Move legal_jumps (P1,
{BitPieces("00000000"
"00000000"
"00000000"
"00000001"
"00000000"
"00000000"
"00000000"
"00000000")},
{P2_jump});
// Testing fixture
struct legalMovesParameters {
BitBoard board;
PlayerId player_id;
Moves legal_moves_exp;
};
struct legalMovesFixture : testing::Test,
testing::WithParamInterface<legalMovesParameters> {
};
// Tests
TEST_P(legalMovesFixture, EQ_Test)
{
auto params = GetParam();
auto legal_moves
= gameengine::utility::legalMoves(params.board, params.player_id);
EXPECT_EQ(legal_moves, params.legal_moves_exp);
}
// Test set instantiations
INSTANTIATE_TEST_SUITE_P(
legalMoves,
legalMovesFixture,
testing::Values(legalMovesParameters{
BitBoard({P1,P2}),
PlayerId::One,
Moves{legal_moves_east,legal_moves_west}
},
legalMovesParameters{
BitBoard({P1,P2_jump}),
PlayerId::One,
Moves{legal_jumps}
}
)
);
......@@ -36,7 +36,7 @@ TEST_P(NextPositionFixture, EQ_Test)
}
// Test set instantiations
INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
NextPosition,
NextPositionFixture,
testing::Values(NextPositionParameters{
......@@ -44,3 +44,5 @@ INSTANTIATE_TEST_CASE_P(
NextPositionParameters{
BitPos(9), MoveDirection::S, BitPos(1)}
) );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment