예제 #1
0
        public void GameStart(int gameId, int playerId, int teamId, string trumpCard, int trumpCardPlayer, string[] cards)
        {
            _initialyzing = true;
            SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_START);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_START, Consts.DEFAULT_SUBJECT);
            ev.Finished = true;

            List <int> initialCards = new List <int>();

            foreach (string cardSerialized in cards)
            {
                SuecaTypes.Card  card   = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(cardSerialized);
                SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), card.Rank.ToString());
                SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), card.Suit.ToString());
                int myCard = SuecaSolver.Card.Create(myRank, mySuit);
                initialCards.Add(myCard);
            }
            SuecaTypes.Card  sharedTrumpCard = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(trumpCard);
            SuecaSolver.Rank trumpRank       = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), sharedTrumpCard.Rank.ToString());
            SuecaSolver.Suit trumpSuit       = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), sharedTrumpCard.Suit.ToString());
            int myTrumpCard = SuecaSolver.Card.Create(trumpRank, trumpSuit);

            _ai           = new RuleBasedPlayer(playerId, initialCards, myTrumpCard, trumpCardPlayer);
            _initialyzing = false;
        }
예제 #2
0
        public void GameStart(int gameId, int playerId, int teamId, string trumpCard, int trumpCardPlayer, string[] cards)
        {
            if (id == playerId)
            {
                moveCounter = 0;
                SuecaTypes.Card  sharedTrumpCard = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(trumpCard);
                SuecaSolver.Rank trumpRank       = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), sharedTrumpCard.Rank.ToString());
                SuecaSolver.Suit trumpSuit       = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), sharedTrumpCard.Suit.ToString());
                int myTrumpCard = SuecaSolver.Card.Create(trumpRank, trumpSuit);
                this.teamId = teamId;
                List <int> initialCards = new List <int>();
                Console.Write("GameStart cards: ");
                foreach (string cardSerialized in cards)
                {
                    SuecaTypes.Card  card   = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(cardSerialized);
                    SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), card.Rank.ToString());
                    SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), card.Suit.ToString());
                    int myCard = SuecaSolver.Card.Create(myRank, mySuit);
                    Console.Write(SuecaSolver.Card.ToString(myCard) + " ");
                    initialCards.Add(myCard);
                }
                Console.WriteLine("");

                ai               = new RBOPlayer(playerId, initialCards, myTrumpCard, trumpCardPlayer);
                allSet           = true;
                processingRepeat = false;

                iaPublisher.ForwardGameStart(gameId, playerId, teamId, trumpCard, trumpCardPlayer, cards);
            }
        }
예제 #3
0
 private string serializeCard(int card)
 {
     SuecaSolver.Rank cardRank = (SuecaSolver.Rank)SuecaSolver.Card.GetRank(card);
     SuecaSolver.Suit cardSuit = (SuecaSolver.Suit)SuecaSolver.Card.GetSuit(card);
     SuecaTypes.Rank  msgRank  = (SuecaTypes.Rank)Enum.Parse(typeof(SuecaTypes.Rank), cardRank.ToString());
     SuecaTypes.Suit  msgSuit  = (SuecaTypes.Suit)Enum.Parse(typeof(SuecaTypes.Suit), cardSuit.ToString());
     return(new SuecaTypes.Card(msgRank, msgSuit).SerializeToJson());
 }
