Esempio n. 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);
    }
Esempio n. 2
0
    public override void CollectObservations(VectorSensor sensor)
    {
        // space size: 10
        // current positions: 2
        wolfSquareController = wolf.Square().GetComponent <SquareController>();

        sensor.AddObservation(wolfSquareController.column / (float)gameManager.columns);
        sensor.AddObservation(wolfSquareController.row / (float)gameManager.rows);

        // position of the sheep: 4 x (1+1) = 8
        foreach (SheepController shp in gameManager.sheep)
        {
            SheepController shpController = shp.GetComponent <SheepController>();
            shpSquareController = shpController.Square().GetComponent <SquareController>();

            sensor.AddObservation(shpSquareController.column / (float)gameManager.columns);
            sensor.AddObservation(shpSquareController.row / (float)gameManager.rows);
        }

        haveObservation = true;
    }
Esempio n. 3
0
    public override void OnActionReceived(float[] branches)
    {
        if (!haveObservation)
        {
            return;
        }

        // 1 branch
        //  0 = {sheep = 0; row = 1; col = -1}
        //  1 = {sheep = 0; row = 1; col = 1}
        //  2 = {sheep = 1; row = 1; col = -1}
        //  3 = {sheep = 1; row = 1; col = 1}
        //  4 = {sheep = 2; row = 1; col = -1}
        //  5 = {sheep = 2; row = 1; col = 1}
        //  6 = {sheep = 3; row = 1; col = -1}
        //  7 = {sheep = 3; row = 1; col = 1}
        int selection = Mathf.FloorToInt(branches[0]);


        int sheep = 0, row = 0, col = 0;

        // which way to go
        if (selection == 0)
        {
            sheep = 0; row = 1; col = -1;
        }
        ;
        if (selection == 1)
        {
            sheep = 0; row = 1; col = 1;
        }
        ;
        if (selection == 2)
        {
            sheep = 1; row = 1; col = -1;
        }
        ;
        if (selection == 3)
        {
            sheep = 1; row = 1; col = 1;
        }
        ;
        if (selection == 4)
        {
            sheep = 2; row = 1; col = -1;
        }
        ;
        if (selection == 5)
        {
            sheep = 2; row = 1; col = 1;
        }
        ;
        if (selection == 6)
        {
            sheep = 3; row = 1; col = -1;
        }
        ;
        if (selection == 7)
        {
            sheep = 3; row = 1; col = 1;
        }
        ;

        // which sheep
        gameManager.sheepNext = gameManager.sheep[sheep];
        SheepController  shController = gameManager.sheep[sheep].GetComponent <SheepController>();
        SquareController squareController = shController.Square().GetComponent <SquareController>();

        // which square
        int nextRow = squareController.row + row;
        int nextCol = squareController.column + col;

        SquareController nextSquare = gameManager.squares[nextCol, nextRow];

        gameManager.sheepNextMove = nextSquare;
    }