コード例 #1
0
ファイル: SingleGame.cs プロジェクト: JPinheiro93/Sueca
        public static void Main()
        {
            string input;

            string[] playersNames = new string[4];
            playersNames[0] = "Bot";
            int firstPlayerID;

            Console.WriteLine("");
            Console.WriteLine("|||||||||||||||||||| SUECA GAME ||||||||||||||||||||");
            Console.WriteLine("");

            Console.WriteLine("Player 0: Bot");
            Console.Write("Player 1: ");
            playersNames[1] = Console.ReadLine();
            Console.Write("Player 2: ");
            playersNames[2] = Console.ReadLine();
            Console.Write("Player 3: ");
            playersNames[3] = Console.ReadLine();
            Console.Write("First player ID: ");
            input         = Console.ReadLine();
            firstPlayerID = Convert.ToInt16(input);
            Console.WriteLine("");

            int                seed         = Guid.NewGuid().GetHashCode();
            Random             randomNumber = new Random(seed);
            Deck               deck         = new Deck();
            List <List <int> > playersHand  = new List <List <int> >(
                new List <int>[] {
                new List <int>(10),
                new List <int>(10),
                new List <int>(10),
                new List <int>(10)
            });

            deck.SampleHands(ref playersHand);
            List <int> currentHand;
            int        trumpCardPlayer = (firstPlayerID - 1 + 4) % 4;
            int        trumpCard = playersHand[trumpCardPlayer][0];
            int        cardIndex, currentPlayerID = firstPlayerID;

            SmartPlayer artificialPlayer = new SmartPlayer(0, playersHand[0], trumpCard, trumpCardPlayer);
            SuecaGame   game             = new SuecaGame(Card.GetSuit(trumpCard), firstPlayerID);

            //Console.WriteLine("---------hands---------");
            //sueca.printhand(playershand[0]);
            //sueca.printhand(playershand[1]);
            //sueca.printhand(playershand[2]);
            //sueca.printhand(playershand[3]);
            //console.writeline("-----------------------");

            for (int i = 0; i < 40; i++)
            {
                currentHand = playersHand[currentPlayerID];
                Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||");
                Console.WriteLine("                 Trick " + (i / 4));
                Console.WriteLine("                 Player " + currentPlayerID + " - " + playersNames[currentPlayerID]);
                Console.WriteLine("                 Trump is " + (Suit)Card.GetSuit(trumpCard));
                Console.WriteLine("");

                game.PrintLastTrick();
                game.PrintCurrentTrick();
                Sueca.PrintCurrentHand(currentHand);
                int chosenCard;

                if (currentPlayerID != 0)
                {
                    Console.Write("Pick the card you want to play by its index: ");
                    input      = Console.ReadLine();
                    cardIndex  = Convert.ToInt16(input);
                    chosenCard = currentHand[cardIndex];
                    artificialPlayer.AddPlay(currentPlayerID, chosenCard);
                }
                else
                {
                    chosenCard = artificialPlayer.Play();
                }

                game.PlayCard(currentPlayerID, chosenCard);
                currentHand.Remove(chosenCard);
                currentPlayerID = game.GetNextPlayerId();
            }

            Console.WriteLine("|||||||||||||||||||||||| END |||||||||||||||||||||||");
            Console.WriteLine("");
            int[] points = game.GetGamePoints();
            Console.WriteLine("Team " + playersNames[0] + " and " + playersNames[2] + " - " + points[0] + " points");
            Console.WriteLine("Team " + playersNames[1] + " and " + playersNames[3] + " - " + points[1] + " points");
            // game.PrintPoints(playersNames);
            Console.WriteLine("");
            Console.ReadLine();
        }
