Esempio n. 1
0
        public void GivenGameRoundIsPlayed_WhenTheplayerWinsOrLosesAMatch_PaysOutAtTheCorrectRate(
            DiceValue pick,
            DiceValue dieValue1,
            DiceValue dieValue2,
            DiceValue dieValue3,
            int balance,
            int bet,
            int winnings,
            int total,
            IDice die1,
            IDice die2,
            IDice die3,
            IPlayer player)
        {
            // Arrange.
            // Set the value of the dice rolled.
            die1.CurrentValue.Returns(dieValue1);
            die2.CurrentValue.Returns(dieValue2);
            die3.CurrentValue.Returns(dieValue3);

            die1.roll().Returns(dieValue1);
            die2.roll().Returns(dieValue2);
            die3.roll().Returns(dieValue3);

            // Taking a bet deducts money from the player.
            player.When(x => x.takeBet(Arg.Any <int>()));//.Do(x => total -= bet);

            var game = new Game(die1, die2, die3);

            // Act
            var sut = game.PlayRound(player, pick, bet);

            // Assert
            sut.Should().Be(winnings);
        }
Esempio n. 2
0
        public void Win1Randomness_IsApproximatelyConvergentToExpectation()
        {
            const DiceValue selectedFace = DiceValue.SPADE;
            const int       numDice      = 3;
            const int       numThrows    = 10000;

            var hitCount = 0d;

            var die = new Dice();

            for (var i = 0; i <= numThrows; i++)
            {
                var hit       = false;
                var rollCount = 0;
                for (var j = 0; j < numDice; j++)
                {
                    die.roll();
                    if (die.CurrentValue == selectedFace)
                    {
                        rollCount++;
                    }
                }
                if (rollCount == 1)
                {
                    hitCount++;
                }
            }

            hitCount.Should()
            .BeGreaterThan(34)
            .And.BeLessThan(35,
                            " P(X=1)=P (first dice match) +P(second dice match) +P(third dice match) =1/6 . 5/6 . 5/6 + 5/6 . 1/6 . 5/6 + 5/6 . 5/6 . 1/6 = 25/72 = 0.3472 And Should converge to:- 100 * 0.3472");
        }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;
        if (timeElapsed >= timeOut)
        {
            diceObjs.Add(rolldice.RollDie(0));
            timeElapsed = 0.0f;
        }


        foreach (GameObject diceObj in diceObjs)
        {
            diceValue = diceObj.GetComponent <DiceValue>();
            if (diceValue.stoped)
            {
                dpm.AddDP(diceValue.value);
                stopDice.Add(diceObj);
            }
        }
        foreach (GameObject stopdie in stopDice)
        {
            diceObjs.Remove(stopdie);
            Destroy(stopdie, 1.0f);
        }
    }
Esempio n. 4
0
        internal static void PlayGame(int bet, Game game, Player player, ref DiceValue pick, int currentGame, ref int winCount, ref int loseCount)
        {
            Console.Write("Start Game {0}: ", currentGame);
            Console.WriteLine("{0} starts with balance {1}", player.Name, player.Balance);

            int turn = 0;

            while (player.balanceExceedsLimitBy(bet) && player.Balance < 200)
            {
                try
                {
                    PlayRound(bet, game, player, pick, ref winCount, ref loseCount);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("{0}\n\n", e.Message);
                }

                pick = Dice.RandomValue;
                turn++;
            } //while

            Console.Write("{1} turns later.\nEnd Game {0}: ", turn, currentGame);
            Console.WriteLine("{0} now has balance {1}\n", player.Name, player.Balance);
        }
        /// <summary>
        /// Rolls this dice (i.e. generates a new random dice value)
        /// </summary>
        /// <returns>Returns the new (current) dice value</returns>
        public DiceValue Roll()
        {
            currentValue = (DiceValue)Enum.Parse(typeof(DiceValue), rand.Next(Convert.ToInt32(DiceValue.MIN), Convert.ToInt32(DiceValue.MAX)).ToString());

            flagUsed = false;

            return(currentValue);
        }
