public void SessionStart(int sessionId, int numGames, int[] agentsIds, int floorId)
        {
            _id = agentsIds[_nameId - 1];
            Console.WriteLine("EMYS-" + _nameId + "--- " + "My id is " + _id);
            if (_id == 0 || _id == 2)
            {
                _teamId = 0;
            }
            else
            {
                _teamId = 1;
            }
            _numGames      = numGames;
            _currentGameId = 0;
            numRobots      = agentsIds.Length;

            SuecaEvent ev1 = new SuecaEvent(Consts.INIT);

            _suecaRPC.AddSuecaEvent(ev1);
            ev1.OtherStringInfos = new string[] { SubjectName(_id) };
            if (_agentType.StartsWith(Consts.AGENT_TYPE_GROUP))
            {
                ev1.AddPropertyChange("Player(" + SubjectName(_id) + ")", Consts.PARTNER, Consts.DEFAULT_SUBJECT);
                ev1.AddPropertyChange("Player(" + SubjectName((_id + 1) % 4) + ")", Consts.OPPONENT, Consts.DEFAULT_SUBJECT);
            }
            else if (_agentType.StartsWith(Consts.AGENT_TYPE_INDIVIDUAL))
            {
                ev1.AddPropertyChange("Player(" + SubjectName(_id) + ")", Consts.PARTNER, Consts.DEFAULT_SUBJECT);
                ev1.AddPropertyChange("Player(" + SubjectName((_id + 1) % 4) + ")", Consts.OPPONENT, Consts.DEFAULT_SUBJECT);
                ev1.AddPropertyChange("Player(" + SubjectName((_id + 2) % 4) + ")", Consts.PARTNER, Consts.DEFAULT_SUBJECT);
                ev1.AddPropertyChange("Player(" + SubjectName((_id + 3) % 4) + ")", Consts.OPPONENT, Consts.DEFAULT_SUBJECT);
            }

            if (_nameId == 1)
            {
                ev1.AddPropertyChange("Dialogue(Style)", "A", Consts.DEFAULT_SUBJECT);
            }
            else
            {
                ev1.AddPropertyChange("Dialogue(Style)", "B", Consts.DEFAULT_SUBJECT);
            }
            ev1.AddPropertyChange(Consts.ID_PROPERTY, _id.ToString(), Consts.DEFAULT_SUBJECT);
            ev1.Finished = true;

            int playerID1 = _randomNumberGenerator.Next(1, 2);
            int playerID2 = ((playerID1 + 1) % 2);

            SuecaPub.GazeAtTarget("player" + playerID1);


            SuecaEvent ev2 = new SuecaEvent(Consts.STATE_SESSION_START);

            _suecaRPC.AddSuecaEvent(ev2);
            ev2.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_SESSION_START, Consts.DEFAULT_SUBJECT);
            ev2.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
            ev2.ChangeTagsAndMeanings(new string[] { "|playerID1|", "|playerID2|" }, new string[] { playerID1.ToString(), playerID2.ToString() });
            ev2.Finished = true;
        }
Exemple #2
0
        public void Renounce(int playerId)
        {
            SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_END, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.END_GAME, "Renounce", Consts.DEFAULT_SUBJECT);
            ev.Finished = true;
        }
        public void Cut(int playerId, int floorId)
        {
            SuecaPub.GazeAtTarget("player" + playerId);
            SuecaEvent ev = new SuecaEvent(Consts.STATE_CUT);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_CUT, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
            ev.ChangeTagsAndMeanings(new string[] { "|playerID|" }, new string[] { playerId.ToString() });
            ev.Finished = true;
        }
        public void Renounce(int playerId, int floorId)
        {
            SuecaPub.GazeAtTarget("player" + playerId);
            SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_END, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.END_GAME, "Renounce", Consts.DEFAULT_SUBJECT);
            ev.Finished = true;
        }
        public void GameEnd(int team0Score, int team1Score, int floorId)
        {
            int playerId = ((_id + 2) % 4); //partner

            SuecaPub.GazeAtTarget("player" + playerId);
            //do not talk for the last game end event
            if (_currentGameId != _numGames - 1)
            {
                SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_END);
                _suecaRPC.AddSuecaEvent(ev);
                ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_END, Consts.DEFAULT_SUBJECT);
                ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);

                int myTeamScore, otherTeamScore;
                if (_teamId == 0)
                {
                    myTeamScore    = team0Score;
                    otherTeamScore = team1Score;
                }
                else
                {
                    myTeamScore    = team1Score;
                    otherTeamScore = team0Score;
                }

                if (otherTeamScore == 120)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "LostQuad", SubjectName(_id));
                }
                else if (otherTeamScore > 90)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "LostDouble", SubjectName(_id));
                }
                else if (otherTeamScore > 60)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "LostSingle", SubjectName(_id));
                }

                if (myTeamScore == 120)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "WinQuad", SubjectName(_id));
                }
                else if (myTeamScore > 90)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "WinDouble", SubjectName(_id));
                }
                else if (myTeamScore > 60)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "WinSingle", SubjectName(_id));
                }

                if (myTeamScore == otherTeamScore)
                {
                    ev.AddPropertyChange(Consts.END_GAME, "Draw", SubjectName(_id));
                }
                ev.ChangeTagsAndMeanings(new string[] { "|playerID|" }, new string[] { playerId.ToString() });
                ev.Finished = true;
            }
        }
        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;
            }
        }