예제 #4
0
        public void GameStart(int gameId, int playerId, int teamId, string trumpCard, int trumpCardPlayer, string[] cards, int floorId)
        {
            int playerID1 = _randomNumberGenerator.Next(1, 2);
            int playerID2 = ((playerID1 + 1) % 2);

            SuecaPub.GazeAtTarget("player" + playerID1);
            if (playerId == _id)
            {
                _initialyzing = true;

                _teamId               = teamId;
                _currentGameId        = gameId;
                _currentTrickId       = 0;
                _currentPlayInTrickId = 0;

                if (gameId != 0)
                {
                    //Console.WriteLine("next games");
                    SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_START);
                    _suecaRPC.AddSuecaEvent(ev);
                    ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_START, Consts.DEFAULT_SUBJECT);
                    ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
                    ev.ChangeTagsAndMeanings(new string[] { "|playerID1|", "|playerID2|" }, new string[] { playerID1.ToString(), playerID2.ToString() });
                    ev.Finished = true;
                }

                List <int> initialCards = new List <int>();
                foreach (string cardSerialized in cards)
                {
                    SuecaTypes.Card  card   = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(cardSerialized);
                    SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), card.Rank.ToString());
                    SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), card.Suit.ToString());
                    int myCard = SuecaSolver.Card.Create(myRank, mySuit);
                    initialCards.Add(myCard);
                }
                SuecaTypes.Card  sharedTrumpCard = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(trumpCard);
                SuecaSolver.Rank trumpRank       = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), sharedTrumpCard.Rank.ToString());
                SuecaSolver.Suit trumpSuit       = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), sharedTrumpCard.Suit.ToString());
                int myTrumpCard = SuecaSolver.Card.Create(trumpRank, trumpSuit);

                if (_nameId == 1)
                {
                    _ai = new RBOPlayer(playerId, initialCards, myTrumpCard, trumpCardPlayer);
                }
                else if (_nameId == 2)
                {
                    _ai = new RKOPlayer(playerId, initialCards, myTrumpCard, trumpCardPlayer);
                }
                Console.WriteLine("MY NAME IS {0}.", _nameId);
                _initialyzing = false;
            }
        }
