void Update()
    {
        Action p1Action = Action.NONE, p2Action = Action.NONE;

        if (nGames < maxGames)
        {
            // You choose
            if (player1.GetAction(out p1Action) && player2.GetAction(out p2Action))
            {
                Debug.Log("P1 chooses: " + p1Action);
                Debug.Log("P2 chooses: " + p2Action);

                // Inform the AIs of the choices.
                player1.ReceiveOpponentAction(p2Action);
                player2.ReceiveOpponentAction(p1Action);

                // Check who wins
                switch (p1Action - p2Action)
                {
                case 0:
                    nDraw++;
                    Debug.Log("Draw!");
                    break;

                case 1:
                case -2:
                    nWon++;
                    Debug.Log("P1 Wins!");
                    break;

                case 2:
                case -1:
                    nLost++;
                    Debug.Log("P1 Wins!");
                    break;
                }
                nGames++;

                float myWinRate = nWon * 100 / (float)nGames;
                float aiWinRate = nLost * 100 / (float)nGames;
                Debug.Log("P1 winrate: " + myWinRate.ToString("0.000") + "% --- P2 winrate: " + aiWinRate.ToString("0.000") + "%"
                          + "\n" + "nGames: " + nGames + " --- nP1Won: " + nWon + " --- nP2Won: " + nLost + " --- nDraw: " + nDraw);
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        Action chosenAction = Action.NONE;


        //if (GetInput(out chosenAction))
        if (nGames < maxGames)
        {
            chosenAction = player1.GetAction();
            // You choose
            Debug.Log("You choose: " + chosenAction);

            // AI chooses

            Action aiAction = player2.GetAction();

            // Check who wins
            int dif = ((int)chosenAction - (int)aiAction);
            if (dif == 1 || dif == -2)
            {
                Debug.Log("YOU WIN!");
                nWon++;
            }
            else if (dif == 2 || dif == -1)
            {
                Debug.Log("YOU LOSE!");
                nLost++;
            }
            else
            {
                Debug.Log("DRAW");
                nDraw++;
            }
            nGames++;

            float myWinRate = nWon * 100 / (float)nGames;
            float aiWinRate = nLost * 100 / (float)nGames;
            Debug.Log("My winrate:" + myWinRate.ToString("0.00") + " % "
                      + "   AI winrate: " + aiWinRate.ToString("0.00") + " % "
                      + "\n nGames: " + nGames + " nWon: " + nWon + "nLost: " + nLost + "nDraw: " + nDraw);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        // Action chosenAction = Action.NONE;

        // if (GetInput(out chosenAction))

        if (nGames < maxGames)
        {
            // You choose
            // Debug.Log("You choose: " + chosenAction);

            // AI chooses
            Action player1Action = Action.NONE; // Player, if any
            Action player2Action = Action.NONE; // AI only

            player1Action = player1.GetAction();
            if (player1Action == Action.NONE)
            {
                return;
            }

            player2Action = player2.GetAction();

            player1.ReceiveOpponentAction(player2Action);
            player2.ReceiveOpponentAction(player1Action);

            // Check who wins
            int diff = (int)player1Action - (int)player2Action;

            string play1Action_string = player1Action.ToString();
            string play2Action_string = player2Action.ToString();

            Debug.Log("P1 - " + play1Action_string + " / P2 - " + play2Action_string);

            if (diff == 1 || diff == -2)
            {
                nWon++;
                Debug.Log("Player 1 WINS !!");
                // Debug.Log("YOU WIN !!");
            }
            else if (diff == 2 || diff == -1)
            {
                nLost++;
                Debug.Log("Player 2 WINS !!");
                // Debug.Log("YOU LOSE !!");
            }
            else if (diff == 0)
            {
                nDraw++;
                Debug.Log("IT'S A DRAW !!");
            }

            nGames++;

            float myWinRate = nWon * 100 / (float)nGames;
            float aiWinRate = nLost * 100 / (float)nGames;
            Debug.Log("Player 1 winrate: " + myWinRate.ToString("0.00") + "%"
                      + "    Player 2 winrate: " + aiWinRate.ToString("0.00") + "%"
                      + "\n nGames: " + nGames + " P1Won: " + nWon + " P2Won: " + nLost + " nDraw: " + nDraw);
        }
    }