Example #1
0
        private void drawPrograms()
        {
            try
            {
                Graphics g = _pbProgramBufferGraphics.Graphics;

                g.Clear(SystemColors.Control);
                //g.Clear(Color.Red);



                EBot[] traceBots = new EBot[ESetting.BOT_COUNT_MIN];
                foreach (EBot bot in _evoEngine.eGrid.bots)
                {
                    for (int i = 0; i < ESetting.BOT_COUNT_MIN; i++)
                    {
                        if (bot.traceIndex == i)
                        {
                            traceBots[i] = bot;
                        }
                    }
                }



                int size     = 280;
                int paddingX = 40;
                int paddingY = 64;


                for (int i = 0; i < 8; i++)
                {
                    int x = 1 + (i % 4) * (size + paddingX);
                    int y = 1 + paddingY + (i / 4) * (size + paddingY);



                    drawProgram(g, x, y, size, traceBots[i], ESetting.TRACE_COLOR[i]);
                }



                //_pbProgramBufferGraphics.Render();
                _pbProgramBufferGraphics.Render(pbProgram.CreateGraphics());
            }
            catch { }
        }
Example #2
0
        private void drawProgram(Graphics g, int x, int y, int size, EBot bot, Color traceColor)
        {
            if (bot == null)
            {
                return;
            }

            int iteration = _evoEngine.eGrid.iteration;



            Brush brushBG = new SolidBrush(traceColor);
            //Brush brushCMD = Brushes.White;
            Brush brushCMD_ADDR = new SolidBrush(traceColor);

            Font fontBot  = new Font(FontFamily.GenericSansSerif, 10.0F, FontStyle.Bold);
            Font fontBotP = new Font(FontFamily.GenericSansSerif, 5.0F, FontStyle.Regular);
            Font fontBotC = new Font(FontFamily.GenericSansSerif, 4.0F, FontStyle.Regular);


            Font fontBotTitle = new Font(FontFamily.GenericSansSerif, 9.0F, FontStyle.Bold);
            Font fontBotCoord = new Font(FontFamily.GenericSansSerif, 8.0F, FontStyle.Regular);

            Brush brushFontTitle = Brushes.Gray;
            Brush brushFontCoord = Brushes.Black;



            Brush brushFontW = Brushes.White;
            Brush brushFontB = Brushes.Black;


            Rectangle recBG = new Rectangle(x - 1, y - 1, size + 2, size + 2);
            Rectangle recCMD;
            Rectangle recCMD_ADDR;

            g.FillRectangle(brushBG, recBG);



            int csize = size / 8;
            int cx;
            int cy;


            int calls_max = 0;

            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                if (bot.calls[i] > calls_max)
                {
                    calls_max = bot.calls[i];
                }
            }

            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                int calls = bot.calls[i];


                int callIndex = 0;

                if (bot.calls[i] > 0)
                {
                    callIndex = 25 + 205 * bot.calls[i] / calls_max;
                }



                cx = x + (i % 8) * csize;
                cy = y + (i / 8) * csize;


                Brush bCMD = new SolidBrush(ESetting.GRAY_COLOR[callIndex]);

                recCMD      = new Rectangle(cx + 1, cy + 1, csize - 2, csize - 2);
                recCMD_ADDR = new Rectangle(cx + 5, cy + 5, csize - 10, csize - 10);

                //g.FillRectangle((i == bot.address ? brushCMD_ADDR : bCMD), recCMD);
                g.FillRectangle(bCMD, (i == bot.address ? recCMD_ADDR : recCMD));



                g.DrawString(bot.program[i].ToString(), fontBot, brushFontW, cx + csize / 4, cy + csize / 3);
                g.DrawString(bot.program[i].ToString(), fontBotP, (callIndex > 127 ? brushFontW : brushFontB), cx + 3, cy + 5);

                g.DrawString(bot.calls[i].ToString(), fontBotC, (callIndex > 127 ? brushFontW : brushFontB), cx + 3, cy + 25);
            }


            cx = x + 2;
            cy = y - 48;
            string title = String.Format("CS: {0}; G: {1}; H: {2}", bot.checkSum.Substring(0, 4), bot.generation, bot.health);

            g.DrawString(title, fontBotTitle, brushFontTitle, cx, cy);

            cx = x + 2;
            cy = y - 28;
            string coord = String.Format("(x,y) = ({0},{1}); course = {2}", bot.point.x, bot.point.y, bot.course.ToString());

            g.DrawString(coord, fontBotCoord, brushFontCoord, cx, cy);

            return;
        }
