Beispiel #1
0
 public Turn(Board board, PieceColour playingColour, ISquare enPassantSquare = null, bool leaf = false)
 {
     CurrentBoard  = board;
     PlayingColour = playingColour;
     CurrentBoard.EnPassantSquare = enPassantSquare;
     _leaf = leaf;
 }
Beispiel #2
0
 private void SendGameOver(PieceColour winningColour)
 {
     if (GameOver != null)
     {
         GameOver(this, winningColour);
     }
 }
Beispiel #3
0
        public IEnumerable <IGridLocation> PawnAttackedLocations(ISquare pawn)
        {
            AssertType(pawn, PieceType.Pawn);

            PieceColour colour = pawn.Colour;
            byte        xCoord = pawn.Location.XCoord;
            byte        yCoord = pawn.Location.YCoord;

            List <IGridLocation> attacked = new List <IGridLocation>();

            // If the pawn is on the last row, it's attacking nothing.
            if (LastRow(pawn))
            {
                return(attacked);
            }

            sbyte minusIfWhite = (sbyte)((colour == PieceColour.White) ? -1 : 1);

            // Add the diagonal squares to the list if they exist on the board.
            IGridLocation left  = new GridLocation((byte)(xCoord - 1), (byte)(yCoord + minusIfWhite));
            IGridLocation right = new GridLocation((byte)(xCoord + 1), (byte)(yCoord + minusIfWhite));

            if (xCoord != 0)
            {
                attacked.Add(left);
            }
            if (xCoord != 7)
            {
                attacked.Add(right);
            }

            return(attacked);
        }
Beispiel #4
0
        public GamePlayerMoveResult MakeMove(PieceColour pieceColour, GameState gameState)
        {
            var currentMoves = gameState.CalculateAvailableMoves(pieceColour).ToList();

            if (!currentMoves.Any())
            {
                return(new GamePlayerMoveResult(null, MoveStatus.NoLegalMoves));
            }

            var moveWeights = new List <Tuple <double, GameMove> >();

            foreach (var move in currentMoves)
            {
                var moveMetric = move.CalculateGameMoveMetrics(pieceColour);

                double weightedResult = 0;
                weightedResult += KingWeight * moveMetric.CreatedFriendlyKings;
                weightedResult += NextAvailableMoveCountWeight * moveMetric.FriendlyMovesAvailable;
                weightedResult += OpponentNextAvailableMoveCountWeight * moveMetric.OpponentMovesAvailable;
                weightedResult += NextMovePiecesAtRiskWeight * moveMetric.NextMoveFriendlyPiecesAtRisk;
                weightedResult += NextMovePiecesToTakeWeight * moveMetric.NextMoveOpponentPiecesAtRisk;
                weightedResult += NextMoveKingWeight * moveMetric.NextMoveFriendlyKingsCreated;
                weightedResult += OpponentNextMoveKingWeight * moveMetric.NextMoveOpponentKingsCreated;

                var resultTuple = new Tuple <double, GameMove>(weightedResult, move);
                moveWeights.Add(resultTuple);
            }

            var selectedMove      = moveWeights.OrderByDescending(m => m.Item1).First().Item2;
            var selectedGameState = selectedMove.PerformMove();
            var result            = new GamePlayerMoveResult(selectedGameState, MoveStatus.SuccessfulMove);

            return(result);
        }
Beispiel #5
0
 private void GameOverHandler(object sender, PieceColour winningColour)
 {
     if (GameOver != null)
     {
         GameOver(this, winningColour);
     }
 }
Beispiel #6
0
 public Piece(PieceType type, PieceColour colour, int value, Position position)
 {
     Type            = type;
     Colour          = colour;
     Value           = value;
     CurrentPosition = position;
 }
Beispiel #7
0
        private PieceRank CalculatePieceRank(int yPosition, PieceColour pieceColour, PieceRank pieceRank)
        {
            PieceRank resultPieceRank = PieceRank.Minion;

            if (pieceRank == PieceRank.King)
            {
                resultPieceRank = PieceRank.King;
            }
            else
            {
                switch (pieceColour)
                {
                case PieceColour.White:
                    if (yPosition == YLength - 1)
                    {
                        resultPieceRank = PieceRank.King;
                    }
                    break;

                case PieceColour.Black:
                    if (yPosition == 0)
                    {
                        resultPieceRank = PieceRank.King;
                    }
                    break;
                }
            }
            return(resultPieceRank);
        }