예제 #5
0
        public void Play(int id, string card, string playInfo)
        {
            SuecaTypes.Card  c      = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(card);
            SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), c.Rank.ToString());
            SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), c.Suit.ToString());
            int myCard = SuecaSolver.Card.Create(myRank, mySuit);

            if (_ai != null && id != this._id)
            {
                SuecaEvent ev = new SuecaEvent(Consts.STATE_PLAY);
                _suecaRPC.AddSuecaEvent(ev);
                ev.AddPropertyChange(Consts.CURRENT_PLAYER, checkTeam(id), Consts.DEFAULT_SUBJECT);
                _ai.AddPlay(id, myCard);
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_PLAY, Consts.DEFAULT_SUBJECT);
                string[] tags     = new string[] { "|rank|", "|suit|", "|playerId|" };
                string[] meanings = new string[] { convertRankToPortuguese(myRank.ToString()), convertSuitToPortuguese(mySuit.ToString()), id.ToString() };
                ev.ChangeTagsAndMeanings(tags, meanings);

                int  currentPlayPoints = _ai.GetCurrentTrickPoints();
                bool hasNewTrickWinner = _ai.HasNewTrickTeamWinner();
                bool lastPlayOfTrick   = _ai.IsLastPlayOfTrick();

                ev.AddPropertyChange(Consts.TRICK_SCORE, currentPlayPoints.ToString(), checkTeam(id));

                //if (hasNewTrickWinner && !lastPlayOfTrick && !robotHasPlayed)
                if (hasNewTrickWinner && !lastPlayOfTrick)
                {
                    int    currentWinnerID = _ai.GetCurrentTrickWinner();
                    string lastPlayInfo    = _ai.GetLastPlayInfo();
                    if (lastPlayInfo == Sueca.PLAY_INFO_NEWTRICK)
                    {
                        ev.AddPropertyChange(Consts.TRICK_WINNER, checkTeam(currentWinnerID), Sueca.PLAY_INFO_NEWTRICK);
                    }
                    else
                    {
                        ev.AddPropertyChange(Consts.TRICK_WINNER, checkTeam(currentWinnerID), checkTeam(id));
                    }

                    int trickIncrease = _ai.GetTrickIncrease();

                    if (trickIncrease > 0)
                    {
                        ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, trickIncrease.ToString(), checkTeam(id));
                    }
                }
                ev.Finished = true;
            }
        }
        public void Play(int id, string card, string playInfo, int floorId)
        {
            SuecaTypes.Card  c      = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(card);
            SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), c.Rank.ToString());
            SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), c.Suit.ToString());
            int myCard = SuecaSolver.Card.Create(myRank, mySuit);

            if (_ai != null && id != this._id)
            {
                SuecaPub.GazeAtTarget("player" + id);

                SuecaEvent ev = new SuecaEvent(Consts.STATE_PLAYPARTNER);
                _suecaRPC.AddSuecaEvent(ev);
                ev.AddPropertyChange(Consts.CURRENT_PLAYER, SubjectName(id), Consts.DEFAULT_SUBJECT);
                _ai.AddPlay(id, myCard);
                string[] tags     = new string[] { "|rank|", "|suit|", "|playerID|", "|nextPlayerID|" };
                string[] meanings = new string[] { ConvertRankToPortuguese(myRank.ToString()), ConvertSuitToPortuguese(mySuit.ToString()), id.ToString(), _ai.GetNextPlayerId().ToString() };
                ev.ChangeTagsAndMeanings(tags, meanings);

                SuecaPub.GazeAtTarget("cardsZone");

                if (_ai.GetTrickIncrease() > 0 || _ai.HasNewTrickTeamWinner())
                {
                    ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, "True", SubjectName(id));
                }
                else
                {
                    ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, "False", SubjectName(id));
                }

                int trickScore = _ai.GetZeroSumTrickScore();
                Console.WriteLine("EMYS" + _nameId + " the current trickScore is: " + trickScore);
                ev.AddPropertyChange(Consts.TRICK_SCORE, trickScore.ToString(), SubjectName(id));


                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_PLAYPARTNER, Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
                ev.OtherIntInfos = new int[] { id };
                ev.Finished      = true;
                _currentPlayInTrickId++;
            }
        }
        public void NextPlayer(int id, int floorId)
        {
            //NextPlayer events arrive to Thalamus Client around 10miliseconds later than Play events, however this method is called first than Play
            //This sleep allows Play event to be fully processed before the next player
            SuecaEvent ev = new SuecaEvent(Consts.STATE_NEXT_PLAYER);

            _suecaRPC.AddSuecaEvent(ev);
            Thread.Sleep(500);

            //Console.WriteLine("The next player is {0}.", id);

            //If a GameStart event has been received but not fully proccessed wait
            while (_initialyzing)
            {
            }

            if (this._id == id && _ai != null)
            {
                SuecaPub.GazeAtTarget("cards" + _id);
                int chosenCard = _ai.Play();
                _ai.AddPlay(id, chosenCard);

                SuecaSolver.Rank chosenCardRank = (SuecaSolver.Rank)SuecaSolver.Card.GetRank(chosenCard);
                SuecaSolver.Suit chosenCardSuit = (SuecaSolver.Suit)SuecaSolver.Card.GetSuit(chosenCard);
                SuecaTypes.Rank  msgRank        = (SuecaTypes.Rank)Enum.Parse(typeof(SuecaTypes.Rank), chosenCardRank.ToString());
                SuecaTypes.Suit  msgSuit        = (SuecaTypes.Suit)Enum.Parse(typeof(SuecaTypes.Suit), chosenCardSuit.ToString());
                string           cardSerialized = new SuecaTypes.Card(msgRank, msgSuit).SerializeToJson();
                string           playInfo       = _ai.GetLastPlayInfo();

                //ev.AddPropertyChange(Consts.PLAY_INFO, playInfo, Consts.DEFAULT_SUBJECT);


                ev.ChangeTagsAndMeanings(new string[] { "|rank|", "|suit|", "|playerID|", "|nextPlayerID|" }, new string[] { ConvertRankToPortuguese(msgRank.ToString()), ConvertSuitToPortuguese(msgSuit.ToString()), ((id + 2) % 4).ToString(), _ai.GetNextPlayerId().ToString() });
                ev.OtherIntInfos    = new int[] { this._id };
                ev.OtherStringInfos = new string[] { cardSerialized, playInfo };

                if (_ai.GetTrickIncrease() > 0 || _ai.HasNewTrickTeamWinner())
                {
                    ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, "True", SubjectName(id));
                }
                else
                {
                    ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, "False", SubjectName(id));
                }

                int trickScore = _ai.GetZeroSumTrickScore();
                Console.WriteLine("EMYS" + _nameId + " the current trickScore is: " + trickScore);
                ev.AddPropertyChange(Consts.TRICK_SCORE, trickScore.ToString(), SubjectName(id));

                ev.Name = Consts.STATE_PLAYSELF;
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_PLAYSELF, Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, _id.ToString(), Consts.DEFAULT_SUBJECT);
            }
            else
            {
                ev.AddPropertyChange(Consts.NEXT_PLAYER, SubjectName(id), Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_NEXT_PLAYER, Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
                ev.ChangeTagsAndMeanings(new string[] { "|nextPlayerID|" }, new string[] { id.ToString() });
                ev.OtherIntInfos = new int[] { id };
            }
            ev.Finished = true;
        }
