public void SendInitializeCommonPiece(BoardPosition position, PieceColor color)
 {
     foreach (var subscriber in this._subscribers)
     {
         subscriber.InitializeCommonPiece(position, color);
     }
 }
        // returns all the available moves for a given color
        public List<MoveResult> GetAllAvailableMoves(PieceColor color)
        {
            var availables = new List<MoveResult>();
            var listToCheck = color == PieceColor.Black ? Pieces.AlivePlayerOnePieces : Pieces.AlivePlayerTwoPieces;

            bool anyJumps;
            //for every living piece of said color
            for (var i = 0; i < listToCheck.Count; i++)
            {
                var piece = listToCheck[i];
                anyJumps = false;
                for (var j = 0; j < availables.Count; j++)
                {
                    //if any current available moves are a jump, then all future moves are invalid unless they are a jump - force only jump moves
                    var m = availables[j];
                    if (m.Type == MoveType.Jump) //if the
                    {
                        anyJumps = true;
                        break;
                    }
                }

                //append the available moves onto the list
                availables.AddRange(GetAvailableMovesForPiece(piece, anyJumps));
            }

            // if there are any jumps, you must take a jump
            if(availables.Any(m => m.Type == MoveType.Jump))
               availables.RemoveAll(m => m.Type != MoveType.Jump);

            return availables;
        }
Exemple #3
0
        private void CheckForCapture(char leftX, char rightX, char y, PieceColor color)
        {
            if (this.Board.IsOccupiedSquare(leftX, y, color))
            {
                this.AddValidMove(leftX, y, true);
            }

            if (this.Board.IsOccupiedSquare(rightX, y, color))
            {
                this.AddValidMove(rightX, y, true);
            }

            // En Passant
            if (this.Board.EnPassantSquare != null)
            {
                if (this.Board.EnPassantSquare.X == leftX && this.Board.EnPassantSquare.Y == y)
                {
                    this.AddValidMove(leftX, y, true, this.Board[leftX, this.Square.Y].Piece);
                }

                if (this.Board.EnPassantSquare.X == rightX && this.Board.EnPassantSquare.Y == y)
                {
                    this.AddValidMove(rightX, y, true, this.Board[rightX, this.Square.Y].Piece);
                }
            }
        }
Exemple #4
0
        public Move(PieceColor color, BoardPosition initialPosition, BoardPosition endingPosition, bool pieceJumped = false, bool pieceCaptured = false)
        {
            if (initialPosition.ContainsPiece())
            {
                throw new ArgumentException("Move initial posiiton must not contain a piece");
            }

            if (endingPosition.ContainsPiece())
            {
                throw new ArgumentException("Move ending posiiton must not contain a piece");
            }

            if (pieceCaptured && !pieceJumped)
            {
                throw new ArgumentException("Capture moves are required to be configured as a jump move");
            }

            if (!ValidateMove(initialPosition, endingPosition, pieceJumped, pieceCaptured))
            {
                throw new ArgumentException("Invalid move requested");
            }

            this.PieceColor = color;
            this.PieceJumped = pieceJumped;
            this.PieceCaptured = pieceCaptured;
            this.InitialPosition = initialPosition;
            this.EndingPosition = endingPosition;
        }
