示例#1
0
 public PerfectInformationGame(PlayerNode p0, PlayerNode p1, PlayerNode p2, PlayerNode p3, int trumpSuit, List <Trick> pastMoves, int myTeamPoints, int otherTeamPoints, bool HYBRID_FLAG = false, int hybridTrickChange = 5)
 {
     players = new PlayerNode[4] {
         p0, p1, p2, p3
     };
     trump  = trumpSuit;
     tricks = new List <Trick>(10);
     foreach (Trick t in pastMoves)
     {
         Trick copyTrick = new Trick(trumpSuit);
         foreach (Move m in t.GetMoves())
         {
             copyTrick.ApplyMove(m);
             foreach (PlayerNode p in players)
             {
                 p.ApplyMove(m);
             }
         }
         tricks.Add(copyTrick);
     }
     firstTeamPoints        = myTeamPoints;
     secondTeamPoints       = otherTeamPoints;
     predictableTrickWinner = -1;
     predictableTrickCut    = false;
     hybridFlag             = HYBRID_FLAG;
     this.hybridTrickChange = hybridTrickChange;
 }
示例#2
0
        internal void UndoMove(Move move)
        {
            if (tricks.Count - 1 < 0)
            {
                Console.WriteLine("PerfectInformationGame.UndoMove >> Negative index");
                //System.Environment.Exit(1);
            }

            predictableTrickWinner = -1;
            predictableTrickCut    = false;
            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.IsFull())
            {
                int[] winnerPoints = currentTrick.GetTrickWinnerAndPoints();
                if (winnerPoints[0] == players[0].Id || winnerPoints[0] == (players[0].Id + 2) % 4)
                {
                    firstTeamPoints -= winnerPoints[1];
                }
                else
                {
                    secondTeamPoints -= winnerPoints[1];
                }
            }
            currentTrick.UndoMove();
            if (currentTrick.IsEmpty())
            {
                tricks.RemoveAt(tricks.Count - 1);
            }
            foreach (PlayerNode p in players)
            {
                //TODO review if is this the correct method
                p.UndoMove(move);
            }
        }
        public int[] GetWinnerAndPointsAndTrickNumber()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            int[] trickAndWinner = currentTrick.GetTrickWinnerAndPoints();
            return(new int[] { trickAndWinner[0], trickAndWinner[1], tricks.Count - 1 });
        }
示例#4
0
        internal void ApplyMove(Move move)
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.IsFull())
            {
                tricks.Add(new Trick(trump));
                currentTrick = tricks[tricks.Count - 1];
            }
            currentTrick.ApplyMove(move);

            if (currentTrick.IsFull())
            {
                predictableTrickWinner = -1;
                predictableTrickCut    = false;
                int[] winnerPoints = currentTrick.GetTrickWinnerAndPoints();
                if (winnerPoints[0] == players[0].Id || winnerPoints[0] == (players[0].Id + 2) % 4)
                {
                    firstTeamPoints += winnerPoints[1];
                }
                else
                {
                    secondTeamPoints += winnerPoints[1];
                }
            }

            foreach (var p in players)
            {
                //TODO review if is this the correct method
                p.ApplyMove(move);
            }
        }
        public void RemovePlay(int playerId, int card)
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.IsFull())
            {
                int[] winnerPoints = currentTrick.GetTrickWinnerAndPoints();
                if (winnerPoints[0] == id || winnerPoints[0] == (id + 2) % 4)
                {
                    MyTeamPoints -= winnerPoints[1];
                }
                else
                {
                    //TODO checks valence of points!!!
                    OtherTeamPoints -= winnerPoints[1];
                }
            }

            currentTrick.UndoMove();

            if (currentTrick.IsEmpty())
            {
                tricks.RemoveAt(tricks.Count - 1);
            }

            if (playerId == id)
            {
                hand.Add(card);
            }
            else
            {
                int cardSuit = Card.GetSuit(card);
                if (!suitHasPlayer[cardSuit].Contains(playerId))
                {
                    suitHasPlayer[cardSuit].Add(playerId);
                }
                if (TrumpCard == card)
                {
                    trumpCardWasPlayed = false;
                }
                else
                {
                    unknownOwnerCards.Add(card);
                }
                if (Card.GetValue(card) > 0)
                {
                    othersPointCards[Card.GetSuit(card)].Add(Card.GetRank(card));
                }
            }

            if (Card.GetSuit(card) == Trump)
            {
                remainingTrumps++;
            }
        }
