Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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++;
            }
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
 public void Play(int id, string card, string playInfo)
 {
     _botCard  = JsonSerializable.DeserializeFromJson <SuecaTypes.Card>(card);
     _playInfo = playInfo;
 }