Esempio n. 6
0
    IEnumerator DiceRoller()
    {
        diceCollider.enabled = false;

        for (int i = 0; i <= repetitions; i++)
        {
            diceValue = Random.Range(1, 7);

            if (diceValue == 1)
            {
                RollOne(); previousRoll = 1;
            }
            else if (diceValue == 2)
            {
                RollTwo(); previousRoll = 2;
            }
            else if (diceValue == 3)
            {
                RollThree(); previousRoll = 3;
            }
            else if (diceValue == 4)
            {
                RollFour(); previousRoll = 4;
            }
            else if (diceValue == 5)
            {
                RollFive(); previousRoll = 5;
            }
            else if (diceValue == 6)
            {
                RollSix(); previousRoll = 6;
            }

            yield return(new WaitForSeconds(delay));
        }

        Debug.Log("Roll: " + diceValue);

        DiceValue diceNumber = new DiceValue();

        RestClient.Put("https://dice-database-test.firebaseio.com/.json", diceNumber);

        //When the player finishes his roll
        yield return(new WaitForSeconds(2f));

        animator[0].SetBool("Shrink", true);
        animator[1].SetBool("Shrink", true);
        animator[2].SetBool("Shrink", true);

        //If it is the player's turn
        //yield return new WaitForSeconds(10f);
        diceCollider.enabled = true;

        /*animator[0].SetBool("Shrink", false);
        *  animator[1].SetBool("Shrink", false);*/
    }
Esempio n. 7
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            using (LogContext.PushProperties(new PropertyEnricher("Player", player, true)))
            {
                Log.Information("Player {Name} has bet {Bet} on {Pick}\tBalance: {Balance}", player.Name, bet, pick, player.Balance);
            }

            if (player == null) throw new ArgumentException("Player cannot be null");
            if (player == null) throw new ArgumentException("Pick cannot be null");
            if (bet < 0) throw new ArgumentException("Bet cannot be negative");

            if (!this.PickCount.ContainsKey(pick)) this.PickCount.Add(pick, 0);
            this.PickCount[pick]++; // Increment counter for pick count for DiceValue

            Log.Information("Deducting bet");
            player.takeBet(bet);
            Log.Information("Balance: {Balance}", player.Balance);

            int matches = 0;
            for (int i = 0; i < dice.Count; i++)
            {
                var value = dice[i].roll();
                Log.Information("Dice {Number} is a {Roll}", i, value);

                if (!this.RollCount.ContainsKey(value)) this.RollCount.Add(value, 0);
                this.RollCount[value]++; // Increment counter for roll count for DiceValue

                if (value.Equals(pick))
                {
                    matches += 1;
                    Log.Information("Match!");
                }
                else
                {
                    Log.Information("Not a Match!");
                }
            }

            int winnings = matches * bet;

            if (matches > 0)
            {
                player.receiveWinnings(winnings);
                player.returnBet(bet);
            }

            Log.Information("Winnings are {Winnings}", winnings);
            Log.Information("Player's Balance is now {Balance}", player.Balance);

            return winnings;
        }
Esempio n. 8
0
        public int PlayRound(IPlayer player, DiceValue pick, int bet)
        {
            if (player == null)
            {
                throw new ArgumentException("Player cannot be null");
            }
            if (player == null)
            {
                throw new ArgumentException("Pick cannot be null");
            }
            if (bet < 0)
            {
                throw new ArgumentException("Bet cannot be negative");
            }

            // Deduct the bet from the player.
            player.takeBet(bet);

            var matches = 0;

            for (var i = 0; i < _dice.Count; i++)
            {
                // Roll each dice.
                _dice[i].roll();

                // Set the current dice values.
                _values[i] = _dice[i].CurrentValue;

                // Reset the dice values.
                if (_values[i].Equals(pick))
                {
                    matches += 1;
                }
            }

            // Check if there were no winnings.
            if (matches <= 0)
            {
                return(0);
            }

            // Calculate the winnings.
            var winnings = matches * bet + bet;

            // Increase balance
            player.receiveWinnings(winnings);
            return(winnings);
        }
Esempio n. 9
0
        public int playRound(int bet, DiceValue pick)
        {
            if (bet < 0) throw new ArgumentException("Bet cannot be negative");

            int matches = 0;
            for (int i = 0; i < dice.Count; i++)
            {
                values[i] = dice[i].roll();
                if (values[i].Equals(pick)) matches += 1;
            }

            int winnings = 0;
            if (matches > 0) winnings = matches * bet + bet;

            return winnings;
        }
