Esempio n. 1
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());
 }
Esempio n. 2
0
        private string[] serializeCards(List <int> list)
        {
            string[] serializedCards = new string[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                SuecaTypes.Rank rank = (SuecaTypes.Rank)Enum.Parse(typeof(SuecaTypes.Rank), SuecaSolver.Card.GetRank(list[i]).ToString());
                SuecaTypes.Suit suit = (SuecaTypes.Suit)Enum.Parse(typeof(SuecaTypes.Suit), SuecaSolver.Card.GetSuit(list[i]).ToString());
                serializedCards[i] = new SuecaTypes.Card(rank, suit).SerializeToJson();
            }

            return(serializedCards);
        }
        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;
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
        }