public static void Main() { Stopwatch sw = new Stopwatch(); sw.Start(); //int seed = Guid.NewGuid().GetHashCode(); //Random randomNumber = new Random(seed); //int NUM_TRICKS = 10; //Deck deck = new Deck(randomNumber, seed); //List<int> hand = deck.GetHand(NUM_TRICKS); //InformationSet infoSet = new InformationSet(hand, (int)Suit.Clubs, randomNumber, seed); //int card = deck.GetRandomCard(); //infoSet.AddPlay(3, card); //Console.WriteLine(Card.ToString(card)); //PIMC pimc = new PIMC(); //pimc.ExecuteWithTimeLimit(infoSet); //infoSet.PrintInfoSet(); //List<int> p0 = new List<int>() //{Card.Create(Rank.Jack, Suit.Clubs), // Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.Jack, Suit.Hearts), // Card.Create(Rank.King, Suit.Hearts), // Card.Create(Rank.Two, Suit.Spades), // Card.Create(Rank.Jack, Suit.Spades), // Card.Create(Rank.Seven, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Two, Suit.Diamonds), // Card.Create(Rank.Queen, Suit.Hearts), // Card.Create(Rank.Four, Suit.Spades), // Card.Create(Rank.Six, Suit.Spades), // Card.Create(Rank.Queen, Suit.Spades), // Card.Create(Rank.Ace, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Two, Suit.Clubs), // Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.Queen, Suit.Clubs), // Card.Create(Rank.King, Suit.Clubs), // Card.Create(Rank.Ace, Suit.Clubs), // Card.Create(Rank.Four, Suit.Diamonds), // Card.Create(Rank.King, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Five, Suit.Clubs), // Card.Create(Rank.Seven, Suit.Clubs), // Card.Create(Rank.Three, Suit.Diamonds), // Card.Create(Rank.Six, Suit.Diamonds), // Card.Create(Rank.King, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Diamonds), // Card.Create(Rank.Four, Suit.Hearts) //}; //List<int> p0 = new List<int>() //{Card.Create(Rank.Four, Suit.Diamonds), // Card.Create(Rank.Six, Suit.Diamonds), // Card.Create(Rank.Jack, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Diamonds), // Card.Create(Rank.Ace, Suit.Hearts), // Card.Create(Rank.Five, Suit.Spades), // Card.Create(Rank.Seven, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.King, Suit.Diamonds), // Card.Create(Rank.Two, Suit.Hearts), // Card.Create(Rank.Six, Suit.Hearts), // Card.Create(Rank.Two, Suit.Spades), // Card.Create(Rank.Jack, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Two, Suit.Clubs), // Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.King, Suit.Clubs), // Card.Create(Rank.Two, Suit.Diamonds), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.King, Suit.Hearts), // Card.Create(Rank.Queen, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Queen, Suit.Clubs), // Card.Create(Rank.Ace, Suit.Diamonds), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Four, Suit.Hearts), // Card.Create(Rank.Four, Suit.Spades), // Card.Create(Rank.Six, Suit.Spades), // Card.Create(Rank.King, Suit.Spades) //}; //List<int> p0 = new List<int>() //{Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Seven, Suit.Clubs), // Card.Create(Rank.Two, Suit.Hearts), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.Seven, Suit.Hearts), // Card.Create(Rank.Two, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Queen, Suit.Clubs), // Card.Create(Rank.King, Suit.Clubs), // Card.Create(Rank.Three, Suit.Diamonds), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Six, Suit.Hearts), // Card.Create(Rank.Five, Suit.Spades), // Card.Create(Rank.Seven, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Jack, Suit.Clubs), // Card.Create(Rank.Four, Suit.Diamonds), // Card.Create(Rank.Six, Suit.Diamonds), // Card.Create(Rank.Queen, Suit.Diamonds), // Card.Create(Rank.King, Suit.Diamonds), // Card.Create(Rank.Jack, Suit.Hearts), // Card.Create(Rank.Queen, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.Ace, Suit.Hearts), // Card.Create(Rank.Three, Suit.Spades), // Card.Create(Rank.Four, Suit.Spades), // Card.Create(Rank.Jack, Suit.Spades), // Card.Create(Rank.King, Suit.Spades), // Card.Create(Rank.Ace, Suit.Spades) //}; //List<int> p0 = new List<int>() //{Card.Create(Rank.Four, Suit.Clubs), // Card.Create(Rank.Jack, Suit.Clubs), // Card.Create(Rank.Two, Suit.Diamonds), // Card.Create(Rank.Ace, Suit.Diamonds), // Card.Create(Rank.Queen, Suit.Hearts), // Card.Create(Rank.Ace, Suit.Hearts), // Card.Create(Rank.King, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Ace, Suit.Clubs), // Card.Create(Rank.Jack, Suit.Diamonds), // Card.Create(Rank.King, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Diamonds), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.Four, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Five, Suit.Clubs), // Card.Create(Rank.King, Suit.Clubs), // Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.Four, Suit.Spades), // Card.Create(Rank.Jack, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Seven, Suit.Clubs), // Card.Create(Rank.Jack, Suit.Hearts), // Card.Create(Rank.Seven, Suit.Hearts), // Card.Create(Rank.Two, Suit.Spades), // Card.Create(Rank.Three, Suit.Spades) //}; //List<int> p0 = new List<int>() //{Card.Create(Rank.Five, Suit.Clubs), // Card.Create(Rank.Seven, Suit.Clubs), // Card.Create(Rank.Four, Suit.Diamonds), // Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.Queen, Suit.Diamonds), // Card.Create(Rank.Two, Suit.Spades), // Card.Create(Rank.Six, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Queen, Suit.Clubs), // Card.Create(Rank.Two, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Diamonds), // Card.Create(Rank.Four, Suit.Hearts), // Card.Create(Rank.Five, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Jack, Suit.Clubs), // Card.Create(Rank.Ace, Suit.Clubs), // Card.Create(Rank.Jack, Suit.Diamonds), // Card.Create(Rank.Ace, Suit.Diamonds), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.King, Suit.Spades), // Card.Create(Rank.Ace, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Two, Suit.Hearts), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Six, Suit.Hearts), // Card.Create(Rank.King, Suit.Hearts), // Card.Create(Rank.Seven, Suit.Hearts), // Card.Create(Rank.Three, Suit.Spades), // Card.Create(Rank.Queen, Suit.Spades) //}; //List<int> p0 = new List<int>() //{Card.Create(Rank.Four, Suit.Diamonds), // Card.Create(Rank.Six, Suit.Diamonds), // Card.Create(Rank.Jack, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Diamonds), // Card.Create(Rank.Ace, Suit.Hearts), // Card.Create(Rank.Five, Suit.Spades), // Card.Create(Rank.Four, Suit.Clubs), // Card.Create(Rank.Two, Suit.Hearts), // Card.Create(Rank.Ace, Suit.Clubs), // Card.Create(Rank.Seven, Suit.Spades) //}; //List<int> p1 = new List<int>() //{Card.Create(Rank.Six, Suit.Clubs), // Card.Create(Rank.Five, Suit.Diamonds), // Card.Create(Rank.King, Suit.Diamonds), // Card.Create(Rank.Seven, Suit.Clubs), // Card.Create(Rank.Six, Suit.Hearts), // Card.Create(Rank.Two, Suit.Spades), // Card.Create(Rank.Three, Suit.Hearts), // Card.Create(Rank.Seven, Suit.Hearts), // Card.Create(Rank.Three, Suit.Spades), // Card.Create(Rank.Jack, Suit.Spades) //}; //List<int> p2 = new List<int>() //{Card.Create(Rank.Two, Suit.Clubs), // Card.Create(Rank.Three, Suit.Clubs), // Card.Create(Rank.King, Suit.Clubs), // Card.Create(Rank.Two, Suit.Diamonds), // Card.Create(Rank.Five, Suit.Hearts), // Card.Create(Rank.King, Suit.Hearts), // Card.Create(Rank.Ace, Suit.Diamonds), // Card.Create(Rank.Queen, Suit.Diamonds), // Card.Create(Rank.Jack, Suit.Clubs), // Card.Create(Rank.Queen, Suit.Spades) //}; //List<int> p3 = new List<int>() //{Card.Create(Rank.Queen, Suit.Clubs), // Card.Create(Rank.Ace, Suit.Spades), // Card.Create(Rank.Three, Suit.Diamonds), // Card.Create(Rank.Four, Suit.Hearts), // Card.Create(Rank.Four, Suit.Spades), // Card.Create(Rank.Six, Suit.Spades), // Card.Create(Rank.Jack, Suit.Hearts), // Card.Create(Rank.Five, Suit.Clubs), // Card.Create(Rank.Queen, Suit.Hearts), // Card.Create(Rank.King, Suit.Spades) //}; //List<List<int>> playersHands = new List<List<int>>(); //playersHands.Add(p0); //playersHands.Add(p1); //playersHands.Add(p2); //playersHands.Add(p3); //Sueca.PrintCards("Initial hand", p0); //List<int> p0Copy = new List<int>(p0); //MaxNode max0 = new MaxNode(0, p0Copy, false); //MinNode min1 = new MinNode(1, p1, false); //MaxNode max2 = new MaxNode(2, p2, false); //MinNode min3 = new MinNode(3, p3, false); //PerfectInformationGame lol = new PerfectInformationGame(max0, min1, max2, min3, p0Copy.Count, (int)Suit.Clubs, new List<Move>(), 0, 0); //int cardValue = lol.SampleGame(10, p0[0]); //Console.WriteLine("Card: " + Card.ToString(p0[0]) + " value: " + cardValue); int NUM_TRICKS = 10; Deck deck = new Deck(); int playerId = 2; int dealerId = (playerId - 1 + 4) % 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.SampleHands(ref playersHands); RBOPlayer ep = new RBOPlayer(playerId, playersHands[playerId], playersHands[dealerId][0], dealerId); //HybridPlayer ep = new HybridPlayer(playerId, playersHands[playerId], playersHands[dealerId][0], dealerId); //RuleBasedPlayer ep = new RuleBasedPlayer(playerId, playersHands[playerId], playersHands[dealerId][0], dealerId); //SmartPlayer ep = new SmartPlayer(playerId, playersHands[playerId], playersHands[dealerId][0], dealerId); //TrickPlayer ep = new TrickPlayer(playerId, playersHands[playerId], playersHands[dealerId][0], dealerId); Sueca.PrintCards("Initial hand", playersHands[playerId]); int chosenCard = ep.Play(); Console.WriteLine("Chosen card: " + Card.ToString(chosenCard)); sw.Stop(); Console.WriteLine("Total Time taken by functions is {0} seconds", sw.ElapsedMilliseconds / 1000); //seconds }
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); }