예제 #8
0
        public void Play(int id, string card, string playInfo)
        {
            processingPlay = true;
            while (processingRepeat)
            {
            }

            if (ai != null && id != this.id)
            {
                int[] pastWinnerPoints = ai.GetWinnerAndPointsAndTrickNumber();
                iaPublisher.GazeAtTarget("cardsZone");

                SuecaTypes.Card  c      = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(card);
                SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), c.Rank.ToString());
                SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), c.Suit.ToString());
                int myCard = SuecaSolver.Card.Create(myRank, mySuit);
                //int localPlayerId = (id + 4 - myIdOnUnityGame) % 4;
                ai.AddPlay(id, myCard);
                Console.WriteLine("UnityPlayerID " + id + " played " + SuecaSolver.Card.ToString(myCard));

                if (moveCounter % 4 == 0)
                {
                    leadSuit = c.Suit.ToString();
                }
                moveCounter++;



                int[]  newWinnerPoints = ai.GetWinnerAndPointsAndTrickNumber();
                string additionalInfo = "";
                float  desirabilityForOther = 0.0f, desirability = (Math.Min(newWinnerPoints[1], 15) / 15.0f) * 10.0f;

                if (pastWinnerPoints[0] == this.id || pastWinnerPoints[0] == (this.id + 2) % 4)
                {
                    additionalInfo += "OURS_";
                }
                else
                {
                    pastWinnerPoints[1] *= -1;
                    additionalInfo      += "THEIRS_";
                }


                if (newWinnerPoints[0] == this.id || newWinnerPoints[0] == (this.id + 2) % 4)
                {
                    desirabilityForOther -= desirability;
                    additionalInfo       += "OURS_";
                    if (pastWinnerPoints[0] == -1 || pastWinnerPoints[2] != newWinnerPoints[2])
                    {
                        additionalInfo = "OURS_OURS_";
                    }
                }
                else
                {
                    newWinnerPoints[1]   *= -1;
                    desirabilityForOther += desirability;
                    desirability         *= -1;
                    additionalInfo       += "THEIRS_";
                    if (pastWinnerPoints[0] == -1 || pastWinnerPoints[2] != newWinnerPoints[2])
                    {
                        additionalInfo = "THEIRS_THEIRS_";
                    }
                }

                Console.WriteLine("Past trick " + pastWinnerPoints[2] + " current trick " + newWinnerPoints[2]);

                if ((Math.Abs(newWinnerPoints[1] - pastWinnerPoints[1]) >= 10 && pastWinnerPoints[2] == newWinnerPoints[2]) || (Math.Abs(newWinnerPoints[1]) >= 10 && pastWinnerPoints[2] != newWinnerPoints[2]))
                {
                    additionalInfo += "HIGH";
                }
                else if ((Math.Abs(newWinnerPoints[1] - pastWinnerPoints[1]) >= 3) || (Math.Abs(newWinnerPoints[1]) >= 3 && pastWinnerPoints[2] != newWinnerPoints[2]))
                {
                    additionalInfo += "LOW";
                }

                Console.WriteLine("AdditionalInfo of play: " + additionalInfo);

                float totalWins = ourWins + theirWins;
                float ourWinsOfSessionRacio = ourWins / totalWins;
                float theirWinsOfSessionRacio = theirWins / totalWins;
                float ourPointsOfGameRacio = ai.PointsPercentage();
                float theirPointsOfGameRacio = 1.0f - ourPointsOfGameRacio;
                float successProbability, failureProbability;

                if (totalWins != 0)
                {
                    successProbability = 0.5f * ourWinsOfSessionRacio + 0.5f * ourPointsOfGameRacio;
                    failureProbability = 0.5f * theirWinsOfSessionRacio + 0.5f * theirPointsOfGameRacio;
                }
                else
                {
                    successProbability = ourPointsOfGameRacio;
                    failureProbability = theirPointsOfGameRacio;
                }

                iaPublisher.MoveExpectations(id, desirability.ToString(), desirabilityForOther.ToString(), successProbability.ToString(), failureProbability.ToString(), additionalInfo);
            }
            processingPlay = false;
        }
