Esempio n. 1
0
    //public override void doAction(ProcessContext context)
    //{
    //    int[] paramIndices = getParameterIndices(currentIndex, instructions);
    //    if (testCondition(bc, currentIndex, instructions))
    //    {
    //        int param3 = paramIndices[2];
    //        instructions[param3]
    //           .doAction(bc, param3, instructions);
    //    }
    //    else
    //    {
    //        int param4 = paramIndices[3];
    //        instructions[param4]
    //            .doAction(bc, param4, instructions);
    //    }
    //}

    public override bool testCondition(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        //Process the comparator
        int   param1 = paramIndices[0];
        float and1   = context.instruction(param1)
                       .instructionToNumber(context.context(param1));
        int   param2 = paramIndices[1];
        float and2   = context.instruction(param2)
                       .instructionToNumber(context.context(param2));

        if (lessThan)
        {
            if (and1 < and2)
            {
                return(true);
            }
        }
        if (greaterThan)
        {
            if (and1 > and2)
            {
                return(true);
            }
        }
        if (equalTo)
        {
            if (and1 == and2)
            {
                return(true);
            }
        }
        return(false);
    }
Esempio n. 2
0
    public override void doAction(ProcessContext context)
    {
        int[] paramIndices   = getParameterIndices(context);
        int   param1         = paramIndices[0];
        int   memoryLocation = (int)context.instruction(param1)
                               .instructionToNumber(context.context(param1));
        BotController bc = context.botController;

        switch (option)
        {
        case Option.STORE:
            int    param2      = paramIndices[1];
            object storeObject = context.instruction(param2)
                                 .getReturnObject(context.context(param2));
            if (!bc.memory.ContainsKey(memoryLocation))
            {
                bc.memory.Add(memoryLocation, storeObject);
            }
            else
            {
                bc.memory[memoryLocation] = storeObject;
            }
            Debug.Log("Stored[" + memoryLocation + "]: " + bc.memory[memoryLocation]);
            break;

        case Option.ERASE:
            bc.memory.Remove(memoryLocation);
            break;
        }
    }
    public void updateInstructionMap(ProcessContext context, ref ProcessedAs[] processMap)
    {
        if (context.instruction() == null)
        {
            return;
        }
        ProcessedAs currentPA = processMap[context.Index];

        if (currentPA == ProcessedAs.CONSTANT)
        {
            return;
        }
        if (currentPA == ProcessedAs.DO_NOTHING)
        {
            if (returnTypes.Count > 0)
            {
                currentPA = processMap[context.Index] = ProcessedAs.QUERY;
            }
            if (command)
            {
                currentPA = processMap[context.Index] = ProcessedAs.COMMAND;
            }
        }
        int lastIndex = context.next(context.Index, false);

        for (int i = 0; i < parameters.Count; i++)
        {
            if (lastIndex >= context.Count)
            {
                //don't re-paint-process the instructions at the beginning
                break;
            }
            if (validParameter(parameters[i], context.instruction(lastIndex)))
            {
                if (parameters[i] == ReturnType.NONE &&
                    context.instruction(lastIndex).command)
                {
                    processMap[lastIndex] = ProcessedAs.COMMAND;
                }
                else
                {
                    processMap[lastIndex] = ProcessedAs.QUERY;
                }
                lastIndex = context.getLastParameterIndex(lastIndex);
            }
            else
            {
                processMap[lastIndex] = ProcessedAs.CONSTANT;
            }
            lastIndex = context.next(lastIndex, false);
        }
    }
Esempio n. 4
0
    public override float instructionToNumber(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        int   param1       = paramIndices[0];
        int   param2       = paramIndices[1];

        return(Vector3.Distance(
                   context.instruction(param1).
                   instructionToPosition(context.context(param1)),
                   context.instruction(param2).
                   instructionToPosition(context.context(param2))
                   ));
    }
Esempio n. 5
0
    public override void doAction(ProcessContext context)
    {
        BotController bc = context.botController;

        int[]   paramIndices = getParameterIndices(context);
        int     param1       = paramIndices[0];
        Vector2 direction    = context.instruction(param1)
                               .instructionToDirection(context.context(param1));

        direction = bc.transform.TransformDirection(direction);
        Entity entity = GridManager.nextObjectInDirection(
            bc.transform.position,
            direction,
            true
            );

        if (!entity)
        {
            return;
        }
        //If object is within range,
        if (Vector2.Distance(bc.transform.position, entity.transform.position) <= 1)
        {
            //Push it
            Vector2 newPos = GridManager.moveObject(entity.gameObject, (Vector2)entity.transform.position + direction);
            if (entity is BotController)
            {
                entity.transform.position = newPos;
            }
        }
    }