Exemple #5
0
        public Piece(PieceType type, PieceColor color, int col, int row, Board board)
        {
            this.Col = col;
            this.Row = row;
            this.X = col * Game.TILESIZE;
            this.Y =  row * Game.TILESIZE;
            this.Color = color;
            this.Board = board;
            FirstMove = true;
            SetType(type);

            this.MouseDown += delegate(object s, MouseButtonEventArgs ev) {
                if (!Game.GameOver && ((!Game.IsConnected && Game.MyTurn(Color)) ||
                    (Game.IsConnected && Game.MainColor == Color && Game.MyTurn())))
                {
                    dragging = true;
                    this.Cursor = Cursors.Hand;
                    System.Windows.Controls.Canvas.SetZIndex(this, 1000);
                }
            };

            this.MouseUp += new MouseButtonEventHandler(image_MouseUp);

            this.MouseMove += new MouseEventHandler(image_MouseMove);

            this.MouseLeave += new MouseEventHandler(image_MouseMove);
        }
 private void AssertPieceLoaded(IEngine engine, string coord, Type type, PieceColor color)
 {
     var piece = engine.Board[coord].Piece;
     Assert.IsNotNull(piece);
     Assert.AreEqual(color, piece.Color);
     Assert.IsInstanceOfType(piece, type);
 }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the Pawn class.
        /// </summary>
        /// <param name="color">Color, white or black, the piece represents.</param>
        public Pawn(PieceColor color)
        {
            m_iterator = new BoardIterator(null, Square.None, Direction.NoDirection);

              if (color == PieceColor.White)
              {
            m_color = PieceColor.White;
            m_opponentColor = PieceColor.Black;

            m_directions[0] = Direction.Up;
            m_directions[1] = Direction.UpLeft;
            m_directions[2] = Direction.UpRight;

            moveAgainRow = 2;
              }

              if (color == PieceColor.Black)
              {
            m_color = PieceColor.Black;
            m_opponentColor = PieceColor.White;

            m_directions[0] = Direction.Down;
            m_directions[1] = Direction.DownLeft;
            m_directions[2] = Direction.DownRight;

            moveAgainRow = 5;
              }
        }
        private static Lines GetConsecutiveLines(Connect4Board b, PieceColor color, int col, Connect4Column move)
        {
            int horizontal = 1, vertical = 1, mainDiagonal = 1, antiDiagonal = 1;
            int nextX, nextY;

            for (nextX = col + 1, nextY = move.LastDropRow; nextX < Connect4Board.COLUMNS && b.GetPiece(nextY, nextX) == color; nextX++)
                horizontal++;
            for (nextX = col - 1; nextX >= 0 && b.GetPiece(nextY, nextX) == color; nextX--)
                horizontal++;

            for (nextX = col, nextY = move.LastDropRow + 1; nextY < Connect4Board.ROWS && b.GetPiece(nextY, nextX) == color; nextY++)
                vertical++;
            for (nextX = col, nextY = move.LastDropRow - 1; nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextY--)
                vertical++;

            for (nextX = col + 1, nextY = move.LastDropRow + 1; nextX < Connect4Board.COLUMNS && nextY < Connect4Board.ROWS && b.GetPiece(nextY, nextX) == color; nextX++, nextY++)
                mainDiagonal++;
            for (nextX = col - 1, nextY = move.LastDropRow - 1; nextX >= 0 && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX--, nextY--)
                mainDiagonal++;

            for (nextX = col + 1, nextY = move.LastDropRow - 1; nextX < Connect4Board.COLUMNS && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX++, nextY--)
                antiDiagonal++;
            for (nextX = col - 1, nextY = move.LastDropRow + 1; nextX >= 0 && nextY < Connect4Board.ROWS && b.GetPiece(nextY, nextX) == color; nextX--, nextY++)
                antiDiagonal++;

            return new Lines(horizontal, vertical, mainDiagonal, antiDiagonal);
        }
        public double Eval(CheckersBoard board, int level, PieceColor playerColor)
        {
            {
                double eval = 0;

                for (int x = 0; x < board.Width; x++)
                    for (int y = 0; y < board.Height; y++)
                    {
                        var piece = board.GetPieceAt(x, y) as CheckersPiece;
                        if (piece != null)
                        {
                            if (piece.Color == playerColor)
                            {
                                if (piece is Pawn) eval += _ownPawnStrength;
                                else if (piece is Queen) eval += _ownQueenStrength;
                            }
                            else
                            {
                                if (piece is Pawn) eval -= _ownPawnStrength;
                                else if (piece is Queen) eval -= _ownQueenStrength;
                            }
                        }
                    }

                return eval;
            }
        }
