public void NextTargetTest() { EnemyGrid grid = new EnemyGrid(); Square firstSquareHit = grid.GetSquare(9, 0); //firstSquareHit.Occupy(); int targetShipLength = 5; AfterFirstHitFiring tactics = new AfterFirstHitFiring(grid, firstSquareHit, targetShipLength); Square nextTarget = tactics.NextTarget(); Assert.IsTrue(nextTarget == grid.GetSquare(9, 1) || nextTarget == grid.GetSquare(8, 0)); Assert.IsFalse(nextTarget == grid.GetSquare(9, 0)); Assert.IsFalse(nextTarget == grid.GetSquare(8, 1)); firstSquareHit = grid.GetSquare(3, 3); //firstSquareHit.Occupy(); tactics = new AfterFirstHitFiring(grid, firstSquareHit, targetShipLength); nextTarget = tactics.NextTarget(); Assert.IsTrue(nextTarget == grid.GetSquare(3, 2) || nextTarget == grid.GetSquare(2, 3) || nextTarget == grid.GetSquare(3, 4) || nextTarget == grid.GetSquare(4, 3)); Assert.IsFalse(nextTarget == grid.GetSquare(3, 3)); }
public void NextTargetTest() { // test for a horizontal ship in the middle of playground EnemyGrid grid = new EnemyGrid(); Square sq1 = grid.GetSquare(3, 3); Square sq2 = grid.GetSquare(3, 4); Square sq3 = grid.GetSquare(3, 5); Square[] squaresHit = new Square[] { sq1, sq2, sq3 }; int targetShipLength = 4; OrientationalFiring tactics = new OrientationalFiring(grid, squaresHit, targetShipLength); Square next = tactics.NextTarget(); Assert.IsTrue(next.Row == 3 && (next.Column == 2 || next.Column == 6)); // now occupy a square at one of ends grid.GetSquare(3, 2).Occupy(); next = tactics.NextTarget(); Assert.IsTrue(next.Row == 3 && next.Column == 6); // test for a vertical ship at the bottom of playground grid = new EnemyGrid(); sq1 = grid.GetSquare(7, 1); sq2 = grid.GetSquare(8, 1); sq3 = grid.GetSquare(9, 1); squaresHit = new Square[] { sq1, sq2, sq3 }; targetShipLength = 4; tactics = new OrientationalFiring(grid, squaresHit, targetShipLength); next = tactics.NextTarget(); Assert.IsTrue(next.Row == 6 && next.Column == 1); // test for a vertical ship in the middle of playground grid = new EnemyGrid(); sq1 = grid.GetSquare(3, 1); sq2 = grid.GetSquare(4, 1); sq3 = grid.GetSquare(5, 1); squaresHit = new Square[] { sq1, sq2, sq3 }; targetShipLength = 4; tactics = new OrientationalFiring(grid, squaresHit, targetShipLength); next = tactics.NextTarget(); Assert.IsTrue((next.Row == 6 || next.Row == 2) && next.Column == 1); // now occupy a square at one of ends grid.GetSquare(6, 1).Occupy(); next = tactics.NextTarget(); Assert.IsTrue(next.Row == 2 && next.Column == 1); // test for a vertical ship at the bottom of playground grid = new EnemyGrid(); sq1 = grid.GetSquare(7, 1); sq2 = grid.GetSquare(8, 1); sq3 = grid.GetSquare(9, 1); squaresHit = new Square[] { sq1, sq2, sq3 }; targetShipLength = 4; tactics = new OrientationalFiring(grid, squaresHit, targetShipLength); next = tactics.NextTarget(); Assert.IsTrue(next.Row == 6 && next.Column == 1); grid = new EnemyGrid(); sq1 = grid.GetSquare(3, 1); sq2 = grid.GetSquare(5, 1); sq3 = grid.GetSquare(4, 1); squaresHit = new Square[] { sq1, sq2, sq3 }; targetShipLength = 4; tactics = new OrientationalFiring(grid, squaresHit, targetShipLength); tactics.AddNewHit(grid.GetSquare(6, 1)); next = tactics.NextTarget(); Assert.IsTrue((next.Row == 7 || next.Row == 2) && next.Column == 1); }