Ejemplo n.º 1
0
        public bool IsPathBlocked(Path path)
        {
            foreach (var square in path.GetSpaces())
            {
                if (GetPiece(square) != null)
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 2
0
        public bool IsPlayerInCheck(PlayerColor color)
        {
            var kingLocation = getKingLocationByColor(color);
            var enemyPieces = _pieces.Where(x => x.Value.Color != color);

            foreach (var pieceAndLocation in enemyPieces)
            {
                var piece = pieceAndLocation.Value;
                var location = pieceAndLocation.Key;

                if (piece.GetLegalMovesFromCoordinate(location, BoardSize).Contains(kingLocation))
                {
                    var path = new Path(location, kingLocation);
                    if (!IsPathBlocked(path))
                    {
                        return true;
                    }
                }
            }

            return false;
        }