// When two players fight it out
        public bool Duel(Player player1, Player player2)
        {
            // Endlessly loops until someone wins
            while (true)
            {
                // Rolls the actions
                ActionRecord player1moves = player1.moves;
                ActionRecord player2moves = player2.moves;

                int roll1 = player1.Roll(player2moves);
                int roll2 = player2.Roll(player1moves);

                // Check if first player wins
                if (roll1 == (roll2 + 1) % 3)
                {
                    Console.WriteLine();
                    Message(string.Format("{0} beats {1}, {2} wins!", (Action)roll1, (Action)roll2, player1.name), 0.25);

                    // Adding win/loss stats because rng is fair
                    player1.results.matchwins++;
                    player2.results.matchlosses++;

                    return(true);
                }

                // Check if second player wins
                if (roll2 == (roll1 + 1) % 3)
                {
                    Console.WriteLine();
                    Message(string.Format("{0} beats {1}, {2} wins!", (Action)roll2, (Action)roll1, player2.name), 0.25);

                    // Adding win/loss stats because rng is fair
                    player1.results.matchlosses++;
                    player2.results.matchwins++;

                    return(false);
                }

                // If they play the same action
                Message(string.Format("Both played {0}, rerolling...", (Action)roll1), 0.2);
            }
        }
Example #2
0
        // Recording and Playing Rolls
        public int Roll(ActionRecord opponentsMoves)
        {
            int roll = 3;

            // Some biased rolling based on opponent's roll records.
            if (rnd.NextDouble() < biasProbability)
            {
                int probabilityMove = rnd.Next(opponentsMoves.total);

                if (probabilityMove < opponentsMoves.rocks)
                {
                    // Play Paper
                    roll = 1;
                }
                else if (probabilityMove < opponentsMoves.rocks + opponentsMoves.papers)
                {
                    // Play Scissors
                    roll = 2;
                }
                else
                {
                    // Play Rock
                    roll = 0;
                }

                /*
                 * double probabilityMove = rnd.NextDouble();
                 * double rockbound = opponentsMoves.rocks / opponentsMoves.total;
                 * double scissorsbound = 1 - (opponentsMoves.scissors / opponentsMoves.total);
                 *
                 * Console.WriteLine(probabilityMove);
                 *
                 * if (probabilityMove < rockbound) roll = 1; // Rock countered by Paper
                 * else if (probabilityMove > scissorsbound) roll = 0; // Scissors countered by Rock
                 * else roll = 2; // Paper countered by Scissors
                 */
            }
            else
            {
                roll = rnd.Next(3);  // When they say "F**k It"
            }
            // Records the rolls
            switch (roll)
            {
            case 0:
                moves.rocks++;
                break;

            case 1:
                moves.papers++;
                break;

            case 2:
                moves.scissors++;
                break;
            }
            moves.total++;

            // Returns action
            return(roll);
        }