Esempio n. 10
0
        internal static void PlayRound(int bet, Game game, Player player, DiceValue pick, ref int winCount, ref int loseCount)
        {
            var winnings = game.playRound(player, pick, bet);
            var currentDiceValues = game.CurrentDiceValues;

            Console.WriteLine("Rolled {0} {1} {2}", currentDiceValues[0], currentDiceValues[1], currentDiceValues[2]);
            if (winnings > 0)
            {
                Console.WriteLine("{0} won {1} balance now {2}", player.Name, winnings, player.Balance);
                winCount++;
            }
            else
            {
                Console.WriteLine("{0} lost {1} balance now {2}", player.Name, bet, player.Balance);
                loseCount++;
            }
        }
Esempio n. 11
0
        private int genereateSumOfThrowDice(string diceType, int numberOfDice)
        {
            Dice   actualDice      = getActualDice(diceType);
            int    sumPoint        = 0;
            int    throwDice       = 0;
            string rolledDicesText = "";

            while (throwDice < numberOfDice)
            {
                DiceValue dv = actualDice.rollADice();
                sumPoint        += (int)dv;
                rolledDicesText += ((int)dv).ToString() + RolePlayGameCoordinator.SEPARATOR;
                rolledDicesText += diceType + RolePlayGameCoordinator.SEPARATOR;
                throwDice++;
            }
            rolledDicesInTurn.Add(rolledDicesText);
            return(sumPoint);
        }
Esempio n. 12
0
        internal static void Play100Games(int bet, Game game, ref DiceValue pick, ref int totalWins, ref int totalLosses)
        {
            int winCount = 0;
            int loseCount = 0;

            var player = new Player("Fred", 100);

            for (int i = 0; i < 100; i++)
            {
                PlayGame(bet, game, player, ref pick, i, ref winCount, ref loseCount);
            } //for

            Log.Information("Win count = {Wins}, Lose Count = {Losses}, {Rate}", winCount, loseCount,
                (float)winCount / (winCount + loseCount));
            Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount,
                (float) winCount/(winCount + loseCount));

            totalWins += winCount;
            totalLosses += loseCount;
        }
Esempio n. 13
0
        public void GivenPlayerPlaysARound_WhenTheplayerWinsOrLosesAMatch_BalanceIncreases(
            DiceValue pick,
            DiceValue dieValue1,
            DiceValue dieValue2,
            DiceValue dieValue3,
            int balance,
            int bet,
            int winnings,
            int total,
            string name
            )
        {
            // Arrange.
            var player = new Player(name, balance);

            // Act : deduct bet and add winnings;
            player.takeBet(bet);
            player.receiveWinnings(winnings);

            // Assert
            player.Balance.Should().Be(total);
        }
Esempio n. 14
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            if (player == null) throw new ArgumentException("Player cannot be null");
            if (player == null) throw new ArgumentException("Pick cannot be null");
            if (bet < 0) throw new ArgumentException("Bet cannot be negative");

            player.takeBet(bet);

            int matches = 0;
            for (int i = 0; i < dice.Count; i++)
            {
                dice[i].roll();
                if (values[i].Equals(pick)) matches += 1;
            }

            int winnings = matches * bet;
            if (matches > 0)
            {
                player.receiveWinnings(winnings);
            }

            return winnings;
        }
Esempio n. 15
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            if (player == null)
            {
                throw new ArgumentException("Player cannot be null");
            }
            if (player == null)
            {
                throw new ArgumentException("Pick cannot be null");
            }
            if (bet < 0)
            {
                throw new ArgumentException("Bet cannot be negative");
            }

            player.takeBet(bet);

            int matches = 0;

            for (int i = 0; i < dice.Count; i++)
            {
                dice[i].roll();
                if (values[i].Equals(pick))
                {
                    matches += 1;
                }
            }

            int winnings = matches * bet;

            if (matches > 0)
            {
                player.receiveWinnings(winnings);
            }

            return(winnings);
        }
