public void TestFindClosest() { const int mapSize = 32; var state = new GameState(mapSize, mapSize, int.MaxValue, 100, 25, 5, 1); var start1 = new Location(16, 16); var target1 = new Location(16, 18); var testCollection1 = new List <Location>(); testCollection1.Add(target1); var testCollection2 = new[] { new Location(1, 1), new Location(mapSize, mapSize), new Location(mapSize, 1), new Location(1, mapSize), target1, }.ToList(); var tests = new[] { new { start = start1, target = target1, dist = 20, resultIsNull = false, set = testCollection1 }, new { start = start1, target = target1, dist = 1, resultIsNull = true, set = testCollection1 }, new { start = start1, target = target1, dist = 20, resultIsNull = false, set = testCollection2 }, }; foreach (var test in tests) { var result = MyBot.FindClosest(state, test.start, x => test.set.Contains(x) ? test.set[test.set.IndexOf(x)]: null, test.dist); if (test.resultIsNull) { Assert.IsNull(result); } else { Assert.NotNull(result); Assert.AreEqual(test.target, result.Target); } } }
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()); } }