public bool IsTerminal(out PlayerId winningPlayerNumber) { winningPlayerNumber = PlayerId.None; if (skips >= 2) { int player1Score = BitTwiddling.PopCount(player1Pieces); int player2Score = BitTwiddling.PopCount(player2Pieces); if (player1Score > player2Score) { winningPlayerNumber = PlayerId.Player1; } if (player1Score < player2Score) { winningPlayerNumber = PlayerId.Player2; } return(true); } ; return(false); }
public ulong Captures(ulong currentPieces, ulong opponentPieces, ulong location) { // from our current location, we can move in any direction // as long as we continually encounter opponent pieces // we capture them all as long as the first non opponent piece contains a current player piece ulong captures = 0ul; int loc_index = BitTwiddling.TrailingZeroCount(location); int row = loc_index / 8; int col = loc_index % 8; captures |= Look(currentPieces, opponentPieces, row, col, -1, 0); // up captures |= Look(currentPieces, opponentPieces, row, col, 1, 0); // down captures |= Look(currentPieces, opponentPieces, row, col, 0, -1); // left captures |= Look(currentPieces, opponentPieces, row, col, 0, 1); // right captures |= Look(currentPieces, opponentPieces, row, col, -1, -1); // up left captures |= Look(currentPieces, opponentPieces, row, col, -1, 1); // up right captures |= Look(currentPieces, opponentPieces, row, col, 1, -1); // down left captures |= Look(currentPieces, opponentPieces, row, col, 1, 1); // down right return(captures); }
public string DescribeLastMove() => BitTwiddling.TrailingZeroCount(lastMove).ToString();