Esempio n. 16
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonUp("Fire1"))
        {
            StartCoroutine(RollMultiDice(rollIndex, rollList.Count));
            rollIndex = rollList.Count;
        }

        foreach (GameObject diceObj in diceObjs)
        {
            diceValue = diceObj.GetComponent <DiceValue>();

            if (diceValue.stoped)
            {
                dpm.AddDP(diceValue.value);
                stopDice.Add(diceObj);
            }
        }
        foreach (GameObject stopDie in stopDice)
        {
            diceObjs.Remove(stopDie);
            Destroy(stopDie, 1.0f);
        }
    }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Dice d1 = new Dice();
            Dice d2 = new Dice();
            Dice d3 = new Dice();

            Player p = new Player("Fred", 100);

            Console.WriteLine(p);
            Console.WriteLine();

            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);
            IList <DiceValue> cdv = g.CurrentDiceValues;

            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            DiceValue rv = Dice.RandomValue;

            Random random = new Random();
            int    bet    = 5;

            p.Limit = 0;
            int       winnings = 0;
            DiceValue pick     = Dice.RandomValue;

            int totalWins   = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount  = 0;
                int loseCount = 0;
                for (int i = 0; i < 100; i++)
                {
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.playRound(p, pick, bet);
                            cdv      = g.CurrentDiceValues;

                            Console.WriteLine("Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2]);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} won {1} balance now {2}", p.Name, winnings, p.Balance);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} lost {1} balance now {2}", p.Name, bet, p.Balance);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick     = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float)winCount / (winCount + loseCount));
                totalWins   += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q"))
                {
                    break;
                }
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Esempio n. 18
0
 public static string stringRepr(DiceValue diceValue)
 {
     return VALUE_REPR_MAP[diceValue];
 }
Esempio n. 19
0
    // Use this for initialization
    void Start()
    {
        takeAttack = false;
            DuelMode = false;

            winwidth = Screen.width;
            winheight = Screen.height;

            Debug.Log(winwidth+" "+winheight);

            // initialise 4player game
            Vector3 st = new Vector3(0,5,0);
             long amount = 250000;

             startTime =0;
            deltaTime = 0.5f;

            pause = false;
            rollyes = false;
            totalPlayers = 4;
            turn = 0;

            for(int i=0;i<64;i++)
                InfoBox[i]=-1;

                float x=-0.08f,y=-0.095f,wx=0.23f,wy=0.2f;
            Rect A = new Rect(x*winwidth,y*winheight,wx*winwidth,wy*winheight);

            wx = 0.05f;
            wy=0.1f;
            y = -0.077f;
            Rect B1 = new Rect(x*winwidth,y*winheight,wx*winwidth,wy*winheight);

            float bX = -0.09f;
            float bY = -0.1f;
            float bH = 0.04f;
            float bW = 0.02f;
            Rect B2 = new Rect(bX*winwidth,bY*winheight,bW*winwidth,bH*winheight);

         	    for(int i=0;i<totalPlayers;i++)
            {
                Players[i] = new GamePlayers();
                Players[i].init(i, amount, st, 0, 0, 0, 0, 5,true);
                PlayerTextures[i].pixelInset = A;
                PlayerTextures[i].transform.Find("logo").guiTexture.pixelInset = B1;
                PlayerTextures[i].transform.Find("cuff1").guiTexture.pixelInset = B2;
                PlayerTextures[i].transform.Find("cuff2").guiTexture.pixelInset = B2;
                PlayerTextures[i].transform.Find("cuff3").guiTexture.pixelInset = B2;

            }

            wx = 0.05f;
            wy = 0.05f;
            Rect D1 = new Rect(x*winwidth,y*winheight,wx*winwidth,wy*winwidth);
            Dice1.pixelInset = D1;
            y=0.0001f;
            Rect D2 = new Rect(x*winwidth,y*winheight,wx*winwidth,wy*winwidth);
            Dice2.pixelInset = D2;

            Vector3 startpos = new Vector3(0,7.5f,0);

            GobPlayer = new GameObject[4];

        //	GobPlayer = Resources.LoadAll("Player") as GameObject[];

            float tosub=-1;

            for(int i=0;i<totalPlayers;i++)
            {
            GameObject instanceg = new GameObject();
                startpos.x = tosub + i;
            instanceg = Instantiate(PlayerFab,startpos,transform.rotation) as GameObject;
            GobPlayer[i] = instanceg;
            for(int j=0;j<4;j++)
            GobPlayer[i].transform.Find("Pcam"+j).camera.enabled = false;
            gameObject.transform.Find("Camera"+i).camera.enabled = false;
        ///	gameObject.transform.Find("Camera"+i).camera.transform.Find("AmbientLight").light.enabled = false;
            }

            gameObject.transform.Find("Camera0").camera.enabled = true;
        //	gameObject.transform.Find("Camera0").camera.transform.Find("AmbientLight").light.enabled= true;
            Plist = new PathList();
            Plist.initList();

                GameObject instance = new GameObject();
                instance = Instantiate(Dicefab,instance.transform.position,instance.transform.rotation) as GameObject;

                instance.name="Dicer1";

                GameObject instance2 = new GameObject();
                instance2 = Instantiate(Dice2fab,instance2.transform.position,transform.rotation) as GameObject;
                instance2.name="Dicer2";

                V1Dice = instance.GetComponent<DiceValue>();
                V2Dice = instance2.GetComponent<DiceValue>();

            Dice1 = Instantiate(Dice1) as GUITexture;

            Dice2 = Instantiate (Dice2) as GUITexture;

            initDepartments();

            //
            Debug.Log("gameinited");
    }
