Exemple #1
0
    // mask some moves as not possible
    public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
    {
        // contains the list of disallowed sheep/moves by number (see: OnActionReceived)
        List <int>  notAllowed           = new List <int>();
        List <bool> perSheepAllowedMoves = new List <bool>();

        for (int i = 0; i < gameManager.sheep.Length; i++)
        {
            // grab the sheep controller
            SheepController  sheep  = gameManager.sheep[i].GetComponent <SheepController>();
            SquareController square = sheep.Square().GetComponent <SquareController>();

            // Get List<bool> of possible moves (true = allowed, false = not allowed)
            // Order is (must match above!):
            // row: 1, col: -1 = 0
            // row: 1, col: 1= 1
            perSheepAllowedMoves = square.PossibleSheepMovesDir();

            // for any false, add the index (or index+1) into notAllowed list
            for (int j = 0; j < perSheepAllowedMoves.Count; j++)
            {
                if (!perSheepAllowedMoves[j])
                {
                    notAllowed.Add(2 * i + j);
                }
            }
        }

        actionMasker.SetMask(0, notAllowed);
    }
Exemple #2
0
    public override void Heuristic(float[] actionsOut)
    {
        List <bool> possibleMoves;

        // pick random sheep that can move
        SheepController shController;
        int             sheepIndex = randomSheepWithMoves(out shController);

        if (!shController)
        {
            return;
        }
        ;

        SquareController sheepSquareController = shController.Square().GetComponent <SquareController>();

        // pick random move
        possibleMoves = sheepSquareController.PossibleSheepMovesDir();

        int matched   = 0;
        int moveIndex = 0;

        for (int i = 0; i < possibleMoves.Count; i++)
        {
            if (possibleMoves[i])
            {
                matched++;

                if (Random.value < 1 / matched)
                {
                    moveIndex = i;
                }
            }
        }

        actionsOut[0] = 2 * sheepIndex + moveIndex;
    }