// Start is called before the first frame update void Start() { WayPointTerrian wpt = new WayPointTerrian(); wpt.Init(); astar = new Astar(); astar.Init(wpt); pl = control.GetComponent <Player>(); }
void Awake() { destination = new Node(0, 3); Astar.Init(ySize, xSize); instance = this; map = new Tile[ySize, xSize]; towersMap = new bool[ySize, xSize]; enemiesCount = new int[ySize, xSize]; for (int i = 0; i < xSize; i++) { enemiesCount[ySize - 1, i] = 1; } Astar.SetGrid(towersMap); GenerateMap(ySize, xSize); Camera.main.transform.position = new Vector3((ySize - 3) / 2f, (xSize) / 2f, -1); }
public static bool Init(Map map) { try { if (singletonInstance == null) { singletonInstance = new Simulation(map); } } catch (Exception exc) //Simulation(map) can throw an exception { throw exc; } Astar.Init(AntHillConfig.mapColCount, AntHillConfig.mapRowCount); return(true); }
// teniendo el grafo construido, determina el camino a seguir con menor coste desde la posicion del tanque // hasta la posicion destino. Es llamado al seleccionar la casilla a la que queremos que vaya el tanque public void resolveGame(int x, int y) { CleanInfo(); UpdateInfo(); flag.transform.position = tablero.getCasPos(x, y); // ponemos la bandera en el destino // creamos A* List <NodeCool> pq = new List <NodeCool>(); Astar astar = new Astar(); // la posicion de origen sera la posicion logica del tanque time = Time.realtimeSinceStartup; // contador de tiempo astar.Init(graph, ref pq, (int)(puzzle.TankPosition.GetColumn() + columns * puzzle.TankPosition.GetRow()), (int)(y + columns * x), H); time = Time.realtimeSinceStartup - time; expandedNodes = astar.GetExpandedNodes(); depth = astar.GetDepth(); memSize = astar.GetMemSize(); UpdateInfo(); // procesamos el camino dado por A* StartCoroutine(createPath(astar)); }
public void AstarTest() { XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-ASTAR-anthill.xml"); AHGraphics.Init(); Astar.Init(AntHillConfig.mapColCount, AntHillConfig.mapRowCount); Simulation test_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); Spider test_spider = new Spider(new Position(5, 0)); Ant test_ant1 = new Warrior(new Position(5, 8)); Ant test_ant2 = new Warrior(new Position(0, 3)); List <KeyValuePair <int, int> > trail = Astar.Search(new KeyValuePair <int, int>(test_spider.Position.X, test_spider.Position.Y), new KeyValuePair <int, int>(test_ant1.Position.X, test_ant1.Position.Y), new TestAstarObject(test_isw)); List <KeyValuePair <int, int> > test_trail1 = new List <KeyValuePair <int, int> >(); /* Laduje ponizsza mape, gdzie uzywam oznaczen: * S - spider; Q-Queen; 1,2 - Ants i standardowych... * <Map row="sssssSssss" /> * <Map row="sxooooooxs" /> * <Map row="sxooooooxs" /> * <Map row="2xooooooxs" /> * <Map row="sxooooooxs" /> * <Map row="sxooooooxs" /> * <Map row="sxoooQooxs" /> * <Map row="sxooooooxs" /> * <Map row="sxooo1ooxs" /> * <Map row="ssssssssss" /> */ test_trail1.Add(new KeyValuePair <int, int>(5, 0)); test_trail1.Add(new KeyValuePair <int, int>(5, 1)); test_trail1.Add(new KeyValuePair <int, int>(5, 2)); test_trail1.Add(new KeyValuePair <int, int>(5, 3)); test_trail1.Add(new KeyValuePair <int, int>(5, 4)); test_trail1.Add(new KeyValuePair <int, int>(5, 5)); test_trail1.Add(new KeyValuePair <int, int>(5, 6)); test_trail1.Add(new KeyValuePair <int, int>(5, 7)); test_trail1.Add(new KeyValuePair <int, int>(5, 8)); Assert.IsNotNull(trail, "Trail is null"); Assert.AreEqual(test_trail1.Count, trail.Count, "Trail {0} and trail_test {1} count is not equal", trail.Count, test_trail1.Count); for (int i = 0; i < test_trail1.Count; i++) { Assert.AreEqual(test_trail1[i], trail[i], "Astar_path element EQUAL problem - is {0}, should be {1}", trail[i], test_trail1[i]); } trail = Astar.Search(new KeyValuePair <int, int>(test_spider.Position.X, test_spider.Position.Y), new KeyValuePair <int, int>(test_ant2.Position.X, test_ant2.Position.Y), new TestAstarObject(test_isw)); List <KeyValuePair <int, int> > test_trail2 = new List <KeyValuePair <int, int> >(); test_trail2.Add(new KeyValuePair <int, int>(5, 0)); test_trail2.Add(new KeyValuePair <int, int>(4, 0)); test_trail2.Add(new KeyValuePair <int, int>(3, 0)); test_trail2.Add(new KeyValuePair <int, int>(2, 0)); test_trail2.Add(new KeyValuePair <int, int>(1, 0)); test_trail2.Add(new KeyValuePair <int, int>(0, 0)); test_trail2.Add(new KeyValuePair <int, int>(0, 1)); test_trail2.Add(new KeyValuePair <int, int>(0, 2)); test_trail2.Add(new KeyValuePair <int, int>(0, 3)); Assert.IsNotNull(trail, "Trail is null"); Assert.AreEqual(test_trail2.Count, trail.Count, "Trail {0} and trail_test {1} count is not equal", trail.Count, test_trail2.Count); for (int i = 0; i < test_trail2.Count; i++) { Assert.AreEqual(test_trail2[i], trail[i], "Astar_path element EQUAL problem - is {0}, should be {1}", trail[i], test_trail2[i]); } }