/// <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; }
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); }
/// <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); }
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); }
/// <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; }