Example #1
0
        public Intent Act(ref GameStateData gs, int id)
        {
            var job = new MCTSAgentJob
            {
                gs       = gs,
                sumScore = new NativeArray <int>(54, Allocator.TempJob),
                rdmAgent = new RandomAgent {
                    rdm = new Random((uint)Time.frameCount)
                },
                id = id
            };
            var handle = job.Schedule();

            handle.Complete();

            var bestActionIndex = -1;
            var bestScore       = long.MinValue;

            for (var i = 0; i < job.sumScore.Length; i++)
            {
                if (bestScore > job.sumScore[i])
                {
                    continue;
                }

                bestScore       = job.sumScore[i];
                bestActionIndex = i;
            }
            //var chosenAction = availableActions[bestActionIndex];

            /*for (int i = 0; i < job.sumScore.Length; i++)
             * {
             *  Debug.Log(i+" "+job.sumScore[i]);
             * }*/
            //Debug.Log(job.sumScore[0]);

            /*Debug.Log(job.sumScore[1]);
            *  Debug.Log(job.sumScore[2]);*/
            Intent chosenIntent = new Intent();

            chosenIntent.moveIntent   = (ActionsAvailable)(bestActionIndex / (int)ActionsAvailable.NONE);
            chosenIntent.actionIntent = (ActionsAvailable)((bestActionIndex % (int)ActionsAvailable.MOVE_BACK_LEFT) + (int)ActionsAvailable.MOVE_BACK_LEFT);
            job.sumScore.Dispose();
            Debug.Log((int)ActionsAvailable.MOVE_BACK_LEFT);
            Debug.Log(bestActionIndex);
            Debug.Log((int)chosenIntent.moveIntent);
            Debug.Log(chosenIntent.moveIntent);
            Debug.Log((int)chosenIntent.actionIntent);
            Debug.Log(chosenIntent.actionIntent);
            return(chosenIntent);
        }
Example #2
0
    public ActionsTypes Act(ref GameState gs, NativeArray <ActionsTypes> availableActions, int playerId)
    {
        var job = new MCTSAgentJob
        {
            availableActions = availableActions,
            gs           = gs,
            summedScores = new NativeArray <long>(availableActions.Length, Allocator.TempJob),
            rdmAgent     = new RandomAgent {
                rdm = new Random((uint)Time.frameCount + (uint)playerId)
            },
            playerId       = playerId,
            gameParameters = GameParameters.Instance.Parameters
        };

        var handle = job.Schedule();

        handle.Complete();

        int bestActionIndex = -1;
        var bestScore       = long.MinValue;

        for (var i = 0; i < job.summedScores.Length; i++)
        {
            if (bestScore > job.summedScores[i])
            {
                continue;
            }

            bestScore       = job.summedScores[i];
            bestActionIndex = i;
        }
        // Check if all value are same
        var  value = job.summedScores[0];
        bool same  = true;

        for (int i = 1; i < job.summedScores.Length; i++)
        {
            same = job.summedScores[i] == value ? true : false;
            if (!same)
            {
                break;
            }
        }

        var chosenAction = availableActions[bestActionIndex];

        Debug.Log("chosenAction:" + chosenAction);
        job.summedScores.Dispose();
        return(chosenAction);
    }
Example #3
0
    public int Act(ref WindjermanGameState gs, NativeList <int> availableActions)
    {
        var job = new MCTSAgentJob
        {
            availableActionsFree   = Rules.AvailableActionsFree,
            availableActionsStun   = Rules.AvailableActionsStun,
            availableActionsFrozen = Rules.AvailableActionsFrozen,
            gs           = gs,
            summedScores = new NativeArray <long>(availableActions.Length, Allocator.TempJob),
            rdmAgent     = new RandomAgent {
                rdm = new Unity.Mathematics.Random((uint)Time.frameCount)
            },
            Playerid = PlayerID
        };

        var handle = job.Schedule();

        handle.Complete();


        var bestActionIndex = -1;
        var bestScore       = long.MinValue;

        for (var i = 0; i < job.summedScores.Length; i++)
        {
            if (bestScore > job.summedScores[i])
            {
                continue;
            }

            bestScore       = job.summedScores[i];
            bestActionIndex = i;
        }

        var chosenAction = availableActions[bestActionIndex];

        job.summedScores.Dispose();
        return(chosenAction);
    }