Exemplo n.º 1
0
    private ShooterChoice MakeRandomChoice(ShooterController shooter)
    {
        Debug.Log("Made random choice.");

        ShooterChoice choice = (ShooterChoice)Random.Range(1, 4);

        while (true)
        {
            // got shoot and have ammo
            if (choice == ShooterChoice.SHOOT && shooter.HasAmmo)
            {
                return(choice);
            }

            // got dodge and have energy
            if (choice == ShooterChoice.DODGE && shooter.HasEnergy)
            {
                return(choice);
            }

            if (choice == ShooterChoice.RELOAD)
            {
                return(choice);
            }

            choice++;

            if ((int)choice >= 4)
            {
                choice = (ShooterChoice)1;
            }
        }
    }
Exemplo n.º 2
0
    private void PostActPhase()
    {
        playerOneChoice = ShooterChoice.WAITING;
        playerTwoChoice = ShooterChoice.WAITING;

        m_phase = GamePhase.CHOICE;
    }
Exemplo n.º 3
0
    public ShooterChoice MakePrediction(bool forPlayer1)
    {
        string prediction = "";

        string ammo   = forPlayer1 ? m_sgm.playerOne.HasAmmo ? "1" : "0" : m_sgm.playerTwo.HasAmmo ? "1" : "0";;
        string energy = forPlayer1 ? m_sgm.playerOne.HasEnergy ? "1" : "0" : m_sgm.playerTwo.HasEnergy ? "1" : "0";;

        if (forPlayer1)
        {
            prediction = ngram.Predict(ammo + energy + GetLastCombo(playerOneChoices, 2));
        }
        else
        {
            prediction = ngram.Predict(ammo + energy + GetLastCombo(playerTwoChoices, 2));
        }

        ShooterChoice choice = StringToChoice(prediction);

        if (choice == ShooterChoice.WAITING)
        {
            nGramStatus.text = "NGram: Not enough data to make a choice.";
        }
        else
        {
            nGramStatus.text = "NGram: Made choice based on data.";
        }

        return(choice);
    }
    public ShooterChoice Predict(ShooterController me, ShooterController enemy)
    {
        float[] input = new float[]
        {
            // player 1 (me)
            me.ammoCount,
            me.energyCount,
            me.health,

            // player 2 (other)
            enemy.ammoCount,
            enemy.energyCount,
            enemy.health
        };

        float[] output = m_ann.Forward(input);

        int   bestChoice = 0;
        float bestResult = output[0];

        // find best
        for (int i = 1; i < output.Length; i++)
        {
            if (output[i] > bestResult)
            {
                bestChoice = i;
                bestResult = output[i];
            }
        }

        // not sure enough.
        if (bestResult < 0.5f)
        {
            return(ShooterChoice.WAITING);
        }

        ShooterChoice choice = (ShooterChoice)(bestChoice + 1);

        // must have ammo to shoot
        if (choice == ShooterChoice.SHOOT && me.HasAmmo)
        {
            return(choice);
        }

        // got dodge and have energy
        if (choice == ShooterChoice.DODGE && me.HasEnergy)
        {
            return(choice);
        }

        if (choice == ShooterChoice.RELOAD)
        {
            return(choice);
        }

        return(ShooterChoice.WAITING);
    }
Exemplo n.º 5
0
    private ShooterChoice NGramChoice()
    {
        ShooterChoice choice = m_ngramControler.MakePrediction(false);

        // ngram failed to make a choice, defaulting random
        if (choice == ShooterChoice.WAITING)
        {
            return(MakeRandomChoice(playerTwo));
        }

        return(choice);
    }
Exemplo n.º 6
0
    private ShooterChoice RBSChoice(bool asPlayerOne)
    {
        ShooterController me   = asPlayerOne ? playerOne : playerTwo;
        ShooterController them = asPlayerOne ? playerTwo : playerOne;

        ShooterChoice choice = m_rbsController.GetChoice(me, them);

        if (choice == ShooterChoice.WAITING)
        {
            return(MakeRandomChoice(me));
        }

        return(choice);
    }