예제 #9
0
        public void NextPlayer(int id)
        {
            while (!allSet)
            {
            }
            while (processingRepeat)
            {
            }
            while (processingPlay)
            {
            }

            iaPublisher.ForwardNextPlayer(id);

            if (this.id == id && ai != null)
            {
                int[] pastWinnerPoints = ai.GetWinnerAndPointsAndTrickNumber();

                Console.WriteLine("I am thinking about what to play...");
                int chosenCard = ai.Play();
                SuecaSolver.Rank chosenCardRank = (SuecaSolver.Rank)SuecaSolver.Card.GetRank(chosenCard);
                SuecaSolver.Suit chosenCardSuit = (SuecaSolver.Suit)SuecaSolver.Card.GetSuit(chosenCard);
                SuecaTypes.Rank  msgRank        = (SuecaTypes.Rank)Enum.Parse(typeof(SuecaTypes.Rank), chosenCardRank.ToString());
                SuecaTypes.Suit  msgSuit        = (SuecaTypes.Suit)Enum.Parse(typeof(SuecaTypes.Suit), chosenCardSuit.ToString());
                string           cardSerialized = new SuecaTypes.Card(msgRank, msgSuit).SerializeToJson();

                ai.AddPlay(id, chosenCard);
                Console.WriteLine("UnityPlayerID " + id + " played " + SuecaSolver.Card.ToString(chosenCard));

                if (moveCounter % 4 == 0)
                {
                    leadSuit = SuecaSolver.Card.GetSuit(chosenCard).ToString();
                }
                moveCounter++;

                int[]  newWinnerPoints = ai.GetWinnerAndPointsAndTrickNumber();
                string additionalInfo = "";
                float  desirabilityForOther = 0.0f, desirability = (Math.Min(newWinnerPoints[1], 15) / 15.0f) * 10.0f;


                if (pastWinnerPoints[0] == this.id || pastWinnerPoints[0] == (this.id + 2) % 4)
                {
                    additionalInfo += "OURS_";
                }
                else
                {
                    pastWinnerPoints[1] *= -1;
                    additionalInfo      += "THEIRS_";
                }

                if (newWinnerPoints[0] == this.id || newWinnerPoints[0] == (this.id + 2) % 4)
                {
                    desirabilityForOther -= desirability;
                    additionalInfo       += "OURS_";
                }
                else
                {
                    newWinnerPoints[1]   *= -1;
                    desirabilityForOther += desirability;
                    desirability         *= -1;
                    additionalInfo       += "THEIRS_";
                }

                Console.WriteLine("Past trick " + pastWinnerPoints[2] + " current trick " + newWinnerPoints[2]);
                if (pastWinnerPoints[0] == -1 || pastWinnerPoints[2] != newWinnerPoints[2])
                {
                    additionalInfo = "NEW_TRICK";
                }
                else if ((Math.Abs(newWinnerPoints[1] - pastWinnerPoints[1]) >= 10) || (Math.Abs(newWinnerPoints[1]) >= 10 && pastWinnerPoints[2] != newWinnerPoints[2]))
                {
                    additionalInfo += "HIGH";
                }
                else if ((Math.Abs(newWinnerPoints[1] - pastWinnerPoints[1]) >= 3) || (Math.Abs(newWinnerPoints[1]) >= 3 && pastWinnerPoints[2] != newWinnerPoints[2]))
                {
                    additionalInfo += "LOW";
                }

                Console.WriteLine("AdditionalInfo of my play: " + additionalInfo);
                iaPublisher.Decision(cardSerialized, chosenCardRank.ToString(), chosenCardSuit.ToString(), additionalInfo);

                float totalWins = ourWins + theirWins;
                float ourWinsOfSessionRacio = ourWins / totalWins;
                float theirWinsOfSessionRacio = theirWins / totalWins;
                float ourPointsOfGameRacio = ai.PointsPercentage();
                float theirPointsOfGameRacio = 1.0f - ourPointsOfGameRacio;
                float successProbability, failureProbability;

                if (totalWins != 0)
                {
                    successProbability = 0.5f * ourWinsOfSessionRacio + 0.5f * ourPointsOfGameRacio;
                    failureProbability = 0.5f * theirWinsOfSessionRacio + 0.5f * theirPointsOfGameRacio;
                }
                else
                {
                    successProbability = ourPointsOfGameRacio;
                    failureProbability = theirPointsOfGameRacio;
                }

                iaPublisher.MoveExpectations(id, desirability.ToString(), desirabilityForOther.ToString(), successProbability.ToString(), failureProbability.ToString(), additionalInfo);
            }
        }
