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"); }
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"); }
private void Initialize() { _map = null; eggs = new LIList <Egg>(); eggs.Clear(); messages = new LIList <Message>(); messages.Clear(); food = new LIList <Food>(); food.Clear(); spiders = new LIList <Spider>(); spiders.Clear(); ants = new LIList <Ant>(); ants.Clear(); rain = null; queen = new Queen(new Position(AntHillConfig.queenXPosition, AntHillConfig.queenYPosition)); }
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 bool DeleteRain() { rain = null; return(true); }
private bool CreateRain(Position point) { rain = new Rain(point); return(true); }
private void openGLControl_Paint(object sender, PaintEventArgs ea) { counter.FrameTick(); //Gl.glClearColor(0, 0, 0, 0); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); if (!cbVisualize.Checked) { return; } Gl.glLoadIdentity(); Glu.gluLookAt(0, AntHillConfig.curMagnitude * 10.0f, AntHillConfig.curMagnitude * -20.0f, 0, 0, 0, 0, -1, 0); //0.5f * Math.Sqrt(2), 0.5f * Math.Sqrt(2)); Gl.glRotated(lookAtAngleX, 1.0d, 0.0d, 0.0d); Gl.glRotated(lookAtAngleY, 0.0d, 1.0d, 0.0d); if (Simulation.simulation == null) { return; } Map map = Simulation.simulation.Map; int signal; Gl.glColor4f(1, 1, 1, 1); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { //if (ShouldOmitDrawing(x, y)) continue; DrawElement(x, y, map.GetTile(x, y).GetTexture(), Dir.N, offsetX, offsetY, 1, 1, 0.0f); } } for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { //if (ShouldOmitDrawing(x, y)) continue; if ((signal = map.MsgCount[x, y].GetCount(MessageType.FoodLocalization)) > 0) { Gl.glColor4f(1, 1, 1, (float)(signal + AntHillConfig.signalInitialAlpha) / AntHillConfig.signalHighestDensity); DrawElement(x, y, (int)AHGraphics.Texture.MessageFoodLocation, Dir.N, offsetX, offsetY, 1, 1, 0.01f); } if ((signal = map.MsgCount[x, y].GetCount(MessageType.QueenInDanger)) > 0) { Gl.glColor4f(1, 1, 1, (float)(signal + AntHillConfig.signalInitialAlpha) / AntHillConfig.signalHighestDensity); DrawElement(x, y, (int)AHGraphics.Texture.MessageQueenInDanger, Dir.N, offsetX, offsetY, 1, 1, 0.01f); } if ((signal = map.MsgCount[x, y].GetCount(MessageType.QueenIsHungry)) > 0) { Gl.glColor4f(1, 1, 1, (float)(signal + AntHillConfig.signalInitialAlpha) / AntHillConfig.signalHighestDensity); DrawElement(x, y, (int)AHGraphics.Texture.MessageQueenIsHungry, Dir.N, offsetX, offsetY, 1, 1, 0.01f); } if ((signal = map.MsgCount[x, y].GetCount(MessageType.SpiderLocalization)) > 0) { Gl.glColor4f(1, 1, 1, (float)(signal + AntHillConfig.signalInitialAlpha) / AntHillConfig.signalHighestDensity); DrawElement(x, y, (int)AHGraphics.Texture.MessageSpiderLocation, Dir.N, offsetX, offsetY, 1, 1, 0.01f); } } } Gl.glColor4f(1, 1, 1, 1); Creature e; Food f; LIList <Ant> .Enumerator enumerator = Simulation.simulation.ants.GetEnumerator(); while (enumerator.MoveNext()) { e = enumerator.Current; //if (ShouldOmitDrawing(e.Position.X, e.Position.Y)) continue; DrawElement(e.Position.X, e.Position.Y, e.GetTexture(), e.Direction, offsetX, offsetY, 1, 1, 0.02f); } LIList <Spider> .Enumerator enumeratorSpider = Simulation.simulation.spiders.GetEnumerator(); while (enumeratorSpider.MoveNext()) { e = enumeratorSpider.Current; //if (ShouldOmitDrawing(e.Position.X, e.Position.Y)) continue; DrawElement(e.Position.X, e.Position.Y, e.GetTexture(), e.Direction, offsetX, offsetY, 1, 1, 0.02f); } LIList <Food> .Enumerator enumeratorFood = Simulation.simulation.food.GetEnumerator(); while (enumeratorFood.MoveNext()) { f = enumeratorFood.Current; //if (ShouldOmitDrawing(f.Position.X, f.Position.Y)) continue; DrawElement(f.Position.X, f.Position.Y, f.GetTexture(), Dir.N, offsetX, offsetY, 1, 1, 0.015f); } e = Simulation.simulation.queen; if (e != null)// && !ShouldOmitDrawing(e.Position.X, e.Position.Y)) { DrawElement(e.Position.X, e.Position.Y, e.GetTexture(), e.Direction, offsetX, offsetY, 1, 1, 0.025f); } //deszcz Rain rain = Simulation.simulation.rain; if (rain != null) { DrawElement(rain.Position.X, rain.Position.Y, rain.GetTexture(), Dir.N, offsetX, offsetY, AntHillConfig.rainWidth, AntHillConfig.rainWidth, 1.0f); } }