private IEnumerable <(Figure, Position)> FindPossibleBlockers(Figure culprit, Position kingPosition, TeamColor kingTeamColor)
        {
            if (culprit.FigureType == FigureType.Knight)
            {
                return(new List <(Figure, Position)>());
            }

            var path     = new Vector(culprit.Position, kingPosition).GetPath();
            var blockers = new List <(Figure, Position)>();

            foreach (var field in path)
            {
                for (int i = 0; i < _board.GetBoardSize(); i++)
                {
                    for (int j = 0; j < _board.GetBoardSize(); j++)
                    {
                        var figure = _board.FigureAt(_board.GetPositionAt(i, j));
                        if (figure != null &&
                            figure.TeamColor == kingTeamColor &&
                            figure.FigureType != FigureType.King &&
                            figure.CanMove(field) &&
                            _moveValidator.CanMove(figure, field).Item1)
                        {
                            blockers.Add((figure, field));
                        }
                    }
                }
            }
            return(blockers);
        }
示例#2
0
        public (bool, string) CanMove(Position from, Position destination)
        {
            var figure = _board.FigureAt(from);

            if (figure == null)
            {
                return(false, "There is no figure at the given position");
            }
            if (!figure.CanMove(destination))
            {
                return(false, $"This move is not possible for a type figure: {figure.FigureType}");
            }

            var moveValidatorResult = _moveValidator.CanMove(figure, destination);

            if (!moveValidatorResult.Item1)
            {
                return(moveValidatorResult);
            }

            if (_verifier.VerifyMoveCauseCheck(figure.Position, destination))
            {
                return(false, "You can't make this move, because it would put your king in a chequered position");
            }

            return(true, "OK");
        }
示例#3
0
 private Figure FindFigureCausingCheck(Figure king)
 {
     for (int i = 0; i < OrdinaryChessBoard.BoardSize; i++)
     {
         for (int j = 0; j < OrdinaryChessBoard.BoardSize; j++)
         {
             var figure = _board.FigureAt(_board.GetPositionAt(j, i));
             if (figure != null &&
                 figure.TeamColor != king.TeamColor &&
                 figure.CanMove(king.Position) &&
                 _moveValidator.CanMove(figure, king.Position).Item1)
             {
                 return(figure);
             }
         }
     }
     return(null);
 }