예제 #10
0
        private void emulateSingleGame()
        {
            startPublisher.SessionStart(0, 1, new int[] { 3 }, 1);

            string input;

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

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

            Console.Write("Press Enter twice to start.");
            Console.ReadLine();
            Console.Write("Player 0 name: ");
            playersNames[0] = Console.ReadLine();
            Console.Write("Player 1 name: ");
            playersNames[1] = Console.ReadLine();
            Console.Write("Player 2 name: ");
            playersNames[2] = Console.ReadLine();
            Console.WriteLine("Player 3 name: Bot");
            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;


            startPublisher.GameStart(0, 3, 1, serializeCard(trumpCard), trumpCardPlayer, serializeCards(playersHand[3]));
            SuecaGame game = new SuecaGame(SuecaSolver.Card.GetSuit(trumpCard), firstPlayerID);


            for (int i = 0; i < 40; i++)
            {
                Console.WriteLine(i);
                startPublisher.NextPlayer(currentPlayerID);

                currentHand = playersHand[currentPlayerID];
                Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||");
                Console.WriteLine("                 Trick " + (i / 4));
                Console.WriteLine("                 Player " + currentPlayerID + " - " + playersNames[currentPlayerID]);
                Console.WriteLine("                 Trump is " + SuecaSolver.Card.ToString(trumpCard)[1]);
                Console.WriteLine("");

                game.PrintLastTrick();
                game.PrintCurrentTrick();
                Sueca.PrintCurrentHand(currentHand);
                int    chosenCard;
                string playInfo = "";

                if (currentPlayerID != 3)
                {
                    Console.Write("Pick the card you want to play by its index: ");
                    input      = Console.ReadLine();
                    cardIndex  = Convert.ToInt16(input);
                    chosenCard = currentHand[cardIndex];
                }
                else
                {
                    while (_botCard == null)
                    {
                    }
                    SuecaSolver.Rank myRank = (SuecaSolver.Rank)Enum.Parse(typeof(SuecaSolver.Rank), _botCard.Rank.ToString());
                    SuecaSolver.Suit mySuit = (SuecaSolver.Suit)Enum.Parse(typeof(SuecaSolver.Suit), _botCard.Suit.ToString());
                    chosenCard = SuecaSolver.Card.Create(myRank, mySuit);
                    _botCard   = null;
                    playInfo   = _playInfo;
                    _playInfo  = "";
                }

                startPublisher.Play(currentPlayerID, serializeCard(chosenCard), playInfo);

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

                if (i != 0 && i % 4 == 3)
                {
                    startPublisher.TrickEnd(game.GetCurrentTrickWinner(), game.GetCurrentTrickPoints());
                }
            }

            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();
        }