Esempio n. 6
0
 public override void doAction(ProcessContext context)
 {
     int[] paramIndices = getParameterIndices(context);
     if (testCondition(context))
     {
         int param2 = paramIndices[1];
         context.instruction(param2)
         .doAction(context.context(param2));
     }
     else
     {
         int param3 = paramIndices[2];
         context.instruction(param3)
         .doAction(context.context(param3));
     }
 }
Esempio n. 7
0
    public override bool testCondition(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        int   param1       = paramIndices[0];

        return(context.instruction(param1)
               .testCondition(context.context(param1)));
    }
Esempio n. 8
0
    private int getMemoryLocation(ProcessContext context)
    {
        int[] paramIndices   = getParameterIndices(context);
        int   param1         = paramIndices[0];
        int   memoryLocation = (int)context.instruction(param1)
                               .instructionToNumber(context.context(param1));

        Debug.Log("Getting memory location[" + memoryLocation + "]");
        return(memoryLocation);
    }
    public override Vector2 instructionToPosition(ProcessContext context)
    {
        int[]  paramIndices = getParameterIndices(context);
        int    param1       = paramIndices[0];
        Entity entity       = context.instruction(param1)
                              .instructionToEntity(context.context(param1));

        if (entity)
        {
            return(entity.transform.position);
        }
        return(base.instructionToPosition(context));
    }
Esempio n. 10
0
    public int getLastParameterIndex(ProcessContext context)
    {
        int lastIndex = context.next();

        for (int i = 0; i < parameters.Count; i++)
        {
            if (validParameter(parameters[i], context.instruction(lastIndex)))
            {
                lastIndex = context.getLastParameterIndex(lastIndex);
            }
            lastIndex = context.next(lastIndex);
        }
        lastIndex = context.prev(lastIndex);
        return(lastIndex);
    }
Esempio n. 11
0
    public int[] getParameterIndices(ProcessContext context)
    {
        int[] paramIndices = new int[parameters.Count];
        int   paramIndex   = context.next();

        for (int i = 0; i < parameters.Count; i++)
        {
            paramIndices[i] = paramIndex;
            if (validParameter(parameters[i], context.instruction(paramIndex)))
            {
                paramIndex = context.getLastParameterIndex(paramIndex);
            }
            paramIndex = context.next(paramIndex);
        }
        return(paramIndices);
    }
Esempio n. 12
0
    public override void doAction(ProcessContext context)
    {
        int[]   paramIndices = getParameterIndices(context);
        int     param1       = paramIndices[0];
        Vector3 position     = context.instruction(param1).
                               instructionToPosition(context.context(param1));
        Vector2       moveDir = Vector2.zero;
        BotController bc      = context.botController;

        switch (option)
        {
        case Option.TOWARDS:
            moveDir = (position - bc.transform.position).normalized;
            break;

        case Option.AWAY:
            moveDir = (bc.transform.position - position).normalized;
            break;
        }
        bc.moveDirection += bc.transform.InverseTransformDirection(moveDir);
    }
Esempio n. 13
0
    public override Entity instructionToEntity(ProcessContext context)
    {
        if (option == Option.SELF)
        {
            return(context.botController);
        }
        if (option == Option.IN_DIRECTION)
        {
            int[]   paramIndices = getParameterIndices(context);
            int     param1       = paramIndices[0];
            Vector2 direction    = context.instruction(param1)
                                   .instructionToDirection(context.context(param1));
            Entity entity = GridManager.nextObjectInDirection(
                context.botController.transform.position,
                context.botController.transform.TransformDirection(direction),
                true
                );
            return(entity);
        }
        //Get the target type string
        string targetTypeString = typeof(BotController).Name;

        if (entityType != EntityType.BOT)
        {
            targetTypeString = typeof(AreaTile).Name + "." + entityType;
        }
        //
        float  extreme = (option == Option.CLOSEST) ? float.MaxValue : 0;
        Entity target  = null;

        foreach (Entity fbc in FindObjectsOfType <Entity>())
        {
            if (fbc != context.botController &&
                fbc.getTypeString() == targetTypeString)
            {
                float distance = Vector3.Distance(
                    context.botController.transform.position,
                    fbc.transform.position
                    );
                switch (option)
                {
                case Option.CLOSEST:
                    if (distance < extreme)
                    {
                        extreme = distance;
                        target  = fbc;
                    }
                    break;

                case Option.FURTHEST:
                    if (distance > extreme)
                    {
                        extreme = distance;
                        target  = fbc;
                    }
                    break;
                }
            }
        }
        return(target);
    }
Esempio n. 14
0
 public virtual float instructionToNumber(ProcessContext context)
 {
     return(context.botController.alphabet.IndexOf(
                context.instruction()
                ));
 }