public long AddPlayerToManualPlayersTable(string playerName, PokerClients pokerClientId, int aiType, string aiConfigStr)
        {
            //First check to see if this player already exists
            if (databaseQueries.playerDetailsByPlayerName(playerName, (short)pokerClientId) != null)
            {
                throw new Exception("A player already exists with that name.");
            }

            long newPlayerId;

            startPlayerWrite();

            if (!pokerPlayers.ContainsKey(pokerClientId))
            {
                pokerPlayers.Add(pokerClientId, new Dictionary <long, PokerPlayer>());
            }

            //lock (playerLocker)
            //{
            PlayerChangesSinceLoad = true;

            newPlayerId = 1;
            foreach (PokerClients client in pokerPlayers.Keys)
            {
                newPlayerId = Math.Max(newPlayerId, (pokerPlayers[client].Count > 0 ? pokerPlayers[client].Keys.Max() : 0) + 1);
            }

            pokerPlayers[pokerClientId].Add(newPlayerId, new PokerPlayer(newPlayerId, playerName, (short)pokerClientId, (AIGeneration)aiType, aiConfigStr));
            //}

            endPlayerWrite();

            return(newPlayerId);
        }
        public PokerPlayer PlayerDetails(string playerName, PokerClients pokerClientId)
        {
            PokerPlayer[] result;

            startPlayerRead();

            //lock (playerLocker)
            //{
            if (pokerPlayers.Count == 0 || !pokerPlayers.ContainsKey(pokerClientId))
            {
                endPlayerRead();
                return(null);
            }

            result = (from current in pokerPlayers[pokerClientId].Values
                      where current.PlayerName == playerName
                      select current).ToArray();
            //}

            endPlayerRead();

            if (result.Length == 0)
            {
                return(null);
            }
            else if (result.Length == 1)
            {
                return(result[0]);
            }
            else
            {
                throw new Exception("More than a single player selected from database when there should only every be 0 or 1.");
            }
        }
        public void LoadManualPlayersTable(string fileLocation)
        {
            startPlayerWrite();

            //lock (playerLocker)
            //{
            if (File.Exists(fileLocation))
            {
                pokerPlayers = new Dictionary <PokerClients, Dictionary <long, PokerPlayer> >();
                string[] fileLines = File.ReadAllLines(fileLocation);

                for (int i = 1; i < fileLines.Length; i++)
                {
                    string[] lineElements = fileLines[i].Split(',');

                    long         playerId     = long.Parse(lineElements[0]);
                    PokerClients playerClient = (PokerClients)short.Parse(lineElements[2]);
                    var          player       = new PokerPlayer(playerId, lineElements[1], (short)playerClient, (AIGeneration)Enum.Parse(typeof(AIGeneration), lineElements[3]), lineElements[4]);

                    if (!pokerPlayers.ContainsKey(playerClient))
                    {
                        pokerPlayers.Add(playerClient, new Dictionary <long, PokerPlayer>());
                    }

                    pokerPlayers[playerClient].Add(playerId, player);
                }
            }

            PlayerChangesSinceLoad = false;
            //}

            endPlayerWrite();
        }
        public void DeleteLegacyTrainingPlayersFromManualPlayersTable(PokerClients pokerClientId, int generationNumToKeep)
        {
            startPlayerWrite();

            //lock (playerLocker)
            //{
            PlayerChangesSinceLoad      = true;
            pokerPlayers[pokerClientId] = (from current in pokerPlayers[pokerClientId]
                                           where (current.Value.PlayerName.StartsWith("geneticPokerAI_" + generationNumToKeep) || !current.Value.PlayerName.StartsWith("geneticPokerAI_"))
                                           select current).ToDictionary(dict => dict.Key, dict => dict.Value);
            //}

            endPlayerWrite();
        }
        public void DeleteAllClientPlayersFromManualPlayersTable(PokerClients pokerClientId)
        {
            startPlayerWrite();

            //lock (playerLocker)
            //{
            PlayerChangesSinceLoad = true;
            pokerPlayers           = (from current in pokerPlayers
                                      where current.Key != pokerClientId
                                      select current).ToDictionary(dict => dict.Key, dict => dict.Value);
            //}

            endPlayerWrite();
        }
