public void TestRetreat() { using (var consoleOutput = new ConsoleOutput()) { var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1); var bot = new MyBot(); state.StartNewTurn(); state.AddAnt(16, 15, 0); state.AddAnt(12, 16, 1); state.AddAnt(12, 15, 1); state.AddAnt(12, 17, 1); var initDist = state.EnemyAnts.Select(x => state.GetDistance(state.MyAnts[0], x)).ToList(); bot.DoTurn(state); ApplyTurn(state, consoleOutput.GetOuput()); consoleOutput.Clear(); var finalDist = state.EnemyAnts.Select(x => state.GetDistance(state.MyAnts[0], x)).ToList(); for (int i = 0; i < initDist.Count; i++) { Assert.Greater(finalDist[i], initDist[i]); } } }
public void TestApplyTurn() { var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1); state.AddAnt(1, 2, 0); state.AddAnt(2, 3, 0); Assert.Contains(new Ant(1, 2, 0), state.MyAnts); Assert.Contains(new Ant(2, 3, 0), state.MyAnts); ApplyTurn(state, "o 1 2 s\r\no 2 3 n\r\n"); Assert.Contains(new Ant(2, 2, 0), state.MyAnts); Assert.Contains(new Ant(1, 3, 0), state.MyAnts); }
public void TestRegroup() { using (var consoleOutput = new ConsoleOutput()) { var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1); var bot = new MyBot(); state.StartNewTurn(); state.AddAnt(18, 15, 0); state.AddAnt(16, 16, 0); state.AddAnt(18, 17, 0); state.AddAnt(12, 15, 1); state.AddAnt(12, 17, 1); {//Extra test for platoon + BuildFrontLine List <Ant> Platoon = new List <Ant>(); Battle.BuildPlatoon(state, Platoon, new Ant(16, 16, 0)); Assert.AreEqual(3, Platoon.Count); List <Ant> EPlatoon = new List <Ant>(); Battle.BuildPlatoon(state, EPlatoon, new Ant(12, 15, 1)); Assert.AreEqual(2, EPlatoon.Count); var AllyDist = Battle.BuildFrontline(state, Platoon, EPlatoon, out int qty, out int distance); Assert.AreEqual(1, qty); Assert.AreEqual(6, AllyDist[Platoon.IndexOf(new Ant(18, 15, 0))]); Assert.AreEqual(5, AllyDist[Platoon.IndexOf(new Ant(16, 16, 0))]); Assert.AreEqual(5, distance); var EnemyDist = Battle.BuildFrontline(state, EPlatoon, Platoon, out int Eqty, out int Edistance); Assert.AreEqual(2, Eqty); } bot.DoTurn(state); consoleOutput.originalOutput.Write(consoleOutput.GetOuput()); ApplyTurn(state, consoleOutput.GetOuput()); consoleOutput.Clear(); Assert.Contains(new Ant(17, 15, 0), state.MyAnts); Assert.Contains(new Ant(16, 16, 0), state.MyAnts); Assert.Contains(new Ant(17, 17, 0), state.MyAnts); } }
public void GetFood() { using (var consoleOutput = new ConsoleOutput()) { var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1); var bot = new MyBot(); state.StartNewTurn(); state.AddAnt(16, 16, 0); state.AddFood(17, 16); Func <Location, Ant> test = x => state.MyAnts.Select(ant => (x.Row == ant.Row && x.Col == ant.Col) ? ant : null).Where(y => y != null).FirstOrDefault(); Assert.NotNull(test(state.MyAnts[0])); Assert.NotNull(test(new Ant(16, 16, 0))); Assert.NotNull(test(new Location(16, 16))); var result = MyBot.FindClosest(state, state.FoodTiles[0], test); Assert.NotNull(result); bot.DoTurn(state); Assert.AreEqual("o 16 16 s\r\n", consoleOutput.GetOuput()); consoleOutput.Clear(); state.StartNewTurn(); state.AddAnt(16, 16, 0); state.AddFood(15, 16); bot.DoTurn(state); Assert.AreEqual("o 16 16 n\r\n", consoleOutput.GetOuput()); } }
public void Restore(GameState state) { state.StartNewTurn(); foreach (var loc in Ants) { state.AddAnt(loc.Row, loc.Col, loc.Team); } foreach (var loc in Hills) { state.AntHill(loc.Row, loc.Col, loc.Team); } foreach (var loc in Food) { state.AddFood(loc.Row, loc.Col); } }