Commit 3db3c94a authored by Emil's avatar Emil

+ jumps to legalmoves (not tested, compiles)

parent dd617cae
......@@ -101,59 +101,101 @@ namespace gameengine::utility
Moves legalMoves(const BitBoard& board, const PlayerId& player_id)
{
Moves new_moves{};
Moves new_jumps{};
BitPieces East;
BitPieces East_jump;
BitPieces West;
BitPieces West_jump;
BitPieces mask = MaskCheck;
BitPieces unoccupied = ~occupiedPositions(board);
// Masks for player One (simple moves)
// Masks for player One (simple moves and jumps)
if (player_id == PlayerId::One) {
East = (unoccupied & MaskEast)>>9 & occupiedPosition(board,player_id);
West = (unoccupied & MaskWest)>>7 & occupiedPosition(board,player_id);
East = (unoccupied & MaskEast)>>9 & occupiedPosition(board,player_id);
East_jump = ((unoccupied & MaskEast)>>9 & occupiedPosition(board,PlayerId::Two)) & ((unoccupied & MaskEast)>>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));
}
// Masks for player Two (simple moves)
// Masks for player Two (simple moves and jumps)
else {
East = (unoccupied & MaskEast)<<7 & occupiedPosition(board,player_id);
West = (unoccupied & MaskWest)<<9 & occupiedPosition(board,player_id);
East = (unoccupied & MaskEast)<<7 & occupiedPosition(board,player_id);
East_jump = ((unoccupied & MaskEast)<<7 & occupiedPosition(board,PlayerId::One)) & ((unoccupied & MaskEast)<<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));
}
//oder all legal moves for player 1
if (player_id == PlayerId::One){
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (EastMove.none()||WestMove.none()){
mask<<=1;
}
if (!EastMove.none()) {
new_moves.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove<<9},{}});
// if there is no jumps, then simple moves are legal
if (East_jump.none()||West_jump.none()){
//oder all legal simple moves for player 1
if (player_id == PlayerId::One){
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (!WestMove.none()){
new_moves.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove<<7},{}});
}
if (!EastMove.none()) {
new_moves.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove<<9},{}});
}
mask<<=1;
}
else {
new_moves.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove<<7},{}});
mask<<=1;
}
}
}
//oder all legal moves for player 2
else {
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (EastMove.none()||WestMove.none()){
mask<<=1;
}
if (!EastMove.none()) {
new_moves.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove>>7},{}});
mask<<=1;
}
else {
}
//oder all legal moves for player 2
else {
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (!WestMove.none()){
new_moves.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove>>9},{}});
mask<<=1;
}
}
if (!EastMove.none()) {
new_moves.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove>>7},{}});
}
mask<<=1;
}
}
return new_moves;
}
// oder all legal jumps
else {
//jumps for player one
if (player_id == PlayerId::One){
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (!WestMove.none()){
new_jumps.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove<<14},BitPieces(WestMove<<7)});
}
if (!EastMove.none()) {
new_jumps.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove<<18},BitPieces(EastMove<<9)});
}
mask<<=1;
}
}
//jumps for player two
else {
while (!mask.none()) {
BitPieces EastMove = East & mask;
BitPieces WestMove = West & mask;
if (!WestMove.none()){
new_jumps.emplace(Move{BitPieces(WestMove), std::vector<BitPieces>{WestMove>>18},BitPieces(WestMove>>9)});
}
if (!EastMove.none()) {
new_jumps.emplace(Move{BitPieces(EastMove), std::vector<BitPieces>{EastMove>>14},BitPieces(EastMove>>7)});
}
mask<<=1;
}
}
return new_jumps;
}
}
bool isLegalMove(const BitBoard& board, const PlayerId& player_id,
......
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