Exemple #10
0
 public Board(Board b)
 {
     this.WhiteBitBoard = b.WhiteBitBoard;
     this.BlackBitBoard = b.BlackBitBoard;
     this.CurrentPlayer = b.CurrentPlayer;
     this.Evaluation = b.Evaluation;
 }
 public ChessPieceViewModel(ChessPiece i_ChessPiece, PieceColor i_PieceColor, PieceSide i_PieceSide, int i_File, int i_Rank)
 {
     ChessCoord tempChessCoord = new ChessCoord();
     tempChessCoord.File = i_File;
     tempChessCoord.Rank = i_Rank;
     m_ChessPieceModel = new ChessPieceModel(i_ChessPiece, i_PieceColor, i_PieceSide, tempChessCoord);
 }
        private static Lines GetConsecutiveLines(OmokBoard b, PieceColor color, Point move)
        {
            int horizontal = 1, vertical = 1, mainDiagonal = 1, antiDiagonal = 1;
            int nextX, nextY;

            for (nextX = move.X + 1, nextY = move.Y; nextX < OmokBoard.COLUMNS && b.GetPiece(nextY, nextX) == color; nextX++)
                horizontal++;
            for (nextX = move.X - 1; nextX >= 0 && b.GetPiece(nextY, nextX) == color; nextX--)
                horizontal++;

            for (nextX = move.X, nextY = move.Y + 1; nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextY++)
                vertical++;
            for (nextX = move.X, nextY = move.Y - 1; nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextY--)
                vertical++;

            for (nextX = move.X + 1, nextY = move.Y + 1; nextX < OmokBoard.COLUMNS && nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextX++, nextY++)
                mainDiagonal++;
            for (nextX = move.X - 1, nextY = move.Y - 1; nextX >= 0 && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX--, nextY--)
                mainDiagonal++;

            for (nextX = move.X + 1, nextY = move.Y - 1; nextX < OmokBoard.COLUMNS && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX++, nextY--)
                antiDiagonal++;
            for (nextX = move.X - 1, nextY = move.Y + 1; nextX >= 0 && nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextX--, nextY++)
                antiDiagonal++;

            return new Lines(horizontal, vertical, mainDiagonal, antiDiagonal);
        }
Exemple #13
0
        /// <summary>
        /// Instantiate <see cref="Piece"/>
        /// </summary>
        /// <param name="type"><see cref="Type"/></param>
        /// <param name="color"><see cref="Color"/></param>
        public Piece(PieceType type, PieceColor color)
        {
            _type = type;
            _color = color;

            Moves = new List<Move>();
            Attacked = new List<Square>();
        }
Exemple #14
0
        public Piece(Square position, Board board, PieceColor color)
        {
            this.position = position;
            this.board = board;
            this.color = color;

            this.board.Squares[position] = this;
        }
Exemple #15
0
        public void Whether_Rook_CantJumpOverAnotherPiece_On_CanMoveTo(PieceColor pieceColor)
        {
            var board = new Board();
            var rook = new Rook(new Square(4, 4), board, PieceColor.White);
            var knight = new Knight(new Square(4, 5), board, pieceColor);

            Assert.That(rook.CanMoveTo(new Square(4, 6)), Is.False);
        }
Exemple #16
0
 public Piece(bool belongsToPlayerTwo, Point position, PieceColor color, int sumoness)
 {
     BelongsToPlayerTwo = belongsToPlayerTwo;
     Position = position;
     Color = color;
     MaxMoveLength = 7 - 2 * sumoness;
     Sumoness = sumoness;
 }
Exemple #17
0
 public FixedDepthPlayer(PieceColor c, int depth)
     : base(c)
 {
     if (depth >= 0)
         maxDepth = depth;
     else
         throw new ArgumentException("Depth must be at least 0");
 }
Exemple #18
0
 public FixedTimePlayer(PieceColor c, int thinkTimeSeconds)
     : base(c)
 {
     if (thinkTimeSeconds > 0)
         this.thinkTimeSeconds = thinkTimeSeconds;
     else
         throw new ArgumentException("Think time must be greater than 0");
 }
