예제 #1
0
        private void createWalls()
        {
            for (int x = 0; x < ESetting.GRID_SIZE_X; x++)
            {
                for (int y = 0; y < ESetting.GRID_SIZE_Y; y++)
                {
                    cells[x, y] = new ECell(x, y);

                    if (x == 0 || x == (ESetting.GRID_SIZE_X - 1) || y == 0 || y == (ESetting.GRID_SIZE_Y - 1))
                    {
                        cells[x, y].SetType(ECellType.WALL);
                    }

                    if (x == 9 && y >= 1 && y <= 7)
                    {
                        cells[x, y].SetType(ECellType.WALL);
                    }

                    if (x == 20 && y >= 8 && y <= 14)
                    {
                        cells[x, y].SetType(ECellType.WALL);
                    }
                }
            }
        }
예제 #2
0
        public void CreateFoodToxin(int count)
        {
            for (int i = 0; i < count; i++)
            {
                ECell cell = selectEmptyCell();

                bool isFood = MRandom.Probability(ESetting.FOOD_PROBABILITY);
                cell.SetType(isFood ? ECellType.FOOD : ECellType.TOXIN);
            }
        }
예제 #3
0
        private void createBots()
        {
            for (int i = 0; i < bots.Length; i++)
            {
                ECell cell = selectEmptyCell();
                bots[i] = new EBot(cell);

                _generationIndex[i] = i;
            }

            RecalculationBotTraceIndex();

            return;
        }
예제 #4
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;
        }
예제 #5
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;
        }
예제 #6
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;
        }
예제 #7
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);
        }