示例#6
0
        public void PrintCurrentTrick()
        {
            Console.WriteLine("Current trick:");
            Trick currentTrick = tricks[tricks.Count - 1];

            if (!currentTrick.IsFull())
            {
                currentTrick.PrintTrick();
            }
            Console.WriteLine("");
        }
        public int GetZeroSumTrickScore()
        {
            Trick currentTrick = tricks[tricks.Count - 1];
            int   trickPoints  = currentTrick.GetCurrentTrickPoints();
            int   trickWinner  = currentTrick.GetCurrentTrickWinner();

            if (trickWinner != id && trickWinner != (id + 2) % 4)
            {
                trickPoints *= -1;
            }
            return(trickPoints);
        }
示例#8
0
 public void PrintLastTrick()
 {
     if (tricks.Count > 0 && tricks[0].IsFull())
     {
         Console.WriteLine("Last trick:");
         Trick currentTrick = tricks[tricks.Count - 1];
         if (currentTrick.IsFull())
         {
             currentTrick.PrintTrick();
         }
         else
         {
             tricks[tricks.Count - 2].PrintTrick();
         }
         Console.WriteLine("");
     }
 }
示例#9
0
        public void PlayCard(int playerId, int card)
        {
            if (tricks.Count - 1 < 0)
            {
                Console.WriteLine("SuecaGame.PlayerCard >> Negative index");
                //System.Environment.Exit(1);
            }

            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.IsFull())
            {
                tricks.Add(new Trick(trump));
                currentTrick = tricks[tricks.Count - 1];
            }
            currentTrick.ApplyMove(new Move(playerId, card));
        }
示例#10
0
        public void predictTrickWinner()
        {
            Trick currentTrick    = tricks[tricks.Count - 1];
            int   winningCard     = currentTrick.GetCurrentWinningCard();
            int   winningPlayerId = currentTrick.GetCurrentWinningPlayer();
            int   remainingPlays  = 4 - currentTrick.GetCurrentTrickSize();
            int   leadSuit        = currentTrick.LeadSuit;

            if (winningCard == -1)
            {
                Console.WriteLine("PIG::predictTrickWinner >> Impossible winningCard");
            }

            //if (Card.GetSuit(winningCard) != leadSuit)
            //{
            //    predictableTrickCut = true;
            //}
            predictableTrickCut = false;

            for (int i = 0, pid = currentTrick.GetNextPlayerId(); i < remainingPlays; i++, pid = (pid + 1) % 4)
            {
                int bestCard = players[pid].GetHighestRankFromSuit(leadSuit, trump);
                if (bestCard == -1)
                {
                    //the player does not have the leadsuit neigher the trump
                    continue;
                }

                if (Card.GetSuit(bestCard) != leadSuit)
                {
                    if (Card.GetSuit(winningCard) == leadSuit || Card.GetRank(bestCard) > Card.GetRank(winningCard))
                    {
                        predictableTrickCut    = true;
                        winningCard            = bestCard;
                        predictableTrickWinner = pid;
                    }
                }
                else if (Card.GetRank(bestCard) > Card.GetRank(winningCard) && !predictableTrickCut)
                {
                    winningCard            = bestCard;
                    predictableTrickWinner = pid;
                }
            }
        }
示例#11
0
        public List <int> orderPossibleMoves(List <int> moves, int playerID)
        {
            Trick currentTrick     = tricks[tricks.Count - 1];
            int   leadSuit         = currentTrick.LeadSuit;
            int   currentTrickSize = currentTrick.GetCurrentTrickSize();

            if (moves.Count == 1)
            {
                return(moves);
            }

            if (currentTrickSize == 0)
            {
                AscendingComparer ac = new AscendingComparer();
                moves.Sort(ac);
                return(moves);
            }

            if (predictableTrickWinner == -1)
            {
                predictTrickWinner();
            }

            if (!predictableTrickCut && (predictableTrickWinner == playerID || predictableTrickWinner == (playerID + 2) % 4))
            {
                AscendingComparer ac = new AscendingComparer();
                moves.Sort(ac);
            }
            else if (predictableTrickCut && (predictableTrickWinner == playerID || predictableTrickWinner == (playerID + 2) % 4))
            {
                AscendingCutComparer acc = new AscendingCutComparer(trump);
                moves.Sort(acc);
            }
            else
            {
                DescendingComparer dc = new DescendingComparer();
                moves.Sort(dc);
            }

            return(moves);
        }