Esempio n. 20
0
 public Dice()
 {
     currentValue = RandomValue;
 }
Esempio n. 21
0
 public void Roll()
 {
     m_value = (DiceValue)m_random.Next(1, 7);
 }
Esempio n. 22
0
 public DiceValue roll()
 {
     currentValue = RandomValue;
     return currentValue;
 }
Esempio n. 23
0
 private DiceValue OppositeValue(DiceValue value)
 {
     return((DiceValue)(DiceValue.Six - (value - 1)));
 }
Esempio n. 24
0
 public static string GetValue(this DiceValue value)
 {
     return(value.GetHashCode().ToString());
 }
Esempio n. 25
0
        public int RollDice(DiceValue v1, DiceValue v2, DiceValue v3, DiceValue v4, DiceValue v5, DiceValue v6)
        {
            int score = 0;

            int[] inputAsIntArray = new int[6] {
                v1.GetHashCode(), v2.GetHashCode(), v3.GetHashCode(), v4.GetHashCode(), v5.GetHashCode(), v6.GetHashCode()
            };

            Array.Sort(inputAsIntArray);

            string inputAsStringPattern = inputAsIntArray[0].ToString() + inputAsIntArray[1].ToString() + inputAsIntArray[2].ToString() + inputAsIntArray[3].ToString() + inputAsIntArray[4].ToString() + inputAsIntArray[5].ToString();


            switch (inputAsStringPattern)
            {
            case "111111":
                score = 2000;
                inputAsStringPattern = "";
                break;

            case "222222":
                score = 400;
                inputAsStringPattern = "";
                break;

            case "333333":
                score = 600;
                inputAsStringPattern = "";
                break;

            case "444444":
                score = 800;
                inputAsStringPattern = "";
                break;

            case "555555":
                score = 1000;
                inputAsStringPattern = "";
                break;

            case "666666":
                score = 1200;
                inputAsStringPattern = "";
                break;

            default:
                if (inputAsStringPattern.Contains("111"))
                {
                    score += 1000;
                    inputAsStringPattern = inputAsStringPattern.Replace("111", "0");
                }
                if (inputAsStringPattern.Contains("222"))
                {
                    score += 200;
                    inputAsStringPattern = inputAsStringPattern.Replace("222", "0");
                }
                if (inputAsStringPattern.Contains("333"))
                {
                    score += 300;
                    inputAsStringPattern = inputAsStringPattern.Replace("333", "0");
                }
                if (inputAsStringPattern.Contains("444"))
                {
                    score += 400;
                    inputAsStringPattern = inputAsStringPattern.Replace("444", "0");
                }
                if (inputAsStringPattern.Contains("555"))
                {
                    score += 500;
                    inputAsStringPattern = inputAsStringPattern.Replace("555", "0");
                }
                if (inputAsStringPattern.Contains("666"))
                {
                    score += 600;
                    inputAsStringPattern = inputAsStringPattern.Replace("666", "0");
                }
                break;
            }

            if (string.IsNullOrWhiteSpace(inputAsStringPattern))
            {
                return(score);
            }

            foreach (var item in inputAsStringPattern)
            {
                DiceValue val = (DiceValue)int.Parse(item.ToString());
                score += pointSystem.GetValueOrDefault(val);
            }
            return(score);
        }
