public void TestAttackAndTake() { GameObject GameObject = new GameObject(); GameObject.whites = new List<Figure>(); GameObject.blacks = new List<Figure>(); King wKing = new King(GameObject, 1, 5, Color.white); Pawn wPawn1 = new Pawn(GameObject, 3, 2, Color.white); Pawn wPawn2 = new Pawn(GameObject, 4, 2, Color.white); Pawn wPawn3 = new Pawn(GameObject, 5, 2, Color.white); King bKing = new King(GameObject, 8, 4, Color.black); Pawn bPawn1 = new Pawn(GameObject, 3, 7, Color.black); Pawn bPawn2 = new Pawn(GameObject, 4, 7, Color.black); Pawn bPawn3 = new Pawn(GameObject, 5, 7, Color.black); GameObject.whites.Add(wKing); GameObject.whites.Add(wPawn1); GameObject.whites.Add(wPawn2); GameObject.whites.Add(wPawn3); GameObject.blacks.Add(bKing); GameObject.blacks.Add(bPawn1); GameObject.blacks.Add(bPawn2); GameObject.blacks.Add(bPawn3); GameObject.UpdateAllBeatFields(); Assert.IsTrue(wPawn1.CanAttackPosition(2, 3)); Assert.IsTrue(wPawn1.CanAttackPosition(4, 3)); Assert.IsTrue(bPawn2.CanAttackPosition(3, 6)); Assert.IsTrue(bPawn2.CanAttackPosition(5, 6)); }
public void TestMove() { GameObject GameObject = new GameObject(); GameObject.whites = new List<Figure>(); GameObject.blacks = new List<Figure>(); King wKing = new King(GameObject, 1, 5, Color.white); Pawn wPawn1 = new Pawn(GameObject, 3, 2, Color.white); Pawn wPawn2 = new Pawn(GameObject, 4, 2, Color.white); Pawn wPawn3 = new Pawn(GameObject, 5, 2, Color.white); King bKing = new King(GameObject, 8, 4, Color.black); Pawn bPawn1 = new Pawn(GameObject, 3, 7, Color.black); Pawn bPawn2 = new Pawn(GameObject, 4, 7, Color.black); Pawn bPawn3 = new Pawn(GameObject, 5, 7, Color.black); GameObject.whites.Add(wKing); GameObject.whites.Add(wPawn1); GameObject.whites.Add(wPawn2); GameObject.whites.Add(wPawn3); GameObject.blacks.Add(bKing); GameObject.blacks.Add(bPawn1); GameObject.blacks.Add(bPawn2); GameObject.blacks.Add(bPawn3); GameObject.UpdateAllBeatFields(); Assert.IsFalse(wPawn1.Move(3, 5)); Assert.IsFalse(wPawn1.Move(2, 3)); Assert.IsTrue(wPawn1.Move(3, 4)); Assert.IsTrue(bPawn3.Move(5, 6)); Assert.IsTrue(wPawn1.Move(3, 5)); Assert.IsFalse(bPawn3.Move(5, 4)); Assert.IsTrue(bPawn2.Move(4, 5)); Assert.IsTrue(wPawn1.Move(4, 6)); // cross-field taking Assert.IsTrue(GameObject.blacks.Count == 3); Assert.IsTrue(bPawn1.Move(4, 6)); Assert.IsTrue(GameObject.whites.Count == 3); bPawn1.field = new Field(3, 7); bPawn1.moveCount = 0; wPawn2.field = new Field(4, 5); Queen bQueen = new Queen(GameObject, 8, 5, Color.black); GameObject.blacks.Add(bQueen); GameObject.UpdateAllBeatFields(); Assert.IsTrue(wKing.Move(2, 5)); Assert.IsTrue(bPawn1.Move(3, 5)); Assert.IsFalse(wPawn2.Move(3, 6)); // Can't take on cross-field because of wKing became opened to attack Assert.IsTrue(wKing.Move(1, 6)); Assert.IsTrue(bQueen.Move(7, 4)); Assert.IsFalse(wPawn2.Move(3, 6)); // Can't take on cross-field because of different move count }
public void TestMove() { GameObject GameObject = new GameObject(); GameObject.whites = new List<Figure>(); GameObject.blacks = new List<Figure>(); King wKing = new King(GameObject, 1, 1, Color.white); King bKing = new King(GameObject, 8, 8, Color.black); Knight bKnight = new Knight(GameObject, 5, 5, Color.black); Knight wKnight = new Knight(GameObject, 5, 4, Color.white); GameObject.whites.Add(wKing); GameObject.blacks.Add(bKing); GameObject.blacks.Add(bKnight); GameObject.whites.Add(wKnight); // knights in the middle of the field GameObject.UpdateAllBeatFields(); Assert.IsTrue(wKnight.MoveFields.Count == 8); Assert.IsTrue(wKnight.CanMoveToPosition(3, 5)); Assert.IsTrue(wKnight.CanMoveToPosition(3, 3)); Assert.IsTrue(wKnight.CanMoveToPosition(4, 6)); Assert.IsTrue(wKnight.CanMoveToPosition(4, 2)); Assert.IsTrue(wKnight.CanMoveToPosition(6, 6)); Assert.IsTrue(wKnight.CanMoveToPosition(6, 2)); Assert.IsTrue(wKnight.CanMoveToPosition(7, 3)); Assert.IsTrue(wKnight.CanMoveToPosition(7, 5)); Assert.IsTrue(bKnight.MoveFields.Count == 8); Assert.IsTrue(bKnight.CanMoveToPosition(3, 6)); Assert.IsTrue(bKnight.CanMoveToPosition(3, 4)); Assert.IsTrue(bKnight.CanMoveToPosition(4, 7)); Assert.IsTrue(bKnight.CanMoveToPosition(4, 3)); Assert.IsTrue(bKnight.CanMoveToPosition(6, 7)); Assert.IsTrue(bKnight.CanMoveToPosition(6, 3)); Assert.IsTrue(bKnight.CanMoveToPosition(7, 4)); Assert.IsTrue(bKnight.CanMoveToPosition(7, 6)); // knights at the border of the field bKnight.field.x = 8; bKnight.field.y = 7; wKnight.field.x = 3; wKnight.field.y = 2; GameObject.UpdateAllBeatFields(); Assert.IsTrue(wKnight.MoveFields.Count == 5); Assert.IsTrue(wKnight.CanMoveToPosition(1, 3)); Assert.IsTrue(wKnight.CanMoveToPosition(2, 4)); Assert.IsTrue(wKnight.CanMoveToPosition(4, 4)); Assert.IsTrue(wKnight.CanMoveToPosition(5, 3)); Assert.IsTrue(wKnight.CanMoveToPosition(5, 1)); Assert.IsTrue(bKnight.MoveFields.Count == 3); Assert.IsTrue(bKnight.CanMoveToPosition(6, 8)); Assert.IsTrue(bKnight.CanMoveToPosition(6, 6)); Assert.IsTrue(bKnight.CanMoveToPosition(7, 5)); // Add white rook Rook wRook = new Rook(GameObject, 8, 2, Color.white); GameObject.whites.Add(wRook); GameObject.UpdateAllBeatFields(); Assert.IsTrue(wRook.Move(8, 3)); Assert.IsFalse(bKnight.Move(6, 8)); // Can't move knight - open attack on king Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7); Assert.IsFalse(bKnight.Move(6, 6)); // Can't move knight - open attack on king Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7); Assert.IsFalse(bKnight.Move(7, 5)); // Can't move knight - open attack on king Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7); // Add white pawn and beat it by knight Pawn p1 = new Pawn(GameObject, 6, 6, Color.white); GameObject.whites.Add(p1); GameObject.UpdateAllBeatFields(); Assert.IsFalse(bKnight.Move(6, 6)); // remove rook GameObject.whites.Remove(wRook); GameObject.UpdateAllBeatFields(); Assert.IsTrue(bKnight.Move(6, 6)); // add white rook wRook.field.x = 5; wRook.field.y = 1; GameObject.whites.Add(wRook); GameObject.UpdateAllBeatFields(); Assert.IsTrue(wRook.Move(5, 8)); Assert.IsTrue(bKnight.Move(5, 8)); // add white rook again wRook.field.x = 1; wRook.field.y = 2; bKnight.field.x = 6; bKnight.field.y = 6; GameObject.whites.Add(wRook); GameObject.UpdateAllBeatFields(); Assert.IsTrue(wRook.Move(1, 8)); Assert.IsFalse(bKnight.Move(5, 4)); //king not covered Assert.IsFalse(bKnight.Move(7, 4)); //king not covered Assert.IsTrue(bKnight.Move(7, 8)); //cover king }
public void TestAttackAndTake() { GameObject GameObject = new GameObject(); GameObject.whites = new List<Figure>(); GameObject.blacks = new List<Figure>(); King wKing = new King(GameObject, 1, 1, Color.white); King bKing = new King(GameObject, 8, 8, Color.black); Knight bKnight = new Knight(GameObject, 5, 5, Color.black); Knight wKnight = new Knight(GameObject, 5, 4, Color.white); GameObject.whites.Add(wKing); GameObject.blacks.Add(bKing); GameObject.blacks.Add(bKnight); GameObject.whites.Add(wKnight); // knights in the middle of the field GameObject.UpdateAllBeatFields(); Assert.IsTrue(wKnight.CanAttackPosition(3, 5)); Assert.IsTrue(wKnight.CanAttackPosition(3, 3)); Assert.IsTrue(wKnight.CanAttackPosition(4, 6)); Assert.IsTrue(wKnight.CanAttackPosition(4, 2)); Assert.IsTrue(wKnight.CanAttackPosition(6, 6)); Assert.IsTrue(wKnight.CanAttackPosition(6, 2)); Assert.IsTrue(wKnight.CanAttackPosition(7, 3)); Assert.IsTrue(wKnight.CanAttackPosition(7, 5)); Assert.IsTrue(bKnight.CanAttackPosition(3, 6)); Assert.IsTrue(bKnight.CanAttackPosition(3, 4)); Assert.IsTrue(bKnight.CanAttackPosition(4, 7)); Assert.IsTrue(bKnight.CanAttackPosition(4, 3)); Assert.IsTrue(bKnight.CanAttackPosition(6, 7)); Assert.IsTrue(bKnight.CanAttackPosition(6, 3)); Assert.IsTrue(bKnight.CanAttackPosition(7, 4)); Assert.IsTrue(bKnight.CanAttackPosition(7, 6)); // knights at the border of the field bKnight.field.x = 8; bKnight.field.y = 7; wKnight.field.x = 3; wKnight.field.y = 2; GameObject.UpdateAllBeatFields(); Assert.IsTrue(wKnight.CanAttackPosition(1, 3)); Assert.IsTrue(wKnight.CanAttackPosition(2, 4)); Assert.IsTrue(wKnight.CanAttackPosition(4, 4)); Assert.IsTrue(wKnight.CanAttackPosition(5, 3)); Assert.IsTrue(wKnight.CanAttackPosition(5, 1)); Assert.IsTrue(bKnight.CanMoveToPosition(6, 8)); Assert.IsTrue(bKnight.CanMoveToPosition(6, 6)); Assert.IsTrue(bKnight.CanMoveToPosition(7, 5)); // Add black pawns Pawn bp1 = new Pawn(GameObject, 2, 4, Color.black); Pawn bp2 = new Pawn(GameObject, 5, 3, Color.black); GameObject.blacks.Add(bp1); GameObject.blacks.Add(bp2); Assert.IsTrue(wKnight.CanAttackPosition(1, 3)); Assert.IsTrue(wKnight.CanAttackPosition(2, 4)); Assert.IsTrue(wKnight.CanAttackPosition(4, 4)); Assert.IsTrue(wKnight.CanAttackPosition(5, 3)); Assert.IsTrue(wKnight.CanAttackPosition(5, 1)); }
public GameObject() { for (sbyte i = 1; i <= 8; i++) { Pawn p1 = new Pawn(this, i, 7, Color.black); this.blacks.Add(p1); Pawn wp1 = new Pawn(this, i, 2, Color.white); this.whites.Add(wp1); } Bishop b1 = new Bishop(this, 3, 8, Color.black); this.blacks.Add(b1); Bishop b2 = new Bishop(this, 6, 8, Color.black); this.blacks.Add(b2); Bishop wb1 = new Bishop(this, 3, 1, Color.white); this.whites.Add(wb1); Bishop wb2 = new Bishop(this, 6, 1, Color.white); this.whites.Add(wb2); Rook r1 = new Rook(this, 1, 8, Color.black); this.blacks.Add(r1); Rook r2 = new Rook(this, 8, 8, Color.black); this.blacks.Add(r2); Rook wr1 = new Rook(this, 1, 1, Color.white); this.whites.Add(wr1); Rook wr2 = new Rook(this, 8, 1, Color.white); this.whites.Add(wr2); Knight kn1 = new Knight(this, 2, 8, Color.black); this.blacks.Add(kn1); Knight kn2 = new Knight(this, 7, 8, Color.black); this.blacks.Add(kn2); Knight wkn1 = new Knight(this, 2, 1, Color.white); this.whites.Add(wkn1); Knight wkn2 = new Knight(this, 7, 1, Color.white); this.whites.Add(wkn2); var q = new Queen(this, 4, 8, Color.black); this.blacks.Add(q); var wq = new Queen(this, 4, 1, Color.white); this.whites.Add(wq); var k = new King(this, 5, 8, Color.black); this.blacks.Add(k); var wk = new King(this, 5, 1, Color.white); this.whites.Add(wk); this.UpdateAllBeatFields(); }
public void TestDraw() { GameObject game = new GameObject(); // get knight game.whites = new List<Figure>(); game.blacks = new List<Figure>(); King wKing = new King(game, 2, 2, Color.white); King bKing = new King(game, 2, 6, Color.black); Rook wRook = new Rook(game, 1, 1, Color.white); Rook bRook = new Rook(game, 1, 7, Color.black); Pawn wPawn = new Pawn(game, 5, 2, Color.white); game.whites.Add(wKing); game.whites.Add(wRook); game.blacks.Add(bKing); game.blacks.Add(bRook); game.whites.Add(wPawn); game.UpdateAllBeatFields(); Assert.IsFalse(game.isDraw); wRook.Move(2, 1); bRook.Move(2, 7); Assert.IsTrue(game.movesToDraw == 2); wPawn.Move(5, 4); Assert.IsTrue(game.movesToDraw == 0); bRook.Move(3, 7); wPawn.Move(5, 5); Assert.IsTrue(game.movesToDraw == 0); bRook.Move(4, 7); wPawn.Move(5, 6); Assert.IsTrue(game.movesToDraw == 0); bRook.Move(1, 7); wPawn.Move(5, 7); Assert.IsTrue(game.movesToDraw == 0); bRook.Move(2, 7); wRook.Move(1, 1); Assert.IsTrue(game.movesToDraw == 2); bRook.Move(5, 7); Assert.IsTrue(game.movesToDraw == 0); sbyte new_x; for (int i = 0; i < 100; i++) { if (game.GetColorTurn() == Color.white) { new_x = (sbyte) (wRook.field.x == 1 ? 2 : 1); Assert.IsTrue(wRook.Move(new_x, 1)); } else { new_x = (sbyte) (bRook.field.x == 1 ? 2 : 1); Assert.IsTrue(bRook.Move(new_x, 7)); } if (game.movesToDraw == 100) Assert.IsTrue(game.isDraw); } }
public void TestTransform() { GameObject GameObject = new GameObject(); GameObject.whites = new List<Figure>(); GameObject.blacks = new List<Figure>(); King wKing = new King(GameObject, 1, 5, Color.white); King bKing = new King(GameObject, 8, 4, Color.black); Pawn wPawn1 = new Pawn(GameObject, 1, 7, Color.white); GameObject.blacks.Add(bKing); GameObject.whites.Add(wKing); GameObject.whites.Add(wPawn1); GameObject.UpdateAllBeatFields(); Assert.IsFalse(wPawn1.Transform(FigureTypes.Knight)); Assert.IsTrue(wPawn1.Move(1, 8)); Assert.IsFalse(wPawn1.Transform(FigureTypes.Pawn)); Assert.IsFalse(wPawn1.Transform(FigureTypes.King)); Assert.IsTrue(wPawn1.Transform(FigureTypes.Knight)); Figure newFigure = GameObject.GetFigureByXY(wPawn1.field.x, wPawn1.field.y); Assert.IsTrue(newFigure.type == FigureTypes.Knight); Assert.IsTrue(newFigure.field.x == 1); Assert.IsTrue(newFigure.field.y == 8); Assert.IsTrue(newFigure.MoveFields.Count == 2); Assert.IsTrue(newFigure.CanMoveToPosition(2, 6)); Assert.IsTrue(newFigure.CanMoveToPosition(3, 7)); }