Exemple #19
0
        public void Whether_Queen_CantJumpOverAnotherPiece_On_CanMoveTo(PieceColor pieceColor)
        {
            var board = new Board();
            var queen = new Queen(new Square(4, 4), board, PieceColor.White);
            var knight = new Knight(new Square(5, 5), board, pieceColor);

            Assert.That(queen.CanMoveTo(new Square(6, 6)), Is.False);
        }
Exemple #20
0
        public PgnMove(string pgnString)
        {
            Match m = r.Match(pgnString);

              if (m.Groups["Move"].Value == "")
              {
            ColorToPlay = PieceColor.Black;
              }
              else
              {
            ColorToPlay = PieceColor.White;
              }

              if (m.Groups["Castling"].Value == "")
              {
            PieceToPlay = StringToPiece(m.Groups["Piece"].Value, ColorToPlay);
            FromFile = StringToFile(m.Groups["File"].Value);
            FromRank = StringToRank(m.Groups["Rank"].Value);
            DestinationSquare = StringToSquare(m.Groups["Destination"].Value);
            PromotionPiece = StringToPromotion(m.Groups["Promotion"].Value);
              }
              else if (m.Groups["Castling"].Value == "O-O")
              {
            if (ColorToPlay == PieceColor.White)
            {
              DestinationSquare = Square.G1;
              PieceToPlay = Piece.WhiteKing;
              FromFile = 4;
              FromRank = 0;
            }

            if (ColorToPlay == PieceColor.Black)
            {
              DestinationSquare = Square.G8;
              PieceToPlay = Piece.BlackKing;
              FromFile = 4;
              FromRank = 7;
            }
              }
              else if (m.Groups["Castling"].Value == "O-O-O")
              {
            if (ColorToPlay == PieceColor.White)
            {
              DestinationSquare = Square.C1;
              PieceToPlay = Piece.WhiteKing;
              FromFile = 4;
              FromRank = 0;
            }

            if (ColorToPlay == PieceColor.Black)
            {
              DestinationSquare = Square.C8;
              PieceToPlay = Piece.BlackKing;
              FromFile = 4;
              FromRank = 7;
            }
              }
        }
        public QueenPiece(PieceColor color, BoardPosition boardPosition)
        {
            this._color = color;
            this._boardPosition = boardPosition;
            this._blackImage = Image.FromFile(@"E:\Projetos\C#\ucs-xna-rmi-draughts\UCS.XNA.Draughts\UCS.Forms.Draughts\Resources\BlackQueen.png");
            this._whiteImage = Image.FromFile(@"E:\Projetos\C#\ucs-xna-rmi-draughts\UCS.XNA.Draughts\UCS.Forms.Draughts\Resources\WhiteQueen.png");

            this.InitializeValidMovementsList();
        }
Exemple #22
0
 public void CalculateValidMoves(PieceColor playerColor)
 {
     // TODO: Parallel.ForEach<PieceBase>(this.Pieces, p => p.CalculateValidMoves());
     foreach (PieceBase piece in this.Pieces)
     {
         if (piece.Color == playerColor)
             piece.CalculateValidMoves();
     }
 }
Exemple #23
0
 public void Start(Position startingPosition, PieceColor playerToMove)
 {
     State = GameState.Normal;
     PlayerToMove = playerToMove;
     UpdateGameState(new Square(0, 0, new NullPiece(null)),
                     new Square(0, 0, new NullPiece(null)),
                     startingPosition,
                     PlayerToMove.GetOppositeColor());
 }
Exemple #24
0
 public Piece( PieceType type, PieceColor color )
 {
     if (type == PieceType.None)
         throw new ArgumentException("Type must be specified");
     if (color == PieceColor.None)
         throw new ArgumentException("Color must be specified");
     _type = type;
     _color = color;
 }