Example #3
0
        private void drawGrid()
        {
            if (_evoEngine == null)
            {
                return;
            }

            EGrid grid = _evoEngine.eGrid;

            //var brush = new SolidColorBrush(Color.FromArgb(255, (byte)R, (byte)G, (byte)B));
            //Brush bb = new SolidBrush(Color.Red);


            Color colorGrid  = Color.DarkGray;
            Brush brushWall  = Brushes.Maroon;
            Brush brushEmpty = Brushes.LightGray;
            Brush brushBot   = Brushes.Navy;
            Brush brushFood  = Brushes.Green;
            Brush brushToxin = Brushes.OrangeRed;

            Font  fontBot   = new Font(FontFamily.GenericSansSerif, 6.0F, FontStyle.Regular);
            Brush brushFont = Brushes.White;

            Font  fontBot2   = new Font(FontFamily.GenericSansSerif, 5.0F, FontStyle.Bold);
            Brush brushFont2 = Brushes.Yellow;

            Font  fontBot3   = new Font(FontFamily.GenericSansSerif, 7.0F, FontStyle.Bold);
            Brush brushFont3 = Brushes.Yellow;

            Graphics g = _pbGridBufferGraphics.Graphics;


            g.Clear(colorGrid);


            ECell[,] cells = grid.cells;

            int size = 24;

            for (int y = 0; y < ESetting.GRID_SIZE_Y; y++)
            {
                for (int x = 0; x < ESetting.GRID_SIZE_X; x++)
                {
                    int px = x * size + 1;
                    int py = y * size + 1;

                    Rectangle r  = new Rectangle(px + 1, py + 1, size - 2, size - 2);
                    Rectangle rc = new Rectangle(px + 3, py + 3, size - 6, size - 6);


                    if (cells[x, y].type == ECellType.EMPTY)
                    {
                        g.FillRectangle(brushEmpty, r);
                    }
                    if (cells[x, y].type == ECellType.WALL)
                    {
                        g.FillRectangle(brushWall, r);
                    }
                    if (cells[x, y].type == ECellType.FOOD)
                    {
                        g.FillRectangle(brushEmpty, r);
                        g.FillEllipse(brushFood, rc);
                    }
                    if (cells[x, y].type == ECellType.TOXIN)
                    {
                        g.FillRectangle(brushEmpty, r);
                        g.FillEllipse(brushToxin, rc);
                    }
                    if (cells[x, y].type == ECellType.BOT)
                    {
                        //
                        //
                    }
                }
            }

            for (int i = 0; i < grid.bots.Length; i++)
            {
                EBot bot = grid.bots[i];


                if (bot.alive)
                {
                    int px = bot.point.x * size + 1;
                    int py = bot.point.y * size + 1;


                    if (bot.traceIndex >= 0)
                    {
                        Brush     bTrace = new SolidBrush(ESetting.TRACE_COLOR[bot.traceIndex]);
                        Rectangle rTrace = new Rectangle(px - 2, py - 2, size + 4, size + 4);
                        g.FillRectangle(bTrace, rTrace);
                    }


                    Rectangle r = new Rectangle(px + 1, py + 1, size - 2, size - 2);
                    g.FillRectangle(brushBot, r);



                    g.DrawString(bot.health.ToString(), fontBot, brushFont, px + 1, py + 2);
                    g.DrawString(bot.generation.ToString(), fontBot2, brushFont2, px + 10, py + 12);

                    /*
                     * if (bot.traceIndex != -1)
                     * {
                     *  g.DrawString(bot.traceIndex.ToString(), fontBot3, brushFont3, px + 6, py + 10);
                     * }
                     */
                }
            }

            //_pbGridBufferGraphics.Render();
            _pbGridBufferGraphics.Render(pbGrid.CreateGraphics());

            return;
        }