Ejemplo n.º 1
0
        public EResultGeneration(EGrid grid)
        {
            generation = grid.generation;
            resultBots = new List <EResultGenerationBot>();

            foreach (EBot bot in grid.bots)
            {
                if (bot.alive)
                {
                    resultBots.Add(new EResultGenerationBot(bot));
                }
            }

            /*
             * resultBots.Sort(
             *  delegate (EResultGenerationBot b1, EResultGenerationBot b2)
             *  {
             *      int compare = b2.generation.CompareTo(b1.generation);
             *
             *      if (compare == 0) compare = b2.health.CompareTo(b1.health);
             *
             *      return compare;
             *  }
             * );
             */
        }
Ejemplo n.º 2
0
        public EHistoryItem(EGrid grid)
        {
            generation = grid.generation;
            iteration  = grid.iteration;

            countDieByToxin = grid.CalcDieByToxin();
            averageHealth   = grid.AverageHealth();
        }
Ejemplo n.º 3
0
        public EResultIteration(EGrid grid)
        {
            iteration = grid.iteration;
            countBot  = grid.CalcBots();
            Tuple <int, int> ft = grid.CalcFoodToxin();

            countFood  = ft.Item1;
            countToxin = ft.Item2;

            countDieByToxin = grid.CalcDieByToxin();
            averageHealth   = grid.AverageHealth();
        }
Ejemplo n.º 4
0
        public void DoRun(EGrid grid)
        {
            int steps = 0;

            _health -= 1;

            while (steps < ESetting.BOT_PROGRAM_STEP_MAX)
            {
                steps += doCommand(grid);
            }

            return;
        }
Ejemplo n.º 5
0
        public void Add(EGrid grid)
        {
            EHistoryItem item = new EHistoryItem(grid);

            _items.Insert(0, item);

            if (_bestItem.iteration < item.iteration)
            {
                _bestItem = item;
            }
            else if (_bestItem.iteration == item.iteration)
            {
                if (_bestItem.averageHealth < item.averageHealth)
                {
                    _bestItem = item;
                }
            }

            return;
        }
Ejemplo n.º 6
0
 public Evo2Engine()
 {
     _eGrid = new EGrid();
 }
Ejemplo n.º 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);
        }