예제 #11
0
        public void NextPlayer(int id)
        {
            //NextPlayer events arrive to Thalamus Client around 10miliseconds later than Play events, however this method is called first than Play
            //This sleep allows Play event to be fully processed
            Thread.Sleep(100);
            SuecaEvent ev = new SuecaEvent(Consts.STATE_NEXT_PLAYER);

            //Console.WriteLine("The next player is {0}.", id);

            //If a GameStart event has been received but not fully proccessed wait
            while (_initialyzing)
            {
            }

            if (this._id == id && _ai != null)
            {
                int chosenCard = _ai.Play();
                _ai.AddPlay(id, chosenCard);

                SuecaSolver.Rank chosenCardRank = (SuecaSolver.Rank)SuecaSolver.Card.GetRank(chosenCard);
                SuecaSolver.Suit chosenCardSuit = (SuecaSolver.Suit)SuecaSolver.Card.GetSuit(chosenCard);
                SuecaTypes.Rank  msgRank        = (SuecaTypes.Rank)Enum.Parse(typeof(SuecaTypes.Rank), chosenCardRank.ToString());
                SuecaTypes.Suit  msgSuit        = (SuecaTypes.Suit)Enum.Parse(typeof(SuecaTypes.Suit), chosenCardSuit.ToString());
                string           cardSerialized = new SuecaTypes.Card(msgRank, msgSuit).SerializeToJson();
                string           playInfo       = _ai.GetLastPlayInfo();

                SuecaPub.Play(this._id, cardSerialized, playInfo);
                ev.Name = Consts.STATE_PLAYING;
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_PLAYING, Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.PLAY_INFO, playInfo, Consts.DEFAULT_SUBJECT);
                ev.ChangeTagsAndMeanings(new string[] { "|rank|", "|suit|" }, new string[] { convertRankToPortuguese(msgRank.ToString()), convertSuitToPortuguese(msgSuit.ToString()) });


                int  currentPlayPoints = _ai.GetCurrentTrickPoints();
                bool hasNewTrickWinner = _ai.HasNewTrickTeamWinner();
                bool lastPlayOfTrick   = _ai.IsLastPlayOfTrick();

                ev.AddPropertyChange(Consts.TRICK_SCORE, currentPlayPoints.ToString(), checkTeam(id));

                //if (hasNewTrickWinner && !lastPlayOfTrick && !robotHasPlayed)
                if (hasNewTrickWinner && !lastPlayOfTrick)
                {
                    int    currentWinnerID = _ai.GetCurrentTrickWinner();
                    string lastPlayInfo    = _ai.GetLastPlayInfo();
                    if (lastPlayInfo == Sueca.PLAY_INFO_NEWTRICK)
                    {
                        ev.AddPropertyChange(Consts.TRICK_WINNER, checkTeam(currentWinnerID), Sueca.PLAY_INFO_NEWTRICK);
                    }
                    else
                    {
                        ev.AddPropertyChange(Consts.TRICK_WINNER, checkTeam(currentWinnerID), checkTeam(id));
                    }

                    int trickIncrease = _ai.GetTrickIncrease();

                    if (trickIncrease > 0)
                    {
                        ev.AddPropertyChange(Consts.TRICK_INCREASE_PROPERTY, trickIncrease.ToString(), checkTeam(id));
                    }
                }
                _robotHasPlayed = true;
            }
            else
            {
                ev.AddPropertyChange(Consts.NEXT_PLAYER, checkTeam(id), Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_NEXT_PLAYER, Consts.DEFAULT_SUBJECT);
                ev.ChangeTagsAndMeanings(new string[] { "|nextPlayerId|" }, new string[] { id.ToString() });
            }
            ev.Finished = true;
            _suecaRPC.AddSuecaEvent(ev);
        }