Esempio n. 26
0
        public void GivenPlayerPlaysARound_WhenTheplayerWinsOrLosesAMatch_BalanceIncreases(
         DiceValue pick,
         DiceValue dieValue1,
         DiceValue dieValue2,
         DiceValue dieValue3,
         int balance,
         int bet,
         int winnings,
         int total,
         string name
            )
        {
            // Arrange.
            var player = new Player(name, balance);

            // Act : deduct bet and add winnings;
            player.takeBet(bet);
            player.receiveWinnings(winnings);

            // Assert
            player.Balance.Should().Be(total);
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            // Create Dice.
            IDice d1 = new Dice();
            IDice d2 = new Dice();
            IDice d3 = new Dice();

            // Create player.
            IPlayer p = new Player("Fred", 100);

            Console.WriteLine(p);
            Console.WriteLine();

            // Create Game.
            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);

            // Initial dice values? Why does this matter?
            IList <DiceValue> cdv = g.CurrentDiceValues;

            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            // Unused random dice value? Why is this done?
            DiceValue rv = Dice.RandomValue;

            // Unused random
            Random random = new Random();

            // Setup initial conditions.
            int bet = 5;

            p.Limit = 0;
            int       winnings = 0;
            DiceValue pick     = Dice.RandomValue;

            Console.WriteLine("Chosen Dice Value:" + pick);

            int totalWins   = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount  = 0;
                int loseCount = 0;

                // Play 100 times
                for (int i = 0; i < 100; i++)
                {
                    // Re-creating player with the same balance each time.
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;

                    // Balance lower limit 0 upper limit 200.
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.PlayRound(p, pick, bet);
                            cdv      = g.CurrentDiceValues;

                            Console.WriteLine("Picked {3} and Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2], pick);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} bet {3} and won {1} balance now {2}", p.Name, winnings, p.Balance, bet);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} bet {3} and lost {1} balance now {2}", p.Name, bet, p.Balance, bet);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick     = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float)winCount / (winCount + loseCount));
                totalWins   += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q"))
                {
                    break;
                }
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Esempio n. 28
0
 public static string stringRepr(DiceValue diceValue)
 {
     return(VALUE_REPR_MAP[diceValue]);
 }
Esempio n. 29
0
 public override string ToString()
 {
     return(DiceAmount.ToString() + "d" + DiceValue.ToString());
 }
Esempio n. 30
0
 public DiceValue roll()
 {
     currentValue = RandomValue;
     return(currentValue);
 }
Esempio n. 31
0
 public static Dice DiceOf(DiceValue dice)
 {
     return((Dice)((int)dice | (int)DiceTypeOf(dice)));
 }
Esempio n. 32
0
 public Dice()
 {
     currentValue = RandomValue;
 }
Esempio n. 33
0
 public static DiceType DiceTypeOf(DiceValue dice)
 {
     return(g_DiceValueType[dice]);
 }
Esempio n. 34
0
 public DiceValue roll()
 {
     this.currentValue = RandomValue;
     return CurrentValue;
 }
Esempio n. 35
0
 public static int Roll(DiceValue dice)
 {
     return(Roll((int)dice));
 }
Esempio n. 36
0
 public Dice()
 {
     m_value = 0;
 }
Esempio n. 37
0
        public void GivenGameRoundIsPlayed_WhenTheplayerWinsOrLosesAMatch_PaysOutAtTheCorrectRate(
            DiceValue pick,
            DiceValue dieValue1,
            DiceValue dieValue2,
            DiceValue dieValue3,
            int balance,
            int bet,
            int winnings,
            int total,
            IDice die1,
            IDice die2,
            IDice die3,
            IPlayer player)
        {
            // Arrange.
            // Set the value of the dice rolled.
            die1.CurrentValue.Returns(dieValue1);
            die2.CurrentValue.Returns(dieValue2);
            die3.CurrentValue.Returns(dieValue3);

            die1.roll().Returns(dieValue1);
            die2.roll().Returns(dieValue2);
            die3.roll().Returns(dieValue3);

            // Taking a bet deducts money from the player.
            player.When(x => x.takeBet(Arg.Any<int>()));//.Do(x => total -= bet);

            var game = new Game(die1, die2, die3);

            // Act
            var sut = game.PlayRound(player, pick, bet);

            // Assert
            sut.Should().Be(winnings);
        }