Exemplo n.º 1
0
 public void CoordinateToIndexTest_87()
 {
     Board target = new Board();
     Point point = new Point(8, 7);  // (8,7) should be the 65th (Index: 64) which is outside list range therefore an exception is expected (using default board width/height of 8)
     int actual;
     actual = target.CoordinateToIndex(point);
 }
Exemplo n.º 2
0
 public void CoordinateToIndexTest_12()
 {
     Board target = new Board();
     Point point = new Point(1, 2);
     int expected = 17; // (1,2) should be the 18th (Index: 17) element in the list (using default board width/height of 8)
     int actual;
     actual = target.CoordinateToIndex(point);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the ValidMoves property of this piece
        /// </summary>
        /// <param name="board">Game board</param>
        public override void UpdateValidMoveList(Board board)
        {
            List<Point> possibleMoves = GetMoveList(board);

            foreach (Point position in possibleMoves)
            {
                if (!board.InBounds(position))
                    possibleMoves.Remove(position);

            }

            this.ValidMoves = possibleMoves;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Puts a standard set of pieces on the board
        /// </summary>
        /// <param name="board">Game board</param>
        public static void InitPieces(Board board)
        {
            List<Tile> tiles = new List<Tile>();

            for (int i = 0; i < board.Width; i++)
            {
                board.AddPiece(MakePawn(new Point(i, 1), Side.Dark), new Point(i, 1));
            }
            for (int i = 0; i < board.Width; i++)
            {
                board.AddPiece(MakePawn(new Point(i, 6), Side.Light), new Point(i, 6));
            }

            //Kings
            board.AddPiece(MakeKing(new Point(4, 0), Side.Dark), new Point(4, 0));
            board.AddPiece(MakeKing(new Point(4, 7), Side.Light), new Point(4, 7));

            //Queens
            board.AddPiece(MakeQueen(new Point(3, 0), Side.Dark), new Point(3, 0));
            board.AddPiece(MakeQueen(new Point(3, 7), Side.Light), new Point(3, 7));

            //Bishops
            board.AddPiece(MakeBishop(new Point(2, 0), Side.Dark), new Point(2, 0));
            board.AddPiece(MakeBishop(new Point(5, 0), Side.Dark), new Point(5, 0));

            board.AddPiece(MakeBishop(new Point(2, 7), Side.Light), new Point(2, 7));
            board.AddPiece(MakeBishop(new Point(5, 7), Side.Light), new Point(5, 7));

            //Knights
            board.AddPiece(MakeKnight(new Point(1, 0), Side.Dark), new Point(1, 0));
            board.AddPiece(MakeKnight(new Point(6, 0), Side.Dark), new Point(6, 0));

            board.AddPiece(MakeKnight(new Point(1, 7), Side.Light), new Point(1, 7));
            board.AddPiece(MakeKnight(new Point(6, 7), Side.Light), new Point(6, 7));

            //Rook
            board.AddPiece(MakeRook(new Point(0, 0), Side.Dark), new Point(0, 0));
            board.AddPiece(MakeRook(new Point(7, 0), Side.Dark), new Point(7, 0));

            board.AddPiece(MakeRook(new Point(0, 7), Side.Light), new Point(0, 7));
            board.AddPiece(MakeRook(new Point(7, 7), Side.Light), new Point(7, 7));

            board.UpdatePieces();
        }
Exemplo n.º 5
0
        public void ValidMovesTest_false00()
        {
            Piece target = PieceBuilder.MakeKnight(new Point(0, 0), Side.Dark);
            Board board = new Board();
            target.UpdateValidMoveList(board);

            List<Point> expected = new List<Point>() { new Point(3, 2), new Point(2, 1) };
            List<Point> actual;
            actual = target.ValidMoves;

            bool result = true;

            foreach (Point point in expected)
            {
                if (!actual.Contains(point))
                {
                    result = false;
                    break;
                }
            }

            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the ValidMoves property of this piece
        /// </summary>
        /// <param name="board">Game board</param>
        public override void UpdateValidMoveList(Board board)
        {
            List<Point> possibleMoves = GetMoveList(board);
            List<Point> forbiddenMoves = new List<Point>();

            foreach (Point position in possibleMoves)   // Adds movement rules specific for pawns
            {
                if (this.Position.X == position.X)
                {
                    if (!board.GetTile(position).IsEmpty())
                        forbiddenMoves.Add(position);
                }
                else
                {
                    if (board.GetTile(position).IsEmpty())
                        forbiddenMoves.Add(position);
                }
            }

            foreach (Point position in forbiddenMoves)
                possibleMoves.Remove(position);

            this.ValidMoves = possibleMoves;
        }
Exemplo n.º 7
0
 public void IndexToCoordinateTest_neg1()
 {
     Board target = new Board();
     int index = -1;
     Point actual;   //IndexOutOfRangeException is expected
     actual = target.IndexToCoordinate(index);
 }
Exemplo n.º 8
0
 public void IndexToCoordinateTest_0()
 {
     Board target = new Board();
     int index = 0;
     Point expected = new Point(0, 0); // Index 0 gives the point (0,0)
     Point actual;   //Point (0,0) is expected
     actual = target.IndexToCoordinate(index);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 9
0
 public void InBoundsTest_Null()
 {
     Board target = new Board();
     Point point = null; // NullReferenceException is expected
     bool actual;
     actual = target.InBounds(point);
 }
Exemplo n.º 10
0
 public void InBoundsTest_81()
 {
     Board target = new Board();
     Point point = new Point(8, 1);   // The x coordinant is out of range
     bool expected = false;   //False is expected
     bool actual;
     actual = target.InBounds(point);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Returns a list of possible moves based on the piece direction vector and movement range
        /// </summary>
        /// <param name="board">Game board</param>
        /// <returns>List of Points</returns>
        protected List<Point> GetMoveList(Board board)
        {
            List<Point> moves = new List<Point>();

            foreach (Point direction in directionVector)
            {
                for (int i = 1; i <= moveReach; i++)
                {
                    Point point = new Point(this.position.X + direction.X * i, this.position.Y + direction.Y * i);

                    if (board.InBounds(point))
                    {
                        if (!ForbiddenCollision(point, board))
                            moves.Add(point);

                        if (!board.GetTile(point).IsEmpty())
                            break;
                    }
                }
            }

            return moves;
        }
Exemplo n.º 12
0
 public void GetPieceTest_null()
 {
     Board target = new Board();
     Piece piece = PieceBuilder.MakePawn(new Point(1, 1), Side.Light);   //Adds no piece
     Point position = new Point(1, 1);   // Look for piece at (1,1)
     Piece expected = null;
     Piece actual;
     actual = target.GetPiece(position);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 13
0
 public ChessComponent()
 {
     board = new Board();
     board.Init();
     turn = Side.Light;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Checks for collision with pieces of piece-type King and pieces of the same side
 /// </summary>
 /// <param name="position">Point position of tile</param>
 /// <param name="board">Game board</param>
 /// <returns>bool</returns>
 private bool ForbiddenCollision(Point position, Board board)
 {
     return board.GetTile(position).OccupiedBy(PieceType.King) || board.GetTile(position).IsOccupiedBy(this.Side);
 }
Exemplo n.º 15
0
 public void TryMovePieceTest_88()
 {
     Board board = new Board();
     Piece piece = PieceBuilder.MakeKing(new Point(1, 1), Side.Light);
     board.AddPiece(piece, new Point(1, 1));
     piece.UpdateValidMoveList(board);
     Point target = new Point(8, 8); //Move the king outside the board
     bool expected = false;
     bool actual;
     actual = board.TryMovePiece(piece, target);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 16
0
 public void GetTileTest_notNull()
 {
     Board target = new Board();
     Point position = new Point(0, 0); // We know from CoordinateToIndexTest_00 that (0,0) is equivalent to index: 0
     Tile expected = target.Tiles[0]; // The result should be the first tile in the list of tiles
     Tile actual;
     actual = target.GetTile(position);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 17
0
 public void GetTileTest_Null()
 {
     Board target = new Board();
     Point position = new Point(8, 7);   // We know from CoordinateToIndexTest_87 that (8,7) is equivalent to index: 64
     Tile actual;    // which should give us an IndexOutOfRange error
     actual = target.GetTile(position);
 }
Exemplo n.º 18
0
 public void GetPieceTest_notNull()
 {
     Board target = new Board();
     Piece piece = PieceBuilder.MakePawn(new Point(1, 1), Side.Light);
     target.AddPiece(piece, new Point(1, 1));   // Adds a piece at (1,1) all other tiles will be null
     Point position = new Point(1, 1);   // Look for piece at (1,1)
     Piece expected = piece;
     Piece actual;
     actual = target.GetPiece(position);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 19
0
 public void InBoundsTest_11()
 {
     Board target = new Board();
     Point point = new Point(1, 1);   // The point (1,1) is in range
     bool expected = true;   //True is expected
     bool actual;
     actual = target.InBounds(point);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Updates the ValidMoves property of this piece
        /// </summary>
        /// <param name="board">Game board</param>
        public override void UpdateValidMoveList(Board board)
        {
            List<Point> possibleMoves = GetMoveList(board);

            this.ValidMoves = possibleMoves;
        }
Exemplo n.º 21
0
 public abstract void UpdateValidMoveList(Board board);