internal ChessMove[] GetBoardThreats(out bool ownKingUnderThreat, PiecePlayer playerToEvaluate) { ChessBoardLocation kingLocation = new ChessBoardLocation(-1, -1); List <ChessMove> opponentMoves = new List <ChessMove>(); var player = playerToEvaluate == PiecePlayer.White ? PiecePlayer.Black : PiecePlayer.White; for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { if (_pieces[i, j].Player == playerToEvaluate) { var moves = GetAvailableMoves(playerToEvaluate, i, j, false); opponentMoves.AddRange(moves); } else if (_pieces[i, j].Player == player && _pieces[i, j].Rank == PieceRank.King) { kingLocation = new ChessBoardLocation(i, j); } } } ownKingUnderThreat = opponentMoves.Where(o => o.To.HorizontalLocation == kingLocation.HorizontalLocation && o.To.VerticalLocation == kingLocation.VerticalLocation).Any(); if (ownKingUnderThreat == true) { // Currently board has been verified as "check". // Now let's verify that is it also "checkmate". } return(opponentMoves.ToArray()); }
public ChessMove(PieceRank rank, PiecePlayer player, int horizontalLocationFrom, int verticalLocationFrom, int horizontalLocationTo, int verticalLocationTo, ChessSpecialMove specialMove) { Rank = rank; Player = player; From = new ChessBoardLocation(horizontalLocationFrom, verticalLocationFrom); To = new ChessBoardLocation(horizontalLocationTo, verticalLocationTo); SpecialMove = specialMove; }