public void TestBestDir() { const int mapSize = 32; var state = new GameState(mapSize, mapSize, int.MaxValue, 100, 25, 5, 1); var baseLoc = new Location(5, 8); { var loc2 = new Location(7, 9); Assert.AreEqual(1, state.getHorizontalDelta(baseLoc, loc2)); Assert.AreEqual(2, state.getVerticalDelta(baseLoc, loc2)); Assert.AreEqual(-1, state.getHorizontalDelta(loc2, baseLoc)); Assert.AreEqual(-2, state.getVerticalDelta(loc2, baseLoc)); } { var loc3 = new Location(1, 2); var loc4 = new Location(mapSize - 1, mapSize - 3); Assert.AreEqual(5, state.getHorizontalDelta(loc3, loc4)); Assert.AreEqual(2, state.getVerticalDelta(loc3, loc4)); Assert.AreEqual(-5, state.getHorizontalDelta(loc4, loc3)); Assert.AreEqual(-2, state.getVerticalDelta(loc4, loc3)); } foreach (var dir in Ants.Ants.Aim.Keys) { var loc = state.GetDestination(baseLoc, dir); Assert.AreEqual(dir, state.GetBestDirection(baseLoc, loc)); } }
public static void MoveAnt(Backup backup, GameState state, Ant ant, Direction dir) { if (backup.Ants.Remove(ant)) { var loc = state.GetDestination(ant, dir); backup.Ants.Add(new Ant(loc, ant.Team)); Console.WriteLine(ant.ToString() + dir + " => " + loc); } else { throw new Exception("Attemtp to move unexisting ant!"); } }