Exemple #25
0
 public void Add(Pawn pawn, int xCoordinate, int yCoordinate, PieceColor pieceColor)
 {
     if (IsLegalBoardPosition(xCoordinate, yCoordinate))
     {
         pawn.XCoordinate = xCoordinate;
         pawn.YCoordinate = yCoordinate;
         pieces[xCoordinate, yCoordinate] = pawn;
     }
 }
        public double Eval(CheckersBoard board, int level, PieceColor playerColor)
        {
            {
                double myval = 0;
                double enemyval = 0;
                for (int x = 0; x < board.Width; x++)
                    for (int y = 0; y < board.Height; y++)
                    {
                        CheckersPiece piece = board.GetPieceAt(x, y) as CheckersPiece;
                        if (piece != null)
                        {
                            int factor = (piece.Color == PieceColor.White) ? (7 - y) : (y);
                            if (piece.Color == playerColor)
                            {
                                if (piece is Pawn) myval += 100 + (factor * factor);
                                else
                                {

                                    myval += 200;
                                    if (y == 0)
                                    {
                                        if (x == 0) myval -= 40;
                                        else myval -= 20;
                                    }
                                    else if (y == 7)
                                    {
                                        if (x == 7) myval -= 40;
                                        else myval -= 20;
                                    }
                                }
                            }
                            else
                            {
                                if (piece is Pawn) enemyval += 100 + (factor * factor);
                                else
                                {
                                    enemyval += 200;
                                    if (y == 0)
                                    {
                                        if (x == 0) enemyval -= 40;
                                        else enemyval -= 20;
                                    }
                                    else if (y == 7)
                                    {
                                        if (x == 7) enemyval -= 40;
                                        else enemyval -= 20;
                                    }
                                }
                            }
                        }
                    }

                if (enemyval == 0) return 100000 + level * level;
                else if (myval == 0) return -100000 - level * level;
                return (myval - enemyval);
            }
        }
Exemple #27
0
 // Apply a full move to the board
 // This swaps CurrentPlayer
 public bool ApplyMove(int xCoord, int yCoord, PieceColor color, Rotation r)
 {
     bool placed = this.PlacePieceAt(xCoord, yCoord, color);
     if (placed)
     {
         this.DoRotation(r);
         this.CurrentPlayer = (color == PieceColor.White) ? PieceColor.Black : PieceColor.White;
     }
     return placed;
 }
Exemple #28
0
    /// <summary>
    /// Gets a player's piece by its color.
    /// </summary>
    public Piece GetPieceByColor( PieceColor color )
    {
        //Find piece
        foreach ( Piece p in pieces )
            if ( p.color == color )
                return p;

        //Return first piece if the proper piece could not be found
        return pieces [ 0 ];
    }
Exemple #29
0
        public GameState(Player player)
        {
            _player = player;
            if (_player != null)
            {
                _myColor = _player.Index == 0 ? PieceColor.Black : PieceColor.White;
            }

            _depGameBoard = new Dependent(UpdateGameBoard);
        }
Exemple #30
0
 // change piece's color
 public void ChangeColor()
 {
     if (color == PieceColor.White) {
         color = PieceColor.Black;
         transform.renderer.material.color = new Color(0.412F, 0.412F, 0.412F, 1F);
     } else if (color == PieceColor.Black){
         color = PieceColor.White;
         transform.renderer.material.color = new Color(1.0F, 1.0F, 1.0F, 1.0F);
     }
 }
Exemple #31
0
    public void ChangeColor(object c)
    {
        PieceColor color = (PieceColor)c;

        ChangeColor(color);
    }
Exemple #32
0
 public Centaur(PieceColor color, Position position) :
     base(color, PieceType.Centaur, position)
 {
 }
        public void FindAndMoveKnightWithAmbiguousMove(string knightCoords, string knightCoords2, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(knightCoords, new Knight(currentPlayer));
            board.AddPiece(knightCoords2, new Knight(currentPlayer));
            board.AddPiece("b4", new Rook(PieceColor.White));

            //Act
            Piece knight = board.PlayMove(moveAN, currentPlayer);

            //Assert
            Assert.Equal(knight, board.CellAt("b4").Piece);
        }
        public void FindAndMoveKnightWithNoObstacles(string knightCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(knightCoords, new Knight(currentPlayer));

            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            var knight = board.PlayMove(moveAN, currentPlayer);

            //Assert
            Assert.Equal(knight, board.CellAt(move.Coordinate).Piece);
            Assert.IsType <Knight>(knight);
            Assert.Null(board.CellAt("d5").Piece);
        }
