public static ulong GetLegalMoves(this BitBoard board, byte player) { // https://intellitect.com/when-to-use-and-not-use-var-in-c/ // https://stackoverflow.com/a/41505/11898496 var moves = 0UL; var playerPiece = board.Pieces[player]; var opponentPiece = board.Pieces[Constant.Opponent(player)]; var empties = board.GetEmpties(); // https://stackoverflow.com/a/105402/11898496 foreach (var direction in DirectionValues) { var candidates = opponentPiece & playerPiece.Shift(direction); while (candidates != 0) { var candidatesShifted = candidates.Shift(direction); moves |= empties & candidatesShifted; candidates = opponentPiece & candidatesShifted; } } return(moves); }
public static bool IsGameComplete(this BitBoard board) { return(board.GetEmpties() == 0 || !board.HasAnyPlayerHasAnyLegalMove()); }