Beispiel #8
0
        public List <Move> AvailableMoves(PieceColour playingColour)
        {
            List <Move> allMoves       = new List <Move>();
            List <Move> availableMoves = new List <Move>();

            foreach (ISquare mover in this)
            {
                if (mover.Type != PieceType.None && mover.Colour == playingColour)
                {
                    foreach (Move move in AvailableMovesFromSquare(mover))
                    {
                        allMoves.Add(move);
                    }
                }
            }

            foreach (Move move in allMoves)
            {
                Turn hypotheticalTurn = new Turn(Copy(), playingColour, leaf: true);
                hypotheticalTurn.Execute(move);
                if (!hypotheticalTurn.CurrentBoard.InCheck(this[move.Start].Colour))
                {
                    availableMoves.Add(move);
                }
            }
            return(availableMoves);
        }
Beispiel #9
0
        private static void TestPieceType(PieceType type, PieceColour colour)
        {
            var piece = new Piece(type, colour);

            Assert.AreEqual(type, piece.Type);
            Assert.AreEqual(colour, piece.Colour);
        }
        /// <summary>
        /// Checks if a given x and y position result in a valid move for a piece and if it is
        /// a standard or kill move. It will add it to the list of moves accordingly.
        /// </summary>
        /// <param name="moves"> List of moves to add potential move to </param>
        /// <param name="x"> X coordinate of the point to be evaluated </param>
        /// <param name="y"> Y coordinate of the point to be evaluated </param>
        /// <param name="colour"> The team that the piece is on </param>
        /// <param name="killOnly"> Whether or not only kill moves should be evaluated </param>
        /// <returns> Boolean, returns false if the are no further possible moves in
        /// this direction as it has been blocked. Returns true if search can
        /// continue</returns>
        private bool addMoveIfValid(List <PossibleMove> moves, Point pos, PieceColour colour, bool killOnly, bool nonKillOnly)
        {
            //Checking that the x and y points are within the limitations of the board
            //This is useful for knights, kings and other pieces that don't have unlimited
            //moving like rooks. Checking here will reduce the overall number of if statements
            if (pos.X < 0 || pos.X >= GlobalVars.GRID_SIZE || pos.Y < 0 || pos.Y >= GlobalVars.GRID_SIZE)
            {
                return(false);
            }

            Piece pieceAtOption = board[pos.X, pos.Y];

            if (pieceAtOption == null && !killOnly)
            {
                moves.Add(new PossibleMove(pos));
                return(true);
            }
            else if (pieceAtOption != null && colour != pieceAtOption.Colour && !nonKillOnly)
            {
                //Add a possible kill move
                moves.Add(new PossibleMove(pos, pieceAtOption));
            }
            //We have hit a piece, therefore no more moves will available in this
            //direction. Signal that no more moves should be made.
            return(false);
        }
Beispiel #11
0
 public GamePiece(PieceColour pieceColour, PieceRank pieceRank, int xCoord, int yCoord)
 {
     PieceColour = pieceColour;
     PieceRank   = pieceRank;
     Xcoord      = xCoord;
     Ycoord      = yCoord;
 }
Beispiel #12
0
 public ChessPiece(PieceType pieceType, PieceColour pieceColour, int file, int rank)
 {
     this.pieceType = pieceType;
     this.pieceColour = pieceColour;
     this.rank = rank;
     this.file = file;
 }
Beispiel #13
0
        private static void lineSetup(char lane, int position, PieceColour colour)
        {
            switch (lane)
            {
            case 'a':
            case 'h':
                board.Add(new Point(lane, position), new Piece(colour, PieceType.Rook));
                break;

            case 'b':
            case 'g':
                board.Add(new Point(lane, position), new Piece(colour, PieceType.Knight));
                break;

            case 'c':
            case 'f':
                board.Add(new Point(lane, position), new Piece(colour, PieceType.Bishop));
                break;

            case 'd':
                board.Add(new Point(lane, position), new Piece(colour, PieceType.Queen));
                break;

            case 'e':
                board.Add(new Point(lane, position), new Piece(colour, PieceType.King));
                break;

            default:
                break;
            }
        }
Beispiel #14
0
 public Player(Game game, PieceColour colour)
 {
     Name                = "Computer";
     _game               = game;
     Colour              = colour;
     IsComputerPlayer    = true;
     _selectMoveCallback = (moves, move) => move;
 }
