Ejemplo n.º 1
0
        private ECell selectEmptyCell()
        {
            ECell cell;

            do
            {
                cell = cells[MRandom.Next(1, ESetting.GRID_SIZE_X - 2), MRandom.Next(1, ESetting.GRID_SIZE_Y - 2)];
            }while (cell.type != ECellType.EMPTY);

            return(cell);
        }
Ejemplo n.º 2
0
        public void DoRecovery(ECell cell)
        {
            //_genom = "";
            _checkSum = String.Empty;
            _point    = cell.point;

            _course      = (MOrientation)MRandom.Next(Enum.GetValues(typeof(MOrientation)).Length);
            _generation += 1;
            _health      = ESetting.BOT_HEALTH_BIRTH;

            _dieByToxin = false;

            _address = 0;

            return;
        }
Ejemplo n.º 3
0
        public void DoMutation(int count)
        {
            _checkSum = String.Empty;
            for (int i = 0; i < count; i++)
            {
                int  attempt = 0;
                byte addr;
                byte cmd = (byte)MRandom.Next(ESetting.BOT_COMMAND_SIZE);

                do
                {
                    attempt += 1;
                    addr     = (byte)MRandom.Next(ESetting.BOT_PROGRAM_SIZE);
                }while (calls[addr] == 0 || attempt <= 8);

                if (program[addr] != cmd)
                {
                    program[addr] = cmd;
                    _generation   = 1;
                }
            }

            return;
        }
Ejemplo n.º 4
0
        public void DoRecovery(ECell cell, EBot sampleBot)
        {
            //_genom = "";
            _checkSum = String.Empty;
            _point    = cell.point;

            _course     = (MOrientation)MRandom.Next(Enum.GetValues(typeof(MOrientation)).Length);
            _generation = sampleBot.generation;
            _health     = ESetting.BOT_HEALTH_BIRTH;

            _dieByToxin = false;

            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                program[i] = sampleBot.program[i];
            }
            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                calls[i] = sampleBot.calls[i];
            }
            _address = 0;

            return;
        }
Ejemplo n.º 5
0
        /*
         * public string checkSum
         * {
         *  get
         *  {
         *      string pid = "";
         *      for (int i = 0; i < program.Length; i++)
         *      {
         *          pid += program[i].ToString("D2");
         *      }
         *
         *      return pid;
         *
         *
         *      //int cs = 0;
         *      //for (int i = 0; i < program.Length; i++) cs += program[i];
         *
         *      //return cs;
         *
         *  }
         * }
         */

        /*
         * public string programid
         * {
         *  get
         *  {
         *      string pid = "";
         *      for (int i = 0; i < program.Length; i++)
         *      {
         *          pid += program[i].ToString("D2");
         *      }
         *
         *      return pid;
         *  }
         * }
         *
         * public void SetHistoryProgram(EProgram program)
         * {
         *  _historyProgram = program;
         * }
         */
        /*
         * public string uid
         * {
         *  get
         *  {
         *      string u = "g" + generation.ToString() + "|p";
         *      for (int i = 0; i < program.Length; i++)
         *      {
         *          u += program[i].ToString("D2");
         *      }
         *
         *      return u;
         *  }
         * }
         */

        public EBot(ECell cell)
        {
            //_genom = "";
            _checkSum = String.Empty;
            _point    = cell.point;

            _course     = (MOrientation)MRandom.Next(Enum.GetValues(typeof(MOrientation)).Length);
            _generation = 1;
            _health     = ESetting.BOT_HEALTH_BIRTH;

            _dieByToxin = false;

            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                program[i] = (byte)MRandom.Next(ESetting.BOT_COMMAND_SIZE);
            }
            for (int i = 0; i < ESetting.BOT_PROGRAM_SIZE; i++)
            {
                calls[i] = 0;
            }
            _address = 0;

            return;
        }
Ejemplo n.º 6
0
        public static bool Probability(int percent)
        {
            int p = MRandom.Next(100);

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