/// <summary>
 /// Update MObject's variables
 /// </summary>
 public void UpdateObject(MOrientation orientation, Vector2 targetPosition, Vector3 targetForwardVector, bool isVisible, Vector2 toFollowMapCoord, float defaultScale, float scaleRatio, bool isScaling, bool isScalingSmoothly, float smoothScaleSpeed)
 {
     this._orientation = orientation;
     this._targetPosition = targetPosition;
     this._targetForwardVec = targetForwardVector;
     this._isVisible = isVisible;
     this._toFollowMapCoord = toFollowMapCoord;
     this._scaleRatio = scaleRatio;
     this._isScalingSmoothly = isScalingSmoothly;
     this._defaultScale = defaultScale;
     this._smoothScaleSpeed = smoothScaleSpeed;
 }
Esempio 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;
        }
    /// <summary>
    /// Calculates the current angle of a minimap object (e.g. MObject) based on the forward vector of the real-life object (e.g. MActor)
    /// </summary>
    /// <param name="objectForwardVec"></param>
    /// <returns></returns>
    public static float CalculateAngle(MOrientation orientation, Vector3 objectForwardVec)
    {
        float clockWise = 0.0f;
        switch (orientation)
        {
            case MOrientation.XZ:
                clockWise = Vector3.Dot(objectForwardVec, Vector3.Cross(Vector3.up, Vector3.forward));
                break;

            case MOrientation.YZ:
                clockWise = Vector3.Dot(objectForwardVec, Vector3.Cross(Vector3.right, Vector3.forward));
                break;
        }
        
        clockWise = clockWise > 0f ? -1f : 1f;
        return clockWise * Vector3.Angle(objectForwardVec, Vector3.forward);
    }
Esempio 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;
        }
Esempio 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;
        }
Esempio n. 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);
        }