Exemple #1
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;
        }
Exemple #2
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;
        }
Exemple #3
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;
        }
Exemple #4
0
 public ECell(int x, int y)
 {
     _point = new MPoint(x, y);
     _type  = ECellType.EMPTY;
 }
Exemple #5
0
        public override bool Equals(object obj)
        {
            MPoint p = (MPoint)obj;

            return(p.x == x && p.y == y);
        }
Exemple #6
0
        private int doCommand(EGrid grid)
        {
            int  step    = 1;
            byte command = program[address];

            calls[address] = calls[address] + 1;

            if (command < 24)
            {
                ECell currentCell = grid.cells[point.x, point.y];

                MPoint targetPoint = point + ESetting.ORIENTATIONS[((int)_course + (command % 8)) % 8];
                ECell  targetCell  = grid.cells[targetPoint.x, targetPoint.y];

                _address += (byte)targetCell.type;

                if (command < 8)
                {
                    //
                    // ШАГНУТЬ
                    //

                    //if (targetCell.content == CellContentType.BOT) { }
                    //if (targetCell.content == CellContentType.EMPTY) { }
                    //if (targetCell.content == CellContentType.FOOD) { }
                    //if (targetCell.content == CellContentType.TOXIN) { }
                    //if (targetCell.content == CellContentType.WALL) { }



                    if (targetCell.type == ECellType.EMPTY)
                    {
                        _point = targetPoint;
                        currentCell.Clear();
                        targetCell.SetType(ECellType.BOT);
                    }
                    else if (targetCell.type == ECellType.FOOD)
                    {
                        _health = Math.Min(health + ESetting.BOT_HEALTH_FOOD, ESetting.BOT_HEALTH_MAX);
                        grid.CreateFoodToxin(1);

                        _point = targetPoint;
                        currentCell.Clear();
                        targetCell.SetType(ECellType.BOT);
                    }
                    else if (targetCell.type == ECellType.TOXIN)
                    {
                        _health     = 0;
                        _dieByToxin = true;
                        grid.CreateFoodToxin(1);

                        _point = targetPoint;
                        currentCell.Clear();
                        targetCell.SetType(ECellType.BOT);
                    }


                    step = ESetting.BOT_PROGRAM_STEP_MAX;
                }
                else if (command < 16)
                {
                    //
                    // ВЗЯТЬ ЕДУ / ПРЕОБРАЗОВАТЬ ЯД
                    //

                    //if (targetCell.content == CellContentType.BOT) { }
                    //if (targetCell.content == CellContentType.EMPTY) { }
                    //if (targetCell.content == CellContentType.FOOD) { }
                    //if (targetCell.content == CellContentType.TOXIN) { }
                    //if (targetCell.content == CellContentType.WALL) { }


                    if (targetCell.type == ECellType.FOOD)
                    {
                        _health = Math.Min(health + ESetting.BOT_HEALTH_FOOD, ESetting.BOT_HEALTH_MAX);
                        targetCell.Clear();
                        grid.CreateFoodToxin(1);
                    }
                    else if (targetCell.type == ECellType.TOXIN)
                    {
                        targetCell.SetType(ECellType.FOOD);
                    }

                    step = ESetting.BOT_PROGRAM_STEP_MAX;
                }
                else if (command < 24)
                {
                    //
                    // ПОСМОТРЕТЬ
                    //

                    //if (targetCell.content == CellContentType.BOT) { }
                    //if (targetCell.content == CellContentType.EMPTY) { }
                    //if (targetCell.content == CellContentType.FOOD) { }
                    //if (targetCell.content == CellContentType.TOXIN) { }
                    //if (targetCell.content == CellContentType.WALL) { }
                }
            }
            else if (command < 32)
            {
                //
                // ПОВЕРНУТЬСЯ
                //

                _address += 1;

                //if (targetCell.content == CellContentType.BOT) { }
                //if (targetCell.content == CellContentType.EMPTY) { }
                //if (targetCell.content == CellContentType.FOOD) { }
                //if (targetCell.content == CellContentType.TOXIN) { }
                //if (targetCell.content == CellContentType.WALL) { }

                _course = (MOrientation)(((int)_course + (command % 8)) % 8);
            }
            else
            {
                //
                // БЕЗУСЛОВНЫЙ ПЕРЕХОД в ПРОГРАММЕ
                //

                _address += command;
                //address += (byte)(command - 31);
                //address += (byte)(command - 31 + 6);
            }

            _address = (byte)(address % ESetting.BOT_PROGRAM_SIZE);

            return(step);
        }