コード例 #1
0
ファイル: Figure.cs プロジェクト: tkondraciuk/Chess
        public virtual List <Move> getPossibleMoves()
        {
            List <Move> moves        = calculateMoves();
            King        king         = Board.GetFigures(Color, FiguresEnum.King).FirstOrDefault() as King;
            List <Move> movesInCheck = new List <Move>();

            foreach (var move in moves)
            {
                Position p = move.Destination;
                Position currentPosition  = new Position(Position);
                Figure   figureOnPosition = Board.GetFigure(p);
                if (figureOnPosition != null)
                {
                    Board.RemoveFigure(figureOnPosition);
                }
                setPosition(p);
                if (!king.isInCheck())
                {
                    movesInCheck.Add(move);
                }
                setPosition(currentPosition);
                if (figureOnPosition != null)
                {
                    Board.AddFigure(figureOnPosition);
                }
            }
            return(movesInCheck);
        }
コード例 #2
0
        public bool isCheck()
        {
            King whiteKing = GetFigures(Color.White, FiguresEnum.King).FirstOrDefault() as King;
            King blackKing = GetFigures(Color.Black, FiguresEnum.King).FirstOrDefault() as King;

            if (whiteKing != null && whiteKing.isInCheck())
            {
                KingInCheck = whiteKing;
                isMate();
                return(true);
            }
            if (blackKing != null && blackKing.isInCheck())
            {
                KingInCheck = blackKing;
                isMate();
                return(true);
            }
            KingInCheck = null;
            return(false);
        }