Exemplo n.º 7
0
    private string ChoiceToString(ShooterChoice sc)
    {
        switch (sc)
        {
        case ShooterChoice.SHOOT:
            return("s");

        case ShooterChoice.DODGE:
            return("d");

        case ShooterChoice.RELOAD:
            return("r");
        }

        return("w");
    }
Exemplo n.º 8
0
    private ShooterChoice ANNChoice(bool asPlayerOne)
    {
        ShooterController me   = asPlayerOne ? playerOne : playerTwo;
        ShooterController them = asPlayerOne ? playerTwo : playerOne;

        ShooterChoice choice = m_annController.Predict(me, them);

        if (choice == ShooterChoice.WAITING)
        {
            annText.text = "ANN: Not enough training. Using random choice.";
            return(MakeRandomChoice(me));
        }

        annText.text = "ANN: Made a choice.";

        return(choice);
    }
Exemplo n.º 9
0
    private void ResetGame()
    {
        playerOne.ammoCount   = 1;
        playerOne.energyCount = 2;
        playerOne.health      = 2;
        playerOne.UpdateSprites();

        playerTwo.ammoCount   = 1;
        playerTwo.energyCount = 2;
        playerTwo.health      = 2;
        playerTwo.UpdateSprites();

        playerOneChoice = ShooterChoice.WAITING;
        playerTwoChoice = ShooterChoice.WAITING;

        endText.text = "";
    }
Exemplo n.º 10
0
    private void UpdateController(ShooterController controller, ShooterChoice choice)
    {
        switch (choice)
        {
        case ShooterChoice.SHOOT:
            controller.SubtractAmmo();
            break;

        case ShooterChoice.DODGE:
            controller.SubtractEnergy();
            break;

        case ShooterChoice.RELOAD:
            controller.AddAmmo();
            controller.AddEnergy();
            break;
        }

        controller.RunAnimation(choice);
    }
Exemplo n.º 11
0
 public void RunAnimation(ShooterChoice choice)
 {
     m_animator.SetInteger("Choice", (int)choice);
     m_animator.SetTrigger("Act");
 }
Exemplo n.º 12
0
    private void ChoicePhase()
    {
        // player 1 choice
        if (Input.GetKeyDown(KeyCode.Alpha1) && playerOne.HasAmmo)
        {
            playerOneChoice = ShooterChoice.SHOOT;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2) && playerOne.HasEnergy)
        {
            playerOneChoice = ShooterChoice.DODGE;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            playerOneChoice = ShooterChoice.RELOAD;
        }

        // player 2
        switch (m_player2Mode)
        {
        case PlayerMode.HUMAN:
            playerTwoChoice = P2HumanChoice();
            break;

        case PlayerMode.RAND:
            if (playerTwoChoice != ShooterChoice.WAITING)
            {
                break;
            }
            playerTwoChoice = MakeRandomChoice(playerTwo);
            break;

        case PlayerMode.RULE:
            if (playerTwoChoice != ShooterChoice.WAITING)
            {
                break;
            }
            playerTwoChoice = RBSChoice(false);
            break;

        case PlayerMode.NGRAM:
            if (playerTwoChoice != ShooterChoice.WAITING)
            {
                break;
            }
            playerTwoChoice = NGramChoice();
            break;

        case PlayerMode.ANN:
            if (playerTwoChoice != ShooterChoice.WAITING)
            {
                break;
            }
            playerTwoChoice = ANNChoice(false);
            break;
        }

        playerOne.isReady = playerOneChoice != ShooterChoice.WAITING;
        playerOne.UpdateSprites();
        playerTwo.isReady = playerTwoChoice != ShooterChoice.WAITING;
        playerTwo.UpdateSprites();

        if (playerOne.isReady && playerTwo.isReady)
        {
            m_phase = GamePhase.ACT;
        }
    }