public override int PlayGame(PerfectInformationGame pig, int alpha, int beta, int depthLimit, int card) { int v = Int16.MinValue; List <int> cards; if (Sueca.UTILITY_FUNC == 2 && pig.IsAnyTeamWinning()) { return(pig.EvalGame2()); } if (pig.reachedDepthLimit(depthLimit) || pig.IsEndGame()) { return(pig.EvalGame1()); } if (card == -1) { cards = Sueca.PossibleMoves(Hand, pig.GetLeadSuit()); pig.orderPossibleMoves(cards, Id); } else { cards = new List <int>(); cards.Add(card); } foreach (int c in cards) { Move move = new Move(Id, c); pig.ApplyMove(move); int moveValue = pig.GetNextPlayer().PlayGame(pig, alpha, beta, depthLimit); if (moveValue > v) { v = moveValue; } pig.UndoMove(move); if (v >= beta) { return(v); } if (v > alpha) { alpha = v; } } return(v); }
override public int Play() { if (currentPlay == 0) { leadSuit = (int)Suit.None; } List <int> possibleMoves = Sueca.PossibleMoves(hand, leadSuit); int randomIndex = randomNumber.Next(0, possibleMoves.Count); int chosenCard = possibleMoves[randomIndex]; hand.Remove(chosenCard); return(chosenCard); }
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 }
public List <int> GetPossibleMoves() { Trick currentTrick = tricks[tricks.Count - 1]; return(Sueca.PossibleMoves(hand, currentTrick.LeadSuit)); }
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(); }