コード例 #2
0
        static int[] processGames(int i,
                                  int[] localCount,
                                  int gameMode,
                                  List <List <int>[]> cardsPerPlayer,
                                  List <int> trumps,
                                  List <int> firstPlayers,
                                  List <int> finalBotTeamPoints,
                                  List <ulong[]> timePerTrick,
                                  Object allGamesLock)
        {
            int    seed         = Guid.NewGuid().GetHashCode();
            Random randomNumber = new Random(seed);

            ArtificialPlayer[] players      = new ArtificialPlayer[4];
            List <List <int> > playersHands = new List <List <int> >(
                new List <int>[] {
                new List <int>(10),
                new List <int>(10),
                new List <int>(10),
                new List <int>(10)
            });
            Deck deck = new Deck();

            deck.SampleHands(ref playersHands);
            int       currentPlayerID = i % 4;
            int       first           = currentPlayerID;
            int       trumpPlayerId   = (first - 1 + 4) % 4;
            int       trumpCard       = playersHands[trumpPlayerId][0];//the trump card is the first card of player that is seated before the one that will start the game
            int       trumpSuit       = Card.GetSuit(trumpCard);
            SuecaGame game            = new SuecaGame(trumpSuit, first);

            int[] firstPlayer = new int[4] {
                0, 0, 0, 0
            };
            firstPlayer[first] = 1;
            ulong[] timeTemp = new ulong[10];

            List <int>[] handsPerPlayer = new List <int> [4];
            for (int k = 0; k < 4; k++)
            {
                handsPerPlayer[k] = new List <int>(10);
                for (int j = 0; j < 10; j++)
                {
                    handsPerPlayer[k].Add(playersHands[k][j]);
                }
            }

            switch (gameMode)
            {
            case 1:
                players[0] = new RuleBasedPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RandomPlayer(1, playersHands[1]);
                players[2] = new RandomPlayer(2, playersHands[2]);
                players[3] = new RandomPlayer(3, playersHands[3]);
                break;

            case 2:
                players[0] = new TrickPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RuleBasedPlayer(1, playersHands[1], trumpCard, trumpPlayerId);
                players[2] = new RuleBasedPlayer(2, playersHands[2], trumpCard, trumpPlayerId);
                players[3] = new RuleBasedPlayer(3, playersHands[3], trumpCard, trumpPlayerId);
                break;

            case 3:
                players[0] = new SmartPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RuleBasedPlayer(1, playersHands[1], trumpCard, trumpPlayerId);
                players[2] = new RuleBasedPlayer(2, playersHands[2], trumpCard, trumpPlayerId);
                players[3] = new RuleBasedPlayer(3, playersHands[3], trumpCard, trumpPlayerId);
                break;

            case 4:
                players[0] = new TimeLimitedPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RuleBasedPlayer(1, playersHands[1], trumpCard, trumpPlayerId);
                players[2] = new RuleBasedPlayer(2, playersHands[2], trumpCard, trumpPlayerId);
                players[3] = new RuleBasedPlayer(3, playersHands[3], trumpCard, trumpPlayerId);
                break;

            case 5:
                players[0] = new RBOPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RuleBasedPlayer(1, playersHands[1], trumpCard, trumpPlayerId);
                players[2] = new RuleBasedPlayer(2, playersHands[2], trumpCard, trumpPlayerId);
                players[3] = new RuleBasedPlayer(3, playersHands[3], trumpCard, trumpPlayerId);
                break;

            case 6:
                players[0] = new HybridPlayer(0, playersHands[0], trumpCard, trumpPlayerId);
                players[1] = new RuleBasedPlayer(1, playersHands[1], trumpCard, trumpPlayerId);
                players[2] = new RuleBasedPlayer(2, playersHands[2], trumpCard, trumpPlayerId);
                players[3] = new RuleBasedPlayer(3, playersHands[3], trumpCard, trumpPlayerId);
                break;

            default:
                break;
            }


            for (int j = 0; j < 40; j++)
            {
                int chosenCard;

                if (currentPlayerID == 0)
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    chosenCard = players[currentPlayerID].Play();
                    sw.Stop();
                    TimeSpan ts       = sw.Elapsed;
                    ulong    realTime = (ulong)ts.Minutes * 60000 + (ulong)ts.Seconds * 1000 + (ulong)ts.Milliseconds;
                    int      trick    = j / 4;
                    timeTemp[trick] = timeTemp[trick] + (ulong)realTime;
                }
                else
                {
                    chosenCard = players[currentPlayerID].Play();
                }
                game.PlayCard(currentPlayerID, chosenCard);
                //Console.WriteLine("Player " + currentPlayerID + " has played " + Card.ToString(chosenCard));
                for (int k = 0; k < 4; k++)
                {
                    players[k].AddPlay(currentPlayerID, chosenCard);
                }
                currentPlayerID = game.GetNextPlayerId();
            }

            int[] points = game.GetGamePoints();
            if (points[0] == 60)
            {
                localCount[0]++;
            }
            else if (points[0] > 60)
            {
                localCount[1]++;
            }
            else
            {
                localCount[2]++;
            }

            if (SAVE_CARDS)
            {
                lock (allGamesLock)
                {
                    cardsPerPlayer.Add(handsPerPlayer);
                    trumps.Add(trumpSuit);
                    firstPlayers.Add(first);
                    finalBotTeamPoints.Add(points[0]);
                    timePerTrick.Add(timeTemp);
                }
            }

            return(localCount);
        }