示例#1
0
        private ErrorCondition Move(Move move)
        {
            if (!BitTranslator.IsValidSquare(move.StartFile, move.StartRank))
            {
                return(ErrorCondition.InvalidSquare);
            }
            if (!BitTranslator.IsValidSquare(move.EndFile, move.EndRank))
            {
                return(ErrorCondition.InvalidSquare);
            }

            ulong startSquare = BitTranslator.TranslateToBit(move.StartFile, move.StartRank);

            if ((CurrentTurn & startSquare) == 0)
            {
                return(ErrorCondition.MustMoveOwnPiece); // Can't move if not your turn
            }
            ulong endSquare = BitTranslator.TranslateToBit(move.EndFile, move.EndRank);

            if ((CurrentTurn & endSquare) != 0)
            {
                return(ErrorCondition.CantTakeOwnPiece); // Can't end move on own piece
            }
            ulong allMoves = MoveGenerator.GenerateValidMovesForPiece(CurrentState, startSquare);

            if ((endSquare & allMoves) == 0)
            {
                return(ErrorCondition.InvalidMovement); // End square is not a valid move
            }
            // The move is good, so update state
            // Update current state
            UpdateState(move, startSquare, endSquare);

            return(ErrorCondition.None);
        }
示例#2
0
        public SquareContents GetSquareContents(char file, int rank)
        {
            var result = (SquareContents)0;

            if (BitTranslator.IsValidSquare(file, rank))
            {
                ulong bit = BitTranslator.TranslateToBit(file, rank);
                result = CurrentState.Board.GetSquareContents(bit);
            }

            return(result);
        }
示例#3
0
        public List <Square> GetValidMoves(char file, int rank)
        {
            if (!BitTranslator.IsValidSquare(file, rank))
            {
                throw new InvalidOperationException();
            }

            var   square   = BitTranslator.TranslateToBit(file, rank);
            ulong allMoves = MoveGenerator.GenerateValidMovesForPiece(CurrentState, square);

            return(BitTranslator.TranslateToSquares(allMoves));
        }