public void GetVisibleSpidersTest() { Worker worker1 = new Worker(new Position(2, 2)); Warrior warrior1 = new Warrior(new Position(3, 3)); Spider spider1 = new Spider(new Position(2, 3)); Spider spider2 = new Spider(new Position(3, 2)); XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-RAIN-anthill.xml"); AHGraphics.Init(); Simulation tmp_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); tmp_isw.ants.AddLast(worker1); tmp_isw.ants.AddLast(warrior1); tmp_isw.spiders.AddLast(spider1); tmp_isw.spiders.AddLast(spider2); Rain test_rain = new Rain(new Position(2, 3)); tmp_isw.rain = test_rain; LIList <Spider> list1 = tmp_isw.GetVisibleSpiders(test_rain); LIList <Spider> list2 = tmp_isw.GetVisibleSpiders(warrior1); LIList <Spider> list3 = tmp_isw.GetVisibleSpiders(worker1); LIList <Spider> list4 = tmp_isw.GetVisibleSpiders(spider2); Assert.IsTrue(list1.Contains(spider1), "GetVisibleAntsTest problem to see spider by rain"); Assert.IsTrue(list2.Contains(spider1), "GetVisibleAntsTest problem to see spider by warriror"); Assert.IsTrue(list3.Contains(spider1), "GetVisibleAntsTest problem to see spider by worker"); Assert.IsTrue(list4.Contains(spider1), "GetVisibleAntsTest problem to see spider by rain"); }
private void loadData(object sender, EventArgs e) { pauseButton_Click(this, null); this.Resize -= new EventHandler(UpdateMap); string name; if (simulationXMLopenFileDialog.ShowDialog() == DialogResult.OK) { name = simulationXMLopenFileDialog.FileName; XmlReaderWriter reader = new XmlReaderWriter(); try { reader.ReadMe(name); Simulation.DeInit(); Simulation.Init(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); } catch { openGLControl.Invalidate(); rightPanel.Enabled = false; MessageBox.Show(Properties.Resources.errorInitialization); return; } rightPanel.Enabled = true; timer.Interval = speedBar.Maximum - speedBar.Value + speedBar.Minimum; this.Resize += new EventHandler(UpdateMap); if (Simulation.simulation.Map.Width > Simulation.simulation.Map.Height) { maxMagnitude = Simulation.simulation.Map.Width; } else { maxMagnitude = Simulation.simulation.Map.Height; } offsetX = -(Simulation.simulation.Map.Width >> 1) + 0.5f; offsetY = -(Simulation.simulation.Map.Height >> 1) + 0.5f; magnitudeBar.Maximum = 50 * Simulation.simulation.Map.Height; AntHillConfig.curMagnitude = ((float)magnitudeBar.Value) / 1000.0f; vScrollBar1.Minimum = 0; vScrollBar1.LargeChange = 1; vScrollBar1.Maximum = 10 * Simulation.simulation.Map.Height + vScrollBar1.LargeChange; vScrollBar1.Value = 10 * (Simulation.simulation.Map.Height >> 1); vScrollBar1.Enabled = true; hScrollBar1.Minimum = 0; hScrollBar1.LargeChange = 1; hScrollBar1.Maximum = 10 * Simulation.simulation.Map.Width + hScrollBar1.LargeChange; hScrollBar1.Value = 10 * (Simulation.simulation.Map.Width >> 1); hScrollBar1.Enabled = true; RecalculateUI(true); openGLControl.Invalidate(); } }
public void QueenTest() { XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-ASTAR-anthill.xml"); Simulation test_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); Assert.AreEqual(test_isw.queen.TurnsToBecomeHungry, 3, "Queen has wrong TurnsToBecomeHungry"); Assert.AreEqual(test_isw.queen.TurnsWithoutFood, 100, "Queen has wrong TurnsWithoutFood"); Assert.AreEqual(new Position(5, 6), test_isw.queen.Position, "queen.Position problem"); }
public void XmlTest() { XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-XML-anthill.xml"); //ant Assert.AreEqual(AntHillConfig.antTurnNumberToBecomeHungry, 3, "problems ant TurnsToBecomeHungry"); Assert.AreEqual(AntHillConfig.antMaxLifeWithoutFood, 100, "problem ant.wrong TurnsWithoutFood"); Assert.AreEqual(AntHillConfig.antFoodQuantityAfterDeath, 1, "problem ant.foodQuantityAfterDeath"); Assert.AreEqual(AntHillConfig.antMaxLife, 100, "problem antMaxLife"); Assert.AreEqual(AntHillConfig.antMaxHealth, 1, "problem ant.MaxHealth"); Assert.AreEqual(AntHillConfig.antForgettingTime, 5, "problem ant.forgettingtime"); Assert.AreEqual(AntHillConfig.antSightRadius, 2, "problem antSightRadius"); Assert.AreEqual(AntHillConfig.antStrength, 3, "problem ant.Strength"); Assert.AreEqual(AntHillConfig.curMagnitude, 1, "problem curMagnitude"); Assert.AreEqual(AntHillConfig.eggHatchTime, 10, "problem egg.HatchTime"); Assert.AreEqual(AntHillConfig.eggHatchWarriorProbability, 0.2, "problem eggHatchWarriorProbability"); Assert.AreEqual(AntHillConfig.foodProbability, 0.2, "problem foodProbability"); Assert.AreEqual(AntHillConfig.mapColCount, 10, "problem mapColCount"); Assert.AreEqual(AntHillConfig.mapRowCount, 10, "problem mapRowCount"); Assert.AreEqual(AntHillConfig.messageLifeTime, 10, "problem messageLifeTime"); Assert.AreEqual(AntHillConfig.messageRadius, 3, "problem messageRadius"); Assert.AreEqual(AntHillConfig.queenLayEggProbability, 0, "problem queenLayEggProbability"); Assert.AreEqual(AntHillConfig.queenXPosition, 5, "problem queenXPosition"); Assert.AreEqual(AntHillConfig.queenYPosition, 6, "problem queenYPosition"); Assert.AreEqual(AntHillConfig.rainMaxDuration, 20, "problem rainMaxDuration"); Assert.AreEqual(AntHillConfig.rainProbability, 0.1, "problem rainProbability"); Assert.AreEqual(AntHillConfig.rainWidth, 3, "problem rainWidth"); Assert.AreEqual(AntHillConfig.spiderFoodQuantityAfterDeath, 5, "problem spiderFoodQuantityAfterDeath"); Assert.AreEqual(AntHillConfig.spiderMaxHealth, 10, "problem spiderMaxHealth"); Assert.AreEqual(AntHillConfig.spiderProbability, 0.5, "problem spiderProbability"); Assert.AreEqual(AntHillConfig.warriorStartCount, 0, "problem warrior startCount"); Assert.AreEqual(AntHillConfig.workerStartCount, 0, "problem workerStartCount"); Assert.AreEqual(AntHillConfig.queenXPosition, 5, "queen.Position.X problem"); Assert.AreEqual(AntHillConfig.queenYPosition, 6, "queen.Position.Y problem"); for (int i = 0; i < AntHillConfig.mapColCount; i++) { Assert.AreEqual(AntHillConfig.tiles[i, 0].TileType, TileType.Outdoor, "Map xml problem in row 0"); Assert.AreEqual(AntHillConfig.tiles[i, 1].TileType, TileType.Wall, "Map xml problem in row 1 "); Assert.AreEqual(AntHillConfig.tiles[i, 2].TileType, TileType.Indoor, "Map xml problem in row 2 "); Assert.AreEqual(AntHillConfig.tiles[i, 3].TileType, TileType.Indoor, "Map xml problem in row 3 "); Assert.AreEqual(AntHillConfig.tiles[i, 4].TileType, TileType.Indoor, "Map xml problem in row 4 "); Assert.AreEqual(AntHillConfig.tiles[i, 5].TileType, TileType.Indoor, "Map xml problem in row 5 "); Assert.AreEqual(AntHillConfig.tiles[i, 6].TileType, TileType.Indoor, "Map xml problem in row 6 "); Assert.AreEqual(AntHillConfig.tiles[i, 7].TileType, TileType.Indoor, "Map xml problem in row 7"); Assert.AreEqual(AntHillConfig.tiles[i, 8].TileType, TileType.Wall, "Map xml problem in row 8 "); Assert.AreEqual(AntHillConfig.tiles[i, 9].TileType, TileType.Outdoor, "Map xml problem in row 9"); } }
public void RainTest() { XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-RAIN-anthill.xml"); Simulation tmp_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); AHGraphics.Init(); Assert.IsNotNull(tmp_isw, "Simulation is NULL problem!!!"); Spider test_spider = new Spider(new Position(61, 71)); tmp_isw.spiders.AddLast(test_spider); Ant test_ant1 = new Warrior(new Position(62, 71)); Ant test_ant2 = new Worker(new Position(61, 72)); tmp_isw.ants.AddLast(test_ant1); tmp_isw.ants.AddLast(test_ant2); Rain test_rain = new Rain(new Position(60, 70)); Assert.IsNotNull(test_rain, "Rain is NULL problem!!!"); Assert.IsTrue(test_rain.IsRainOver(60, 70), "Rain isn't exist or Rain.IsRainOver problem"); Assert.IsTrue(test_rain.IsRainOver(62, 72), "Rain is too small or Rain.IsRainOver problem"); //Assert.IsTrue(test_rain.IsRainOver(58, 68), "Rain is too small or Rain.IsRainOver problem"); Assert.IsTrue(test_rain.IsRainOver(63, 73), "Rain is too big or Rain.IsRainOver problem"); Assert.IsFalse(test_rain.IsRainOver(57, 67), "Rain is too big or Rain.IsRainOver problem"); Assert.AreEqual(new Position(60, 70), test_rain.Position, "Rain.Position problem"); Assert.IsTrue((test_rain.TimeToLive >= 0) && (test_rain.TimeToLive < AntHillConfig.rainMaxDuration + 1), "Rain.TimeToLive range problem"); int tmp = test_rain.TimeToLive; Assert.AreEqual(tmp, test_rain.TimeToLive, "Rain.TimeToLive problem should be {0}, but is {1}", tmp, test_rain.TimeToLive); Assert.IsTrue(tmp_isw.spiders.Contains(test_spider), "Find spider problem"); Assert.IsTrue(tmp_isw.ants.Contains(test_ant1), "Find warrior problem"); Assert.IsTrue(tmp_isw.ants.Contains(test_ant2), "Find worker problem"); Assert.IsNotNull(test_rain, "Rain is NULL problem!!!"); test_rain.Maintain((ISimulationWorld)tmp_isw); Assert.AreEqual(tmp - 1, test_rain.TimeToLive, "Rain.Maintain problem should be {0}, but is {1}", tmp - 1, test_rain.TimeToLive); Assert.IsFalse(tmp_isw.spiders.Contains(test_spider), "Rain destroy spiders problem"); Assert.IsFalse(tmp_isw.ants.Contains(test_ant1), "Rain destroy warriors problem"); Assert.IsFalse(tmp_isw.ants.Contains(test_ant2), "Rain destroy workers problem"); }
public void CitizenTest() { Worker worker1 = new Worker(new Position(2, 2)); Worker worker2 = new Worker(new Position(3, 3)); XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-RAIN-anthill.xml"); AHGraphics.Init(); /*test AddSet() function*/ Simulation tmp_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); //Message message = new Message(new Position(2, 2), MessageType.FoodLocalization, new Position(0,0)); tmp_isw.CreateMessage(new Position(2, 2), MessageType.FoodLocalization, new Position(0, 0)); tmp_isw.ants.AddLast(worker1); tmp_isw.ants.AddLast(worker2); //tmp_isw.messages.AddLast(message); //worker1.AddToSet(message,2); //worker1.SpreadSignal(tmp_isw); LIList <Message> list = tmp_isw.GetVisibleMessages(worker2); bool check = list.Count != 0; Assert.IsTrue(check, "problem with adding messages"); /*test GetNearestFood()*/ LIList <Food> foodList = new LIList <Food>(); foodList.AddLast(new Food(new Position(4, 4), 1)); foodList.AddLast(new Food(new Position(8, 8), 3)); foodList.AddLast(new Food(new Position(2, 3), 3)); foodList.AddLast(new Food(new Position(1, 1), 3)); Food nFood = worker1.testGetNearestFood(foodList); Assert.AreEqual(new Position(2, 3), nFood.Position, "finding nearest food problem"); /*test ReadMessage()*/ Worker worker3 = new Worker(new Position(4, 4)); worker3.AddToSet(new Message(new Position(5, 5), MessageType.FoodLocalization, new Position(0, 0)), 1); worker3.AddToSet(new Message(new Position(1, 1), MessageType.FoodLocalization, new Position(0, 0)), 3); worker3.AddToSet(new Message(new Position(3, 3), MessageType.FoodLocalization, new Position(0, 0)), 2); Message nMessage = worker3.testReadMessage(MessageType.FoodLocalization); Assert.AreEqual(new Position(1, 1), nMessage.Position, "ReadMessage function problem in Citizen"); }
public void GetVisibleMessagesTest() { Worker worker1 = new Worker(new Position(2, 2)); Warrior warrior1 = new Warrior(new Position(3, 3)); Message message1_tmp = new Message(new Position(2, 2), MessageType.QueenIsHungry, new Position(0, 0)); Message message2_tmp = new Message(new Position(3, 3), MessageType.QueenInDanger, new Position(0, 0)); XmlReaderWriter reader = new XmlReaderWriter(); reader.ReadMe("..\\..\\tests\\test-RAIN-anthill.xml"); AHGraphics.Init(); Simulation tmp_isw = new Simulation(new Map(AntHillConfig.mapColCount, AntHillConfig.mapRowCount, AntHillConfig.tiles)); tmp_isw.ants.AddLast(worker1); tmp_isw.ants.AddLast(warrior1); tmp_isw.CreateMessage(new Position(2, 2), MessageType.QueenIsHungry, new Position(0, 0)); tmp_isw.CreateMessage(new Position(3, 3), MessageType.QueenInDanger, new Position(0, 0)); Rain test_rain = new Rain(new Position(3, 3)); tmp_isw.rain = test_rain; LIList <Message> list1 = tmp_isw.GetVisibleMessages(test_rain); LIList <Message> list2 = tmp_isw.GetVisibleMessages(warrior1); LIList <Message> list3 = tmp_isw.GetVisibleMessages(worker1); Assert.AreEqual(list1.First.Value.Position, message1_tmp.Position, "GetVisibleMessagesTest problem to see message by rain (POSITION)"); Assert.AreEqual(list1.First.Value.GetMessageType, message1_tmp.GetMessageType, "GetVisibleMessagesTest problem to see message by rain (MESSAGETYPE)"); Assert.AreEqual(list1.First.Value.TargetPosition, message1_tmp.TargetPosition, "GetVisibleMessagesTest problem to see message by rain (TARGETPOS)"); Assert.AreEqual(list2.Last.Value.Position, message2_tmp.Position, "GetVisibleMessagesTest problem to see message by warriror (POSITION)"); Assert.AreEqual(list2.Last.Value.GetMessageType, message2_tmp.GetMessageType, "GetVisibleMessagesTest problem to see message by warriror (MESSAGETYPE)"); Assert.AreEqual(list2.Last.Value.TargetPosition, message2_tmp.TargetPosition, "GetVisibleMessagesTest problem to see message by warriror (TARGETPOS)"); Assert.AreEqual(list3.First.Value.Position, message1_tmp.Position, "GetVisibleMessagesTest problem to see message by worker (POSITION)"); Assert.AreEqual(list3.First.Value.GetMessageType, message1_tmp.GetMessageType, "GetVisibleMessagesTest problem to see message by worker (MESSAGETYPE)"); Assert.AreEqual(list3.First.Value.TargetPosition, message1_tmp.TargetPosition, "GetVisibleMessagesTest problem to see message by worker (TARGETPOS)"); }
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]); } }