Exemplo n.º 1
0
        public void NameWinner(List <CL_player> players)
        {
            CL_player winner = players.Find(p => p.IsWinner);

            if (!players.Exists(p => p.IsWinner))
            {
                int maxScore = players.Max(p => p.Score);
                winner = players.Find(p => p.Score == maxScore);
            }
            winner.VictoryCount++;
            winner.IsWinner = false;
            //Console.WriteLine("And the winner is... {0} with {1} points.", winner.Name, winner.Score);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            CL_cards_games   deck     = new CL_cards_games();
            CL_croupier      croupier = new CL_croupier();
            CL_player        player1  = new CL_player(false, "Player 1");
            CL_player        player2  = new CL_player(false, "Player 2");
            List <CL_player> players  = new List <CL_player>
            {
                player1,
                player2,
                croupier
            };

            Stopwatch watch = new Stopwatch();

            watch.Start();

            for (int i = 0; i < 10000; i++)
            //System.Threading.Tasks.Parallel.For(0, 10000, (int x) =>
            {
                deck.CreateDeck();
                List <CL_cards> shuffledDeck = croupier.Shuffle(deck.Deck);
                croupier.GiveCards(shuffledDeck, players);
                foreach (CL_player player in players)
                {
                    croupier.CountScore(player);
                }
                croupier.NameWinner(players);
            } // Parallel.For

            foreach (CL_player player in players)
            {
                decimal win   = player.VictoryCount;
                decimal ratio = win / 10000 * 100;
                Console.WriteLine("{0} wins: {1} , win ratio: {2}%.", player.Name, player.VictoryCount, ratio);
            }
            watch.Stop();

            Utils utils = new Utils();

            utils.OddsRatioCalculation(players);

            Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms.");

            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void CountScore(CL_player player)
        {
            player.Score = player.Hand.Sum(c => c.Value);
            CL_cards firstCard = player.Hand.First();

            if (player.IsCroupier)
            {
                if (player.Hand.All(c => c.Value == firstCard.Value))
                {
                    player.IsWinner = true;
                }
                else if (player.Hand.All(c => c.Symbol == firstCard.Symbol))
                {
                    player.Score += 35;
                }
            }
            else if (player.Hand.All(c => c.Symbol == firstCard.Symbol))
            {
                player.Score += 20;
            }
            Console.WriteLine("Score de {0} : {1}.", player.Name, player.Score);
        }