示例#1
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);
            }
        }
示例#2
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);
        }