Exemple #35
0
 /// <inheritdoc/>
 public Queen(int x, int y, PieceColor color)
     : base(x, y, color, 9, Piece.Queen)
 {
 }
 public Queen(PieceColor color, IMovable bishop, IMovable rook) : base(color)
 {
     this.Bishop = bishop;
     this.Rook   = rook;
 }
Exemple #37
0
 public Marshall(PieceColor pieceColor, Point position) : base(pieceColor, position)
 {
     Image = Image.FromFile(pieceColor == PieceColor.White ?
                            @"Assets/ChessPieces/WhiteMarshall.png" :
                            @"Assets/ChessPieces/BlackMarshall.png");
 }
Exemple #38
0
 public Rook(PieceColor color, Position position, ImmutableList <Move> moveHistory)
     : base(PieceType.Rook, color, position, moveHistory)
 {
 }
Exemple #39
0
 public Bishop(PieceColor color)
 {
     Name   = "Bishop";
     Symbol = 'B';
     Color  = color;
 }
Exemple #40
0
 /// <summary>
 /// Small helper to get the mangled key for an image
 /// </summary>
 /// <param name="job"></param>
 /// <param name="color"></param>
 /// <returns></returns>
 private static string GetPieceImageKey(PieceClass job, PieceColor color)
 {
     return(String.Concat(job.ToString(), color.ToString()));
 }
 public void Add(Pawn pawn, int xCoordinate, int yCoordinate, PieceColor pieceColor)
 {
     throw new NotImplementedException("Need to implement ChessBoard.Add()");
 }
Exemple #42
0
 protected Piece(PieceColor color)
 {
     Color = color;
 }
Exemple #43
0
        public void TryParseMove_ParsesPromotion(string input, string expectedStart, string expectedEnd, PieceColor color, SquareContents piece)
        {
            var endSq      = MoveParser.ParseSquare(expectedEnd);
            var startSq    = MoveParser.ParseSquare(expectedStart);
            var pieceColor = color == PieceColor.White ? SquareContents.White : SquareContents.Black;
            var board      = BoardState.Empty.SetPiece(startSq, SquareContents.Pawn | pieceColor);

            var game           = new Game(board, color);
            var result         = game.Move(input);
            var expectedSquare = game.GetSquareContents(endSq.File, endSq.Rank);

            Assert.That(result, Is.EqualTo(ErrorCondition.None));
            Assert.That(expectedSquare, Is.EqualTo(piece));
        }
Exemple #44
0
 public override void ToString_GivenPieceBase_ShouldReturn(string position, PieceColor pieceColor, char symbol) => this.ToString(CreatePawn(position, pieceColor), position, symbol);
 public Queen(PieceColor color) : base(color)
 {
     this.Type = ChessPieceType.Queen;
 }
Exemple #46
0
 public Pawn(PieceColor pieceColor) : base(pieceColor, PieceType.Pawn)
 {
 }
Exemple #47
0
 public Queen(Square position, PieceColor color)
 {
     Square  = position;
     IsAlive = true;
     Color   = color;
 }
Exemple #48
0
 public Pawn(int position, PieceColor color) : base(position, color)
 {
     Value = PieceValue.Pawn;
 }
Exemple #49
0
        // direction:                             14, 12, 32, 36, 74, 78, 98, 96  ;

        public KnightPiece(int _row, int _column, PieceColor _color, Game _owner)
            : base(_row, _column, _color, PieceType.Knight, _owner)
        {
            CanJump   = true;
            MoveRange = 1;
        }
Exemple #50
0
 public Spider(PieceColor color, int number) : base(color, number)
 {
 }
Exemple #51
0
 public Pawn(PieceColor color, ChessBoard board)
     : base(color, board)
 {
     MoveStrategy = new PawnAdapterStrategy(MoveCount, Direction, board);
 }