Exemple #7
0
        public void TrickEnd(int winnerId, int trickPoints)
        {
            _robotHasPlayed = false;

            SuecaEvent ev = new SuecaEvent(Consts.STATE_TRICK_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_TRICK_END, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.TRICK_WINNER, checkTeam(winnerId), checkTeam(winnerId));
            ev.AddPropertyChange(Consts.TRICK_END, trickPoints.ToString(), checkTeam(_id));
            ev.ChangeTagsAndMeanings(new string[] { "|playerId|", "|trickpoints|" }, new string[] { winnerId.ToString(), trickPoints.ToString() });
            ev.Finished = true;
        }
        public void Deal(int playerId, int floorId)
        {
            SuecaPub.GazeAtTarget("player" + playerId);
            SuecaEvent ev = new SuecaEvent(Consts.STATE_DEAL);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_DEAL, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);
            ev.ChangeTagsAndMeanings(new string[] { "|playerID|" }, new string[] { playerId.ToString() });
            ev.Finished = true;
            //if robot has floor speaks, otherwise just gazes random
            SuecaPub.GazeAtTarget("random");
        }
Exemple #9
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;
        }
Exemple #10
0
        public void Deal(int playerId)
        {
            SuecaEvent ev = new SuecaEvent(Consts.STATE_DEAL);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_DEAL, Consts.DEFAULT_SUBJECT);
            ev.ChangeTagsAndMeanings(new string[] { "|playerId1|" }, new string[] { playerId.ToString() });
            ev.Finished = true;
        }
Exemple #11
0
        public void SessionStart(int sessionId, int numGames, int[] agentsIds, int shouldGreet)
        {
            _id = agentsIds[_nameId - 1];
            //Console.WriteLine("My id is " + _id);

            SuecaEvent ev = new SuecaEvent(Consts.STATE_SESSION_START);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_SESSION_START, Consts.DEFAULT_SUBJECT);
            ev.Finished = true;
        }
Exemple #12
0
        public void SessionEnd(int sessionId, int team0Score, int team1Score)
        {
            SuecaEvent ev = new SuecaEvent(Consts.STATE_SESSION_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_SESSION_END, Consts.DEFAULT_SUBJECT);
            if (team0Score > team1Score)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Lost", Consts.DEFAULT_SUBJECT);
            }
            if (team0Score < team1Score)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Win", Consts.DEFAULT_SUBJECT);
            }
            if (team0Score == team1Score)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Draw", Consts.DEFAULT_SUBJECT);
            }
            ev.Finished = true;
        }
        public void SessionEnd(int sessionId, int team0Score, int team1Score, int floorId)
        {
            int playerId = ((_id + 2) % 4); //partner

            SuecaPub.GazeAtTarget("player" + playerId);
            SuecaEvent ev = new SuecaEvent(Consts.STATE_SESSION_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_SESSION_END, Consts.DEFAULT_SUBJECT);
            ev.AddPropertyChange(Consts.DIALOGUE_FLOOR_PROPERTY, floorId.ToString(), Consts.DEFAULT_SUBJECT);

            int myTeamScore, otherTeamScore;

            if (_teamId == 0)
            {
                myTeamScore    = team0Score;
                otherTeamScore = team1Score;
            }
            else
            {
                myTeamScore    = team1Score;
                otherTeamScore = team0Score;
            }

            if (otherTeamScore > myTeamScore)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Lost", SubjectName(_id));
            }
            if (otherTeamScore < myTeamScore)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Win", SubjectName(_id));
            }
            if (otherTeamScore == myTeamScore)
            {
                ev.AddPropertyChange(Consts.END_SESSION, "Draw", SubjectName(_id));
            }
            ev.ChangeTagsAndMeanings(new string[] { "|playerID|" }, new string[] { playerId.ToString() });
            ev.Finished = true;
        }
Exemple #14
0
        public void GameEnd(int team0Score, int team1Score)
        {
            SuecaEvent ev = new SuecaEvent(Consts.STATE_GAME_END);

            _suecaRPC.AddSuecaEvent(ev);
            ev.AddPropertyChange(Consts.DIALOGUE_STATE_PROPERTY, Consts.STATE_GAME_END, Consts.DEFAULT_SUBJECT);

            if (team0Score == 120)
            {
                ev.AddPropertyChange(Consts.END_GAME, "LostQuad", Consts.DEFAULT_SUBJECT);
            }
            else if (team0Score > 90)
            {
                ev.AddPropertyChange(Consts.END_GAME, "LostDouble", Consts.DEFAULT_SUBJECT);
            }
            else if (team0Score > 60)
            {
                ev.AddPropertyChange(Consts.END_GAME, "LostSingle", Consts.DEFAULT_SUBJECT);
            }

            if (team1Score == 120)
            {
                ev.AddPropertyChange(Consts.END_GAME, "WinQuad", Consts.DEFAULT_SUBJECT);
            }
            else if (team1Score > 90)
            {
                ev.AddPropertyChange(Consts.END_GAME, "WinDouble", Consts.DEFAULT_SUBJECT);
            }
            else if (team1Score > 60)
            {
                ev.AddPropertyChange(Consts.END_GAME, "WinSingle", Consts.DEFAULT_SUBJECT);
            }

            if (team0Score == team1Score)
            {
                ev.AddPropertyChange(Consts.END_GAME, "Draw", Consts.DEFAULT_SUBJECT);
            }
            ev.Finished = true;
        }
Exemple #15
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;
        }
Exemple #18
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);
        }