Пример #1
0
    public int Act(ref WindjermanGameState gs, NativeList <int> availableActions)
    {
        var job = new RandomRolloutJob
        {
            availableActions       = availableActions,
            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(availableActions.Length, 1);

        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);
    }
Пример #2
0
        public Intent Act(ref GameStateData gs, int id)
        {
            var job = new RandomRolloutJob
            {
                gs = gs,
                intent = new NativeArray<ActionsAvailable>(2, Allocator.TempJob),
                rdmAgent = new RandomAgent
                {
                    rdm = new Random((uint) Time.frameCount)
                },
                id = id
            };
            var handle = job.Schedule();
            handle.Complete();

            intent.moveIntent = job.intent[0];
            intent.actionIntent = job.intent[1];

            job.intent.Dispose();
            return intent;
        }
Пример #3
0
    public ActionsTypes Act(ref GameState gs, NativeArray <ActionsTypes> availableActions, int playerId)
    {
        var job = new RandomRolloutJob
        {
            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(availableActions.Length, 1);

        handle.Complete();

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

        for (var i = 0; i < job.summedScores.Length; i++)
        {
            if (bestScore > job.summedScores[i])
            {
                continue;
            }
            //  Debug.Log(availableActions[i] + " : " + job.summedScores[i]);
            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;
            }
        }

        ActionsTypes chosenAction;

        if (!same)
        {
            chosenAction = availableActions[bestActionIndex];
        }
        else
        {
            chosenAction = job.rdmAgent.Act(ref gs, availableActions);
        }
        if (playerId == 0)
        {
            Debug.Log(chosenAction);
        }
        job.summedScores.Dispose();

        return(chosenAction);
    }