Exemple #52
0
        public Chessboard(string FEN)
        {
            PieceBoard = new Piece[8, 8];

            string[] data   = FEN.Split(' ');
            string[] pieces = data[0].Split('/');

            int row = 0;
            int col = 0;

            for (int i = 0; i < pieces.Length; i++)
            {
                for (int j = 0; j < pieces[i].Length; j++)
                {
                    if (Char.IsDigit(pieces[i][j]))
                    {
                        for (int k = 0; k < int.Parse(pieces[i][j].ToString()); k++)
                        {
                            PieceBoard[col, row] = new Empty(new Point(col, row), this, PieceColor.none);
                            col++;
                        }
                    }
                    else
                    {
                        PieceColor color = char.IsUpper(pieces[i][j]) ? PieceColor.white : PieceColor.black;

                        if (char.ToLower(pieces[i][j]) == 'r')
                        {
                            PieceBoard[col, row] = new Rook(new Point(col, row), this, color);
                        }
                        else if (char.ToLower(pieces[i][j]) == 'n')
                        {
                            PieceBoard[col, row] = new Knight(new Point(col, row), this, color);
                        }
                        else if (char.ToLower(pieces[i][j]) == 'b')
                        {
                            PieceBoard[col, row] = new Bishop(new Point(col, row), this, color);
                        }
                        else if (char.ToLower(pieces[i][j]) == 'q')
                        {
                            PieceBoard[col, row] = new Queen(new Point(col, row), this, color);
                        }
                        else if (char.ToLower(pieces[i][j]) == 'k')
                        {
                            PieceBoard[col, row] = new King(new Point(col, row), this, color);
                        }
                        else if (char.ToLower(pieces[i][j]) == 'p')
                        {
                            PieceBoard[col, row] = new Pawn(new Point(col, row), this, color);
                        }

                        col++;
                    }
                }
                col = 0;
                row++;
            }

            WhiteOnMove = (data[1][0] == 'w') ? true : false;

            foreach (char c in data[2])
            {
                if (c == 'K')
                {
                    WhiteCastlingShort = true;
                }
                else if (c == 'Q')
                {
                    WhiteCastlingLong = true;
                }
                else if (c == 'k')
                {
                    BlackCastlingShort = true;
                }
                else if (c == 'q')
                {
                    BlackCastlingLong = true;
                }
            }
        }
        public void FindAndMoveKnightWithObstaclesShouldThrowError(string knightCoords, string obstacleCoords, string moveAN, PieceColor currentPlayer)
        {
            //Arange
            var board = new Board(false);

            board.AddPiece(knightCoords, new Knight(currentPlayer));
            board.AddPiece(obstacleCoords, new Bishop(currentPlayer));

            //Act
            var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer);

            //Assert
            Action exception = () => board.FindPieceWhoNeedsToBeMoved(moveAN, currentPlayer);

            Assert.Throws <InvalidOperationException>(exception);
        }
Exemple #54
0
 public override void ImplicitOperatorChar_GivenPieceColor_ShouldReturn(PieceColor pieceColor, char expected) => this.ImplicitOperatorChar(CreatePawn("a2", pieceColor), expected);
Exemple #55
0
 public bool IsEnemyPiece(PieceColor currentPlayer)
 {
     return(GetPieceColor() != currentPlayer);
 }
Exemple #56
0
 public override void ImplicitOperatorPiece_GivenPieceColor_ShouldReturn(PieceColor pieceColor, char symbol) => this.ImplicitOperatorPiece(CreatePawn("a2", pieceColor), symbol);
Exemple #57
0
 public HumanEngine(PieceColor color)
 {
     Color = color;
 }
Exemple #58
0
 public void ChangeColor(PieceColor c, float time)
 {
     new DelayCall().Init(time, c, ChangeColor);
 }
Exemple #59
0
 public Pawn(Point position, Chessboard board, PieceColor color) : base(position, board, color)
 {
     Letter = '\0';
 }
 public PieceBuilder As(PieceColor color)
 {
     this.color = color;
     return(this);
 }