Esempio n. 1
0
        private void generateProgram(Bot parentBot)
        {
            address   = 0;
            program   = new byte[Const.BOT_PROGRAM_SIZE];
            cmd_calls = new int[Const.BOT_PROGRAM_SIZE];


            for (int i = 0; i < Const.BOT_PROGRAM_SIZE; i++)
            {
                cmd_calls[i] = 0;
            }
            if (parentBot != null)
            {
                for (int i = 0; i < Const.BOT_PROGRAM_SIZE; i++)
                {
                    program[i] = parentBot.program[i];
                }
            }
            else
            {
                //DEBUG
                //for (int i = 0; i < Const.BOT_PROGRAM_SIZE; i++) program[i] = (byte)MRandom.Next(24);
                for (int i = 0; i < Const.BOT_PROGRAM_SIZE; i++)
                {
                    program[i] = (byte)MRandom.Next(Const.BOT_COMMAND_SIZE);
                }
            }

            return;
        }
Esempio n. 2
0
        private void createBots(List <Bot> parentBots)
        {
            bots = new List <Bot>();

            int x;
            int y;



            for (int i = 0; i < Const.BOT_COUNT_MAX; i++)
            {
                do
                {
                    x = MRandom.Next(1, Const.GRID_SIZE_X - 2);
                    y = MRandom.Next(1, Const.GRID_SIZE_Y - 2);
                } while (Grid.CurrentGrid.cells[x, y].content != CellContentType.EMPTY);



                Bot bot;
                if (parentBots != null)
                {
                    Bot parentBot = parentBots[i % Const.BOT_COUNT_MIN];
                    bot = new Bot(x, y, parentBot);

                    if (i >= 16 && i < 24)
                    {
                        bot.DoMutation(1, parentBot);
                    }
                    if (i >= 32 && i < 40)
                    {
                        bot.DoMutation(1, parentBot);
                    }
                    if (i >= 48 && i < 56)
                    {
                        bot.DoMutation(1, parentBot);
                    }

                    //if (i >= 24 && i < 32) bot.DoMutation(2, parentBot);
                    //if (i >= 32 && i < 40) bot.DoMutation(2, parentBot);
                    //if (i >= 0 && i < 8) bot.program[0] = (byte)MRandom.Next(Const.BOT_COMMAND_SIZE);
                }
                else
                {
                    bot = new Bot(x, y);
                }



                bots.Add(bot);
                Grid.CurrentGrid.cells[x, y].SetContent(CellContentType.BOT);
            }


            return;
        }
Esempio n. 3
0
        /*
         * private void createFood()
         * {
         *  int x;
         *  int y;
         *
         *  for (int i = 0; i < Const.FOOD_COUNT; i++)
         *  {
         *      do
         *      {
         *          x = MRandom.Next(1, Const.GRID_SIZE_X - 2);
         *          y = MRandom.Next(1, Const.GRID_SIZE_Y - 2);
         *
         *      } while (Grid.CurrentGrid.cells[x, y].content != CellContentType.EMPTY);
         *
         *      Grid.CurrentGrid.cells[x, y].SetContent(CellContentType.FOOD);
         *  }
         * }
         *
         * private void createToxin()
         * {
         *  int x;
         *  int y;
         *
         *  for (int i = 0; i < Const.TOXIN_COUNT; i++)
         *  {
         *      do
         *      {
         *          x = MRandom.Next(1, Const.GRID_SIZE_X - 2);
         *          y = MRandom.Next(1, Const.GRID_SIZE_Y - 2);
         *
         *      } while (Grid.CurrentGrid.cells[x, y].content != CellContentType.EMPTY);
         *
         *      Grid.CurrentGrid.cells[x, y].SetContent(CellContentType.TOXIN);
         *  }
         * }
         */

        public void CreateFoodToxin(int count)
        {
            int x;
            int y;

            for (int i = 0; i < count; i++)
            {
                do
                {
                    x = MRandom.Next(1, Const.GRID_SIZE_X - 2);
                    y = MRandom.Next(1, Const.GRID_SIZE_Y - 2);
                } while (Grid.CurrentGrid.cells[x, y].content != CellContentType.EMPTY);

                bool isFood = MRandom.Probability(Const.FOOD_PROBABILITY);
                Grid.CurrentGrid.cells[x, y].SetContent(isFood ? CellContentType.FOOD : CellContentType.TOXIN);
            }
        }
Esempio n. 4
0
        public Bot(int x, int y, Bot parentBot)
        {
            point = new MPoint(x, y);

            //DEBUG
            //courseOrientation = OrientationType.TOP;
            courseOrientation = (OrientationType)MRandom.Next(Enum.GetValues(typeof(OrientationType)).Length);

            health    = Const.BOT_HEALTH_BIRTH;
            iteration = 0;
            age       = (parentBot != null ? parentBot.age + 1 : 1);

            generateProgram(parentBot);

            dieByToxin = false;

            return;
        }
Esempio n. 5
0
        public void DoMutation(int count, Bot parentBot)
        {
            for (int i = 0; i < count; i++)
            {
                byte addr;
                byte cmd = (byte)MRandom.Next(Const.BOT_COMMAND_SIZE);

                do
                {
                    addr = (byte)MRandom.Next(Const.BOT_PROGRAM_SIZE);
                }while (parentBot.cmd_calls[addr] == 0);

                //cmd = (byte)((program[addr] + cmd) % Const.BOT_COMMAND_SIZE);
                program[addr] = cmd;
            }

            address = 0;
            age     = 1;
        }
Esempio n. 6
0
        public static bool Probability(int percent)
        {
            int p = MRandom.Next(100);

            return(p < percent);
        }
Esempio n. 7
0
 public static int Next(int size)
 {
     return(MRandom.Next(0, size - 1));
 }