예제 #6
0
        private void playPoker_Click(object sender, EventArgs e)
        {
            if (playPoker.Text == "Play Poker")
            {
                PokerClients client             = PokerClients.HumanVsBots;
                int          actionPauseTime    = int.Parse(this.actionPause.Text);
                byte         minNumTablePlayers = 2;

                AISelection[] selectedPlayers = this.aiSelectionControl1.AISelection();

                //Select the playerId's for all of the bot players
                if (selectedPlayers.Length > 10)
                {
                    throw new Exception("A maximum of 10 players is allowed.");
                }

                databaseCache.InitialiseRAMDatabase();

                long[]   newPlayerIds        = PokerHelper.CreateOpponentPlayers(selectedPlayers, obfuscateBots.Checked, (short)client);
                string[] selectedPlayerNames = new string[newPlayerIds.Length];
                for (int i = 0; i < newPlayerIds.Length; i++)
                {
                    selectedPlayerNames[i] = databaseQueries.convertToPlayerNameFromId(newPlayerIds[i]);
                }

                //Shuffle the player list so we have absolutly no idea who is who.
                selectedPlayerNames = shuffleList(selectedPlayerNames.ToList()).ToArray();
                clientCache         = new databaseCacheClient((short)client, this.gameName.Text, decimal.Parse(this.littleBlind.Text), decimal.Parse(this.bigBlind.Text), decimal.Parse(this.startingStack.Text), 10, HandDataSource.PlayingTest);
                CacheMonitor.CacheMonitor cacheMonitor = new PokerBot.CacheMonitor.CacheMonitor(clientCache, !showAllCards.Checked);

                pokerGame = new BotVsHumanPokerGame(PokerGameType.BotVsHuman, clientCache, minNumTablePlayers, selectedPlayerNames, Decimal.Parse(startingStack.Text), 0, Int16.Parse(actionPause.Text), cacheMonitor);
                pokerGame.startGameTask();
                pokerGame.ShutdownAIOnFinish();

                cacheMonitor.Show();
                playPoker.Text = "End Game";
            }
            else
            {
                playPoker.Text    = "Ending Game";
                playPoker.Enabled = false;

                pokerGame.ShutdownAIOnFinish();
                pokerGame.EndGame = true;

                playPoker.Text    = "Play Poker";
                playPoker.Enabled = true;
            }
        }
        /// <summary>
        /// Converts the aiConfigStr provided into playerIds, sorted in the same order.
        /// </summary>
        /// <param name="aiConfigStr"></param>
        /// <param name="pokerClientId"></param>
        /// <returns></returns>
        public long[] PlayerIdsFromAiType(AIGeneration aiType, PokerClients pokerClientId)
        {
            long[] playerMatches;

            startPlayerRead();

            playerMatches = (from current in pokerPlayers[pokerClientId].Values
                             where current.AiType == aiType && current.PlayerName != ""
                             select current.PlayerId).ToArray();

            endPlayerRead();

            if (playerMatches.Count() == 0)
            {
                throw new Exception("The aiType provided did not produce any playerIds. aiType=" + aiType + ", pokerClientId=" + pokerClientId);
            }
            else
            {
                return(playerMatches);
            }
        }
        public long[] ClientOpponentPlayerIds(PokerClients pokerClient, List <int> excludeAIGenerations, int currentTrainingGenerationType)
        {
            long[] playerIds = new long[0];
            startPlayerRead();

            //lock (playerLocker)
            //{
            if (pokerPlayers.ContainsKey(pokerClient))
            {
                playerIds = (from current in pokerPlayers[pokerClient].Values
                             where !excludeAIGenerations.Contains((int)current.AiType) && (((int)current.AiType == currentTrainingGenerationType && !current.AiConfigStr.StartsWith("Genetic")) || (int)current.AiType != currentTrainingGenerationType)
                             where current.PlayerName != ""
                             select current.PlayerId).ToArray();
            }

            //}

            endPlayerRead();

            return(playerIds);
        }
        public long[] AddPlayersToManualPlayersTable(PokerClients pokerClientId, int aiType, string[] playerNames, string[] aiConfigStrs)
        {
            List <long> newPlayerIds = new List <long>();

            if (!pokerPlayers.ContainsKey(pokerClientId))
            {
                pokerPlayers.Add(pokerClientId, new Dictionary <long, PokerPlayer>());
            }

            startPlayerWrite();
            //lock (playerLocker)
            //{
            PlayerChangesSinceLoad = true;

            long nextPlayerId = 1;

            foreach (PokerClients client in pokerPlayers.Keys)
            {
                nextPlayerId = Math.Max(nextPlayerId, (pokerPlayers[client].Count > 0 ? pokerPlayers[client].Keys.Max() : 0) + 1);
            }

            for (int i = 0; i < playerNames.Length; i++)
            {
                if (databaseQueries.playerDetailsByPlayerName(playerNames[i], (short)pokerClientId) != null)
                {
                    throw new Exception("A player already exists with that name.");
                }

                newPlayerIds.Add(nextPlayerId);
                pokerPlayers[pokerClientId].Add(nextPlayerId, new PokerPlayer(nextPlayerId, playerNames[i], (short)pokerClientId, (AIGeneration)aiType, aiConfigStrs[i]));

                nextPlayerId++;
            }
            //}

            endPlayerWrite();

            return(newPlayerIds.ToArray());
        }
예제 #10
0
        /// <summary>
        /// Converts the aiConfigStr provided into playerIds, sorted in the same order.
        /// </summary>
        /// <param name="aiConfigStr"></param>
        /// <param name="pokerClientId"></param>
        /// <returns></returns>
        public long[] PlayerIdsFromConfigStr(string[] aiConfigStr, PokerClients pokerClientId)
        {
            long[] playerMatches;

            startPlayerRead();

            //lock (playerLocker)
            //{
            playerMatches = (from current in pokerPlayers[pokerClientId].Values
                             where aiConfigStr.Contains(current.AiConfigStr) && current.PlayerName != ""
                             select current.PlayerId).ToArray();
            //}

            endPlayerRead();

            if (playerMatches.Count() == 0)
            {
                throw new Exception("The aiConfigStr provided did not produce any playerIds. aiConfigStr.Length=" + aiConfigStr.Length + ", aiConfigStr[0]=" + aiConfigStr[0]);
            }
            else
            {
                return(playerMatches);
            }
        }