예제 #1
0
        private void Draw(Box box)
        {
            Gl.glLoadIdentity();
            //            Gl.glTranslatef(box.Position.X, box.Position.Y, -6f);
            var ratio = 0.03f;
            Gl.glTranslatef(box.X * ratio, box.Y * ratio, -6f);

            var color = box.Color;

            this.SetGlColor(color);

            Gl.glRotatef(box.Rotation, 0.0f, 0.0f, 1.0f);
            Gl.glBegin(Gl.GL_QUADS);
            var z = 0.0f;
            var width = box.Width * ratio * 0.5f;
            var height = box.Height * ratio * 0.5f;
            Gl.glVertex3f(-width, height, z);
            Gl.glVertex3f(width, height, z);
            Gl.glVertex3f(width, -height, z);
            Gl.glVertex3f(-width, -height, z);
            Gl.glEnd();
        }
예제 #2
0
        public void Run()
        {
            this.Initialize();
            this.Reshape();
            this.InitGL();
            this.worldObjects.Add(new Box(60, 120));
            this.worldObjects.Add(new Box(10, 10, 0 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 10 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 20 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 31 - 30 + 5, 0 + 60 - 5));

               // Gene length 2 - just X and Y position
               algorithm = new Algorithm();
               for (int i = 0; i < 10; ++i)
               {
               var box1 = new Box(10, 10);
               algorithm.AddBox(box1);
               }
               algorithm.Run();

            Events.Run();
        }
예제 #3
0
 public void AddBox(Box box)
 {
     cargo.Add(box);
 }
예제 #4
0
        private void Events_Tick(object sender, TickEventArgs e)
        {
            algorithm.Epoch();
            this.worldObjects.RemoveRange(1, this.worldObjects.Count - 1);
            var ground = (Box)this.worldObjects[0];
            var decode = this.algorithm.Best.Decode();
            for (int i = 0; i < this.algorithm.Cargo.Count; i++)
            {
                var pos = decode[i];
                var box = this.algorithm.Cargo[i];
                var newBox = new Box(box.Width, box.Height);

                newBox.X = pos.X - (ground.Width / 2) + (newBox.Width / 2);
                newBox.Y = -1 * pos.Y + (ground.Height / 2) - (newBox.Height / 2);
                newBox.Color = box.Color;
                this.worldObjects.Add(newBox);
            }

            this.DrawScene();
            Video.GLSwapBuffers();
        }
예제 #5
0
        private bool Overlaps(Box box)
        {
            bool result = false;
            foreach (var cargoBox in this.cargo)
            {
                if (cargoBox != box)
                {
                    result = box.Overlaps(cargoBox);
                }
            }

            return result;
        }