示例#1
0
        public List <InGamePlayer> GetAllGamesPlayers(string playerhash)
        {
            List <InGamePlayer> players      = new List <InGamePlayer>();
            RoundInfo           ri           = roundsInfo[currentRound];
            List <InGamePlayer> roundPlayers = ri.GetPlayers(playerhash);

            return(roundPlayers);
        }
示例#2
0
        private bool NextRound()
        {
            WriteLog();

            bool coalitionHasBeenFormed = isCoalitionFormed();

            if (coalitionHasBeenFormed)
            {
                foreach (var item in roundsInfo[currentRound].playersRoundInfo)
                {
                    Player.AddScore(item.Key, item.Value.playerOffer);
                    Player.AddGame(item.Key, item.Value.playerOffer);
                    Player.SetFutureStatus(item.Key, Player.Status.WaitingRoom);
                    Player.ResetEntranceTime(item.Key);
                }
                return(false);
            }
            else
            {
                if (currentRound >= configuration.RoundsNumber - 1)
                {
                    foreach (var item in roundsInfo[currentRound].playersRoundInfo)
                    {
                        Player.SetFutureStatus(item.Key, Player.Status.WaitingRoom);
                        Player.ResetEntranceTime(item.Key);
                    }
                    return(false);
                }
            }

            RoundInfo ri = roundsInfo[currentRound];

            foreach (var item in ri.playersRoundInfo)
            {
                if (!Player.isPlayerConnected(item.Key))
                {
                    foreach (var item2 in roundsInfo[currentRound].playersRoundInfo)
                    {
                        Player.SetFutureStatus(item2.Key, Player.Status.WaitingRoom);
                        Player.ResetEntranceTime(item2.Key);
                    }
                    return(false);
                }
            }

            currentRound++;
            stateChangeTime = DateTime.Now;
            roomState       = RoomState.ProposalMaking;
            UpdateAllPlayersRoles();
            return(true);
        }
示例#3
0
        private bool OffersWereGiven()
        {
            RoundInfo ri          = roundsInfo[currentRound];
            bool      offersGiven = false;

            foreach (var item in ri.playersRoundInfo)
            {
                if (item.Value.playerOffer > 0)
                {
                    offersGiven = true;
                }
            }
            return(offersGiven);
        }
示例#4
0
        private static void PlayAi(Type configurationType, int timeInTheCurrentState, out RoundInfo ri, KeyValuePair <string, CRoom> room, out int aiIndex)
        {
            if (configurationType == Type.NE)
            {
                ri      = room.Value.roundsInfo[room.Value.currentRound];
                aiIndex = 0;
                foreach (var shouldBeAIPlayer in ri.playersRoundInfo)
                {
                    if (shouldBeAIPlayer.Value.isAI && shouldBeAIPlayer.Value.isProposer && timeInTheCurrentState >= 10)
                    {
                        double[] offers      = room.Value.configuration.AiDevision[room.Value.currentRound];
                        double[] weights     = new double[ri.playersRoundInfo.Count];
                        int      totalWeight = 10;
                        int      i           = 0;
                        foreach (var player in ri.playersRoundInfo)
                        {
                            weights[i++] = player.Value.weight;
                        }
                        int[]  playerIndex         = getPlayersToOffer(aiIndex, offers, weights, totalWeight);
                        double sumOfOfferExcludeAi = 0;
                        for (int j = 0; j < playerIndex.Length; j++)
                        {
                            if (j != aiIndex && playerIndex[j] == 1)
                            {
                                sumOfOfferExcludeAi += offers[j];
                            }
                        }
                        int index = 0;

                        foreach (var player in ri.playersRoundInfo)
                        {
                            if (index == aiIndex)
                            {
                                player.Value.playerOffer    = 100 - sumOfOfferExcludeAi;
                                player.Value.playerResponse = PlayerResponse.None;
                            }
                            else if (playerIndex[index] == 1)
                            {
                                player.Value.playerOffer    = offers[index];
                                player.Value.playerResponse = PlayerResponse.None;
                            }
                            index++;
                        }
                        break;
                    }
                    aiIndex++;
                }
            }
            else if (configurationType == Type.NORMAL)
            {
                ri      = room.Value.roundsInfo[room.Value.currentRound];
                aiIndex = 0;
                foreach (var item in ri.playersRoundInfo)
                {
                    if (item.Value.isAI && item.Value.isProposer && timeInTheCurrentState >= 10)
                    {
                        double[] offers       = room.Value.configuration.AiDevision[aiIndex];
                        int      playersindex = 0;
                        foreach (var item2 in ri.playersRoundInfo)
                        {
                            item2.Value.playerOffer    = offers[playersindex];
                            item2.Value.playerResponse = PlayerResponse.None;
                            playersindex++;
                        }
                        break;
                    }
                    aiIndex++;
                }
            }
            else
            {
                ri      = room.Value.roundsInfo[room.Value.currentRound];
                aiIndex = 0;
            }
        }
示例#5
0
 private static void ResponseAsAi(Type configurationType, int timeInTheCurrentState, out RoundInfo ri, KeyValuePair <string, CRoom> room, out int aiIndex)
 {
     if (configurationType == Type.NE)
     {
         ri      = room.Value.roundsInfo[room.Value.currentRound];
         aiIndex = 0;
         foreach (var item in ri.playersRoundInfo)
         {
             if (item.Value.isAI && item.Value.playerOffer > 0 && item.Value.playerResponse == PlayerResponse.None && timeInTheCurrentState >= 5)
             {
                 double acceptance = room.Value.configuration.AiDevision[room.Value.currentRound][aiIndex];
                 if (item.Value.playerOffer >= acceptance)
                 {
                     item.Value.playerResponse = PlayerResponse.Accepted;
                 }
                 else
                 {
                     item.Value.playerResponse = PlayerResponse.Refused;
                 }
                 break;
             }
             aiIndex++;
         }
     }
     else if (configurationType == Type.NORMAL)
     {
         ri      = room.Value.roundsInfo[room.Value.currentRound];
         aiIndex = 0;
         foreach (var item in ri.playersRoundInfo)
         {
             if (item.Value.isAI && item.Value.playerOffer > 0 && item.Value.playerResponse == PlayerResponse.None && timeInTheCurrentState >= 5)
             {
                 double acceptance = room.Value.configuration.AcceptnaceRateAi[aiIndex];
                 if (item.Value.playerOffer > acceptance)
                 {
                     item.Value.playerResponse = PlayerResponse.Accepted;
                 }
                 else
                 {
                     item.Value.playerResponse = PlayerResponse.Refused;
                 }
                 break;
             }
             aiIndex++;
         }
     }
     else
     {
         ri      = room.Value.roundsInfo[room.Value.currentRound];
         aiIndex = 0;
     }
 }