示例#12
0
        public string GetLastPlayInfo()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.LastPlayIsNewTrick())
            {
                return(Sueca.PLAY_INFO_NEWTRICK);
            }
            else if (currentTrick.LastPlayIsFollowing())
            {
                return(Sueca.PLAY_INFO_FOLLOWING);
            }
            else if (currentTrick.LastPlayIsCut())
            {
                return(Sueca.PLAY_INFO_CUT);
            }
            else
            {
                return(Sueca.PLAY_INFO_NOTFOLLOWING);
            }
        }
示例#13
0
        internal int GetCurrentTrickResponsible()
        {
            Trick currentTrick = tricks[tricks.Count - 1];
            int   partnerID    = ((id + 2) % 4);
            int   winnerId     = currentTrick.GetCurrentTrickWinner();

            if (!currentTrick.IsFull())
            {
                Console.WriteLine("Current trick is not full to call GetResponsible!");
                if (tricks.Count > 1)
                {
                    currentTrick = tricks[tricks.Count - 2];
                }
            }

            if (currentTrick.IsFull())
            {
                if (winnerId == id || winnerId == partnerID)
                {
                    return(winnerId);
                }
                else
                {
                    int myPlayPoints      = Card.GetValue(currentTrick.GetPlayOf(id));
                    int partnerPlayPoints = Card.GetValue(currentTrick.GetPlayOf(partnerID));
                    if (myPlayPoints > 0 || partnerPlayPoints > 0)
                    {
                        return(myPlayPoints >= partnerPlayPoints ? id : partnerID);
                    }
                    else
                    {
                        return(winnerId);
                    }
                }
            }
            return(winnerId);
        }
示例#14
0
        public int GetCurrentTrickWinner()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(currentTrick.GetCurrentWinningPlayer());
        }
示例#15
0
        public void AddPlay(int playerID, int card)
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            if (currentTrick.IsFull())
            {
                int[] winnerPoints = currentTrick.GetTrickWinnerAndPoints();
                if (winnerPoints[0] == id || winnerPoints[0] == (id + 2) % 4)
                {
                    MyTeamPoints += winnerPoints[1];
                }
                else
                {
                    //TODO checks valence of points!!!
                    OtherTeamPoints += winnerPoints[1];
                }
                tricks.Add(new Trick(Trump));
                currentTrick = tricks[tricks.Count - 1];
            }

            //check if player has the leadSuit
            int leadSuit  = currentTrick.LeadSuit;
            int cardSuit  = Card.GetSuit(card);
            int cardValue = Card.GetValue(card);

            if (playerID != id && cardSuit == leadSuit && !suitHasPlayer[leadSuit].Contains(playerID))
            {
                Console.WriteLine("AddPlay: The player has renounced!");
            }

            currentTrick.ApplyMove(new Move(playerID, card));

            if (playerID != id && cardSuit != leadSuit && leadSuit != (int)Suit.None)
            {
                if (suitHasPlayer[leadSuit].Contains(playerID))
                {
                    suitHasPlayer[leadSuit].Remove(playerID);
                }
            }

            if (cardSuit == Trump)
            {
                remainingTrumps--;
            }
            if (playerID == id)
            {
                if (hand.Remove(card) == false)
                {
                    //Console.WriteLine("INFOSET Trying to remove an nonexisting card!!!");
                }
            }
            else
            {
                if (TrumpCard == card)
                {
                    trumpCardWasPlayed = true;
                }
                else
                {
                    if (unknownOwnerCards.RemoveCard(card) == false)
                    {
                        Console.WriteLine("FILIPA");
                    }
                }
                if (cardValue > 0)
                {
                    othersPointCards[cardSuit].Remove(Card.GetRank(card));
                }
            }
        }
示例#16
0
        public int GetTrickIncrease()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(currentTrick.GetTrickIncrease());
        }
示例#17
0
        internal bool IsLastPlayOfTrick()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(currentTrick.IsLastPlayOfTrick());
        }
示例#18
0
        public bool HasNewTrickTeamWinner()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(currentTrick.HasNewTrickTeamWinner());
        }
示例#19
0
        public List <int> GetPossibleMoves()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(Sueca.PossibleMoves(hand, currentTrick.LeadSuit));
        }
示例#20
0
        public int GetCurrentTrickPoints()
        {
            Trick currentTrick = tricks[tricks.Count - 1];

            return(currentTrick.GetCurrentTrickPoints());
        }