Beispiel #15
0
 public Piece(PieceColour colour, Board board, int row, int column, Player player)
 {
     _board  = board;
     _row    = row;
     _column = column;
     Owner   = player;
     Colour  = colour;
 }
Beispiel #16
0
 public Piece(PieceType type, PieceColour colour, bool can_double_move = true, bool has_moved_before = false, bool just_double_moved = false)
 {
     MyPieceType     = type;
     MyPieceColour   = colour;
     CanDoubleMove   = can_double_move;
     HasMovedBefore  = has_moved_before;
     JustDoubleMoved = just_double_moved;
 }
Beispiel #17
0
        public MoveMap(Piece piece)
        {
            Square start = piece.Square;

            _board  = piece.Board;
            _colour = start.Occupier.Colour;
            _root   = new MoveMapNode(null, start);
            Generate();
        }
Beispiel #18
0
        /// <summary>
        /// extension: get all available moves for all the pieces of specific colour
        /// </summary>
        /// <param name="board"></param>
        /// <param name="playerColour"></param>
        /// <returns></returns>
        public static IEnumerable <AIMove> GetAllAvailableMoves(this Board board, PieceColour playerColour)
        {
            var opponentKingPos = board.AvailablePieces.First(x => x.Type == PieceType.King && x.Colour != playerColour).CurrentPosition;

            return(board.AvailablePieces.ToList().Shuffle().Where(x => x.Colour == playerColour)
                   .SelectMany(y => board.GetAvailableMoves(y)
                               .Select(z => new AIMove(y.CurrentPosition, z)))
                   .Where(x => x.NewPosition.Row != opponentKingPos.Row || x.NewPosition.Column != opponentKingPos.Column) //can't kill the king - only via checkmate
                   .AsParallel());
        }
Beispiel #19
0
        public Tuple <char, int, char, int> miniMax(Dictionary <Point, Piece> state, PieceColour startingPlayer)
        {
            gs.state         = state;
            gs.currentPlayer = startingPlayer;
            GenerateStates(this, 2, startingPlayer);
            //minimaxValue = GenerateStates(this, 0, isMaximizingPlayer, int.MinValue, int.MaxValue);
            var listOfMoves = children.FindAll(o => o.minimaxValue == minimaxValue);

            return(action);
        }
Beispiel #20
0
        public static bool CheckMove(PieceColour playerColour, Point startPoint, Point destination, bool?computerPawnPromotion = false)
        {
            if (!Board.board.ContainsKey(startPoint) ||
                !Board.board.ContainsKey(destination))
            {
                return(false);
            }


            Piece pieceToMove   = Board.board[startPoint];
            Piece pieceToMoveTo = Board.board[destination];

            skipForCastleCheck = false;

            if (((pieceToMove.type == PieceType.Rook && pieceToMoveTo.type == PieceType.King) ||
                 (pieceToMove.type == PieceType.King && pieceToMoveTo.type == PieceType.Rook)) &&
                pieceToMoveTo.colour == pieceToMove.colour)
            {
                skipForCastleCheck = true;
            }

            if (pieceToMove.colour != playerColour)
            {
                return(false);
            }

            if (pieceToMoveTo.colour == playerColour && !skipForCastleCheck)
            {
                return(false);
            }

            //Blue goes from 1 to 8, Red goes from 8 to 1
            switch (pieceToMove.type)
            {
            case PieceType.Pawn:
                return(PawnRuleset.rules(startPoint, destination, (playerColour == PieceColour.Blue) ? true : false, computerPawnPromotion.Value));

            case PieceType.Rook:
                return(RookRuleset.rules(startPoint, destination));

            case PieceType.Knight:
                return(KnightRuleset.rules(startPoint, destination));

            case PieceType.Bishop:
                return(BishopRuleset.rules(startPoint, destination));

            case PieceType.Queen:
                return(QueenRuleset.rules(startPoint, destination));

            case PieceType.King:
                return(KingRuleset.rules(startPoint, destination));
            }

            return(false);
        }
Beispiel #21
0
        public static bool KingCheckmate(PieceColour colour)
        {
            var ownPieces = Board.board.Where(o => o.Value.colour == colour).ToList();

            //var possibleMoves = Board.board.Where(o => o.Value.colour != colour);
            List <Point> possibleMoves = Board.board.Keys.ToList();

            foreach (var ownPieceKV in ownPieces)
            {
                foreach (var possiblePosition in possibleMoves)
                {
                    if (CheckMove(colour, ownPieceKV.Key, possiblePosition))
                    {
                        Piece pieceToMovePiece      = Board.board[ownPieceKV.Key];
                        Piece positionToMoveToPiece = Board.board[possiblePosition];

                        ExecuteMove(ownPieceKV.Key, possiblePosition);

                        if (!KingCheck(colour))
                        {
                            Reverse();

                            if (pieceToMoveFirstMove)
                            {
                                Board.board[ownPieceKV.Key].firstMove = true;
                            }

                            if (pieceToMoveToFirstMove)
                            {
                                Board.board[possiblePosition].firstMove = true;
                            }

                            return(false);
                        }
                        else
                        {
                            Reverse();

                            if (pieceToMoveFirstMove)
                            {
                                Board.board[ownPieceKV.Key].firstMove = true;
                            }

                            if (pieceToMoveToFirstMove)
                            {
                                Board.board[possiblePosition].firstMove = true;
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #22
0
        public Piece(Board board, int row, int column, PieceColour pieceColour)
        {
            Board = board;

            Row    = row;
            Column = column;

            PieceColour = pieceColour;

            Texture = TextureManager.GetTexture($"Content/Sprites/{pieceColour.ToString().ToLower()}-{GetType().Name.ToLower()}.png");
        }
Beispiel #23
0
 public ChessClock(PieceColour colour, TimeSpan span)
 {
     TimeLeft    = span;
     timer       = new Timer(1000);
     this.Colour = colour;
     second      = new TimeSpan(0, 0, 1);
     if (MainClass.win != null)
     {
         MainClass.win.UpdateClock(this);
     }
 }
Beispiel #24
0
        public Bishop(PieceColour colour, Position p)
        {
            this.colour   = colour;
            this.position = p;

            // Bishops move in diagonal vectors
            moves = new List <IMove>();
            moves.Add(new VectorMove(1, 1));
            moves.Add(new VectorMove(1, -1));
            moves.Add(new VectorMove(-1, 1));
            moves.Add(new VectorMove(-1, -1));
        }
Beispiel #25
0
        public bool IsCheckmated(PieceColour colour)
        {
            foreach (var piece in AvailablePieces.Where(x => x.Colour == colour))
            {
                if (GetAvailableMoves(piece).Any())
                {
                    return(false); //there are still available moves -> no checkmate
                }
            }

            return(true);
        }
Beispiel #26
0
        public bool InCheck(PieceColour playingColour)
        {
            foreach (GridLocation location in AttackedLocations(playingColour))
            {
                if (this[location].Colour == playingColour && this[location].Type == PieceType.King)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #27
0
        public Bishop(PieceColour colour, Position p)
        {
            this.colour = colour;
            this.position = p;

            // Bishops move in diagonal vectors
            moves = new List<IMove>();
            moves.Add(new VectorMove(1, 1));
            moves.Add(new VectorMove(1, -1));
            moves.Add(new VectorMove(-1, 1));
            moves.Add(new VectorMove(-1, -1));
        }
Beispiel #28
0
        }                                         // 0 for none, 1 for check, 2 for checkmate

        public Move(byte source, byte destination, PieceColour colour, Piece movingPiece,
                    MoveResult result, string fen, int checkOrCheckmate, SpecifierType specifierRequired = SpecifierType.None, PieceType?promoteTo = null)
        {
            Source            = source;
            Destination       = destination;
            Colour            = colour;
            MovingPiece       = movingPiece;
            SpecifierRequired = specifierRequired;
            PromoteTo         = promoteTo;
            Result            = result;
            FEN = fen;
            CheckOrCheckmate = checkOrCheckmate;
        }
Beispiel #29
0
        public static bool isGameOver(PieceColour colour)
        {
            PieceColour opposingColour = colour == PieceColour.Blue ? PieceColour.Red : PieceColour.Blue;

            if (KingCheckmate(opposingColour))
            {
                Console.WriteLine($"\n{opposingColour} is in checkmate, the game is over!");
                Console.WriteLine($"\n{colour} wins!");
                return(true);
            }

            return(false);
        }
Beispiel #30
0
        public Piece(string stringType, PieceColour pieceColour, Vector2 pos)
        {
            //Constants
            mPieceTexture = Content.Load<Texture2D>(stringType);
            Type = Helpers.GetPieceType(stringType);
            Colour = pieceColour;

            //Updated on move
            BoardTile = Helpers.TileToBoardCoord((int)pos.X,(int)pos.Y);
            Position = Helpers.TileToPixel((int) pos.X, (int) pos.Y);
            TilePosition = new TilePosition(){ X = (int)pos.Y,Y = (int)pos.X};
            CollisionRect = new Rectangle((int)Position.X, (int)Position.Y, 64, 64);
        }
Beispiel #31
0
        public MoveMap(Board board, int row, int column)
        {
            Square start = board[row, column];

            if (start.IsEmpty)
            {
                throw new ArgumentException("Starting square must be occupied.");
            }

            _root   = new MoveMapNode(null, start);
            _board  = board;
            _colour = start.Occupier.Colour;
            Evaluate();
        }
Beispiel #32
0
        private static void gameLoop()
        {
            while (true)
            {
                Board.boardState();

                if (playersTurn)
                {
                    Console.ForegroundColor = (isPlayerOneBlue) ? ConsoleColor.Blue : ConsoleColor.Red;
                    colour = isPlayerOneBlue ? PieceColour.Blue : PieceColour.Red;
                    Console.WriteLine("\nPlayer's turn...");

                    if (Logic.KingCheck(colour))
                    {
                        Console.WriteLine("\nPlayer is now in check.");
                    }

                    if (playerMove(colour))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    Console.ForegroundColor = (!isPlayerOneBlue) ? ConsoleColor.Blue : ConsoleColor.Red;
                    colour = !isPlayerOneBlue ? PieceColour.Blue : PieceColour.Red;
                    Console.WriteLine("\nComputer's turn...");

                    if (Logic.KingCheck(colour))
                    {
                        Console.WriteLine("\nComputer is now in check.");
                    }

                    Computer computer = new Computer();
                    computer.computerMove(colour);

                    playersTurn = !playersTurn;

                    if (Logic.isGameOver(colour))
                    {
                        break;
                    }
                }
            }
        }
Beispiel #33
0
        public void AddPiece(PieceColour colour, PieceType type, int position)
        {
            if (position >= 64)
            {
                throw new ArgumentOutOfRangeException("position",
                                                      "Position index for the chessboard must be less than 64.");
            }

            if (Squares [position].Piece != null)
            {
                throw new ArgumentException("That square is already occupied.", "position");
            }

            Squares[position].Piece = new Piece(colour, type);
        }
Beispiel #34
0
 public ToMoveData(PieceColour colour, Piece pawn, Piece knight, Piece bishop, Piece rook, Piece queen, Piece king, int pawnStartRank, int pawnPromRank, int pawnYDir,
     CastleFlags canCastleKS, CastleFlags canCastleQS, Square kingStartSq, Square kingRookSq, Square queenRookSq)
 {
     Colour = colour;
     Pawn = pawn;
     Knight = knight;
     Bishop = bishop;
     Rook = rook;
     Queen = queen;
     King = king;
     PawnStartRank = pawnStartRank;
     PawnPromRank = pawnPromRank;
     PawnYDir = pawnYDir;
     CanCastleKS = canCastleKS;
     CanCastleQS = canCastleQS;
     KingStartSq = kingStartSq;
     KingRookSq = kingRookSq;
     QueenRookSq = queenRookSq;
     KingKCastleSq = new Square(kingStartSq.File + 2, kingStartSq.Rank);
     KingQCastleSq = new Square(kingStartSq.File - 2, kingStartSq.Rank);
     RookKCastleSq = new Square(kingStartSq.File + 1, kingStartSq.Rank);
     RookQCastleSq = new Square(kingStartSq.File - 1, kingStartSq.Rank);
 }
Beispiel #35
0
        private Move MakeMove(int from, int to)
        {
            Move move = GetMove(from, to);

            // If move is valid, update the game info
            if (move.Valid)
            {
                // Remove piece from En-Passant capture
                if (move.EnPassantCapture)
                {
                    int diff = _activeColour == PieceColour.White ? -8 : 8;
                    _board[move.To + diff] = new Piece();
                }

                _enPassantTarget = move.EnPassantTarget;

                // TODO: Disable move if it results in check

                // TODO: Disable castling if it passes through check

                // TODO: Handle pawn promotion

                // Disable castling flags
                if ( _board[move.From].Type == PieceType.King )
                {
                    if (_activeColour == PieceColour.White)
                    {
                        _whiteKingside = false;
                        _whiteQueenside = false;
                    }
                    else
                    {
                        _blackKingside = false;
                        _blackQueenside = false;
                    }
                }
                else if (_board[move.From].Type == PieceType.Rook)
                {
                    if (_activeColour == PieceColour.White && move.From == 0)
                        _whiteQueenside = false;
                    else if (_activeColour == PieceColour.White && move.From == 7)
                        _whiteKingside = false;
                    else if (_activeColour == PieceColour.Black && move.From == 56)
                        _blackQueenside = false;
                    else if (_activeColour == PieceColour.Black && move.From == 63)
                        _blackKingside = false;
                }

                // Update player, clock, etc
                if (_activeColour == PieceColour.Black)
                {
                    _activeColour = PieceColour.White;
                    _fullMoveNumber++;
                }
                else
                {
                    _activeColour = PieceColour.Black;
                }
                // TODO: Correctly increment the halfmove clock
                //if (move.QuietMove)
                //{
                //    _halfMoveClock++;
                //}
                //else
                //{
                //    _halfMoveClock = 0;
                //}
                // Update the board
                _board[move.To] = _board[move.From];
                _board[move.From] = new Piece();

                // TODO: Add to move list
            }
            return move;
        }
Beispiel #36
0
 public Piece(PieceType type, PieceColour colour)
 {
     _store = (byte)((byte)type | (byte)colour);
 }
Beispiel #37
0
 public Piece(PieceType pieceType, PieceColour colour)
 {
     this.pieceType = pieceType;
     this.pieceColour = colour;
 }
Beispiel #38
0
        /// <summary>
        /// Construct from Forsyth–Edwards Notation (FEN), 
        /// http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
        /// </summary>
        /// <param name="fen"></param>
        public Board(string fen)
        {
            var parts = fen.Split(new[] { ' ' }, 6);
            if (parts.Length != 6)
            {
                throw new ArgumentException("fen is in an incorrect format. It does not have 6 parts.");
            }

            var ranks = parts[0].Split(new[] { '/' });
            if (ranks.Length != 8)
            {
                throw new ArgumentException("fen is in an incorrect format. The first part does not have 8 ranks.");
            }

            // Setup the board
            InitializeBlankBoard();
            int i = 0;
            // FEN starts with rank 8 and ends with rank 1
            for (int r = 7; r >= 0; r--)
            {
                foreach (char p in ranks[r])
                {
                    if (char.IsDigit(p))
                    {
                        // Blank squares to skip
                        int skip = p - '0';
                        if (skip > 8)
                        {
                            throw new ArgumentException("fen is in an incorrect format.");
                        }
                        i += skip;
                    }
                    else
                    {
                        if (i > 63)
                        {
                            throw new ArgumentException("fen is in an incorrect format.");
                        }
                        _board[i++] = new Piece(p);
                    }
                }
            }

            // Active Colour
            _activeColour = parts[1].ToLowerInvariant() == "w" ? PieceColour.White : PieceColour.Black;

            // Castling availability
            _whiteKingside = false;
            _whiteQueenside = false;
            _blackKingside = false;
            _blackQueenside = false;
            foreach (char c in parts[2])
            {
                switch (c)
                {
                    case 'K':
                        _whiteKingside = true;
                        break;
                    case 'Q':
                        _whiteQueenside = true;
                        break;
                    case 'k':
                        _blackKingside = true;
                        break;
                    case 'q':
                        _blackQueenside = true;
                        break;
                }
            }

            // En passant target square
            _enPassantTarget = IndexFromSquare(parts[3]);

            // Halfmove clock
            if (!Int32.TryParse(parts[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out _halfMoveClock))
            {
                throw new ArgumentException("fen is in an incorrect format. Halfmove clock is not an int.");
            }

            // Fullmove number
            if (!Int32.TryParse(parts[5], NumberStyles.Integer, CultureInfo.InvariantCulture, out _fullMoveNumber))
            {
                throw new ArgumentException("fen is in an incorrect format. Fullmove number is not an int.");
            }
        }
Beispiel #39
0
 private static void TestPieceType( PieceType type, PieceColour colour )
 {
     var piece = new Piece( type, colour );
      Assert.AreEqual( type, piece.Type );
      Assert.AreEqual( colour, piece.Colour );
 }