/// <summary> /// Returns the player details from the database. Returns null if the player is not located. /// </summary> /// <param name="playerName"></param> /// <param name="pokerClientId"></param> /// <returns></returns> public static PokerPlayer playerDetailsByPlayerName(string playerName, short pokerClientId) { if (DatabaseMode.LOCALMODE.Equals(Mode)) { if (databaseCache.databaseRAM != null) { return(databaseCache.databaseRAM.PlayerDetails(playerName, (PokerClients)pokerClientId)); } else { string[] fileLines = File.ReadAllLines(manualPlayersTableFileLocation); for (int i = 1; i < fileLines.Length; i++) { string[] lineElements = fileLines[i].Split(','); if (lineElements[1].Equals(playerName) && lineElements[2].Equals(Convert.ToString(pokerClientId))) { AIGeneration generation = (AIGeneration)Enum.Parse(typeof(AIGeneration), lineElements[3]); return(new PokerPlayer(long.Parse(lineElements[0]), playerName, pokerClientId, generation, lineElements[4])); } } return(null); } } else { throw new NotImplementedException(); } }
public static string[] AiDefaultConfigs(AIGeneration requestedAIGeneration) { if (DatabaseMode.LOCALMODE.Equals(Mode)) { //Load default ai configs from manual file and return if (File.Exists(manualPlayersTableFileLocation)) { string[] fileLines = File.ReadAllLines(manualPlayersTableFileLocation); for (int i = 1; i < fileLines.Length; i++) { string[] lineElements = fileLines[i].Split(','); AIGeneration generation = (AIGeneration)Enum.Parse(typeof(AIGeneration), lineElements[3]); if (generation == requestedAIGeneration) { return(lineElements[4].Split('|')); } } //If we didn't find any config then just return empty return(new string[0]); } else { throw new FileNotFoundException("Failed to find AiConfigsFile " + manualPlayersTableFileLocation); } } else { throw new NotImplementedException(); } throw new ArgumentException("The requested AI generation " + requestedAIGeneration + " was not found."); }
public PokerPlayer(long playerId, string playerName, short pokerClientId, AIGeneration aiType, string aiConfigStr) { this.PlayerId = playerId; this.PlayerName = playerName; this.PokerClientId = pokerClientId; this.AiType = aiType; this.AiConfigStr = aiConfigStr; }
public DecisionRequest(long playerId, databaseCache cache, AIGeneration serverType, string aiConfigStr, bool aiManagerInSafeMode) { this.playerId = playerId; this.cache = cache; this.serverType = serverType; this.aiConfigStr = aiConfigStr; this.aiManagerInSafeMode = aiManagerInSafeMode; this.decisionSignal = new ManualResetEvent(false); }
public tablePlayer(long playerId, long tableId, long handId) { this.playerId = playerId; this.tableId = tableId; lastRefreshTime = DateTime.Now; lastRefreshHandId = handId; //Determine a possible AI version for this player int aiTypeInt; databaseQueries.aiPlayerConfig(playerId, out aiTypeInt, out aiConfigStr); aiType = (AIGeneration)aiTypeInt; }
/// <summary> /// Returns the playerId associated with the aiConfigStr /// </summary> /// <param name="aiConfigStr"></param> /// <returns></returns> public static long[] getPlayerIdsFromAiType(AIGeneration aiType, short pokerClientId) { long[] playerIds; if (DatabaseMode.LOCALMODE.Equals(Mode) && databaseCache.databaseRAM != null) { playerIds = databaseCache.databaseRAM.PlayerIdsFromAiType(aiType, (PokerClients)pokerClientId); } else { throw new NotImplementedException(); } return((from ids in playerIds orderby ids ascending select ids).ToArray()); }
/// <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); } }
/// <summary> /// Creates an instance using supplied values /// </summary> /// <param name="playerId"></param> /// <param name="maxHands"></param> /// <param name="handsCounted"></param> /// <param name="rFreq_PreFlop"></param> /// <param name="rFreq_PostFlop"></param> /// <param name="cFreq_PreFlop"></param> /// <param name="cFreq_PostFlop"></param> /// <param name="checkFreq_PreFlop"></param> /// <param name="checkFreq_PostFlop"></param> /// <param name="playFreqPreFlop"></param> /// <param name="playFreqPostFlop"></param> public PlayerAggression(long playerId, int maxHands, int handsCounted, decimal rFreq_PreFlop, decimal rFreq_PostFlop, decimal cFreq_PreFlop, decimal cFreq_PostFlop, decimal checkFreq_PreFlop, decimal checkFreq_PostFlop, decimal playFreqPreFlop, decimal playFreqPostFlop, AIGeneration aiType) { this.playerId = playerId; this.maxHands = maxHands; this.handsCounted = handsCounted; this.rFreq_PreFlop = rFreq_PreFlop; this.rFreq_PostFlop = rFreq_PostFlop; this.cFreq_PreFlop = cFreq_PreFlop; this.cFreq_PostFlop = cFreq_PostFlop; this.checkFreq_PreFlop = checkFreq_PreFlop; this.checkFreq_PostFlop = checkFreq_PostFlop; this.playFreqPreFlop = playFreqPreFlop; this.playFreqPostFlop = playFreqPostFlop; this.aiType = aiType; }
/// <summary> /// Returns the AI type to use for a given player and table. /// </summary> /// <param name="playerId"></param> /// <param name="tableId"></param> /// <returns></returns> public void PlayerAiConfig(long playerId, long tableId, out AIGeneration aiServerType, out string aiConfigStr) { lock (locker) { if (tablePlayersDict.ContainsKey(playerId)) { aiServerType = tablePlayersDict[playerId].AiType; aiConfigStr = tablePlayersDict[playerId].AiConfigStr; } else { //If this config is not yet in the cache then get it directly from the database int aiTypeInt; databaseQueries.aiPlayerConfig(playerId, out aiTypeInt, out aiConfigStr); aiServerType = (AIGeneration)aiTypeInt; //Allthough an entry is added to the dictionary here it may be removed again by the cacheTrackerWorker when it replaces tablePlayersDict lock (locker) tablePlayersDict.Add(playerId, new tablePlayer(playerId, tableId, latestHandId)); } } }
/// <summary> /// Initiaties a decision but overrides the player config using the specified serverType and configStr /// </summary> /// <param name="handId"></param> /// <param name="playerId"></param> /// <param name="genericGameCache"></param> /// <returns></returns> public Play GetDecision(long playerId, databaseCache genericGameCache, AIGeneration serverType, string aiConfigStr) { try { //AIGeneration serverType; //string aiConfigStr; int selectedInstanceIndex; //Check for any simple errors PreDecisionErrorChecking(playerId, genericGameCache); //Determine which instance to use selectedInstanceIndex = DetermineAvailableInstance(); //Enter the correct lock lock (instanceLocks[selectedInstanceIndex]) { //Update the infostore //If anything in the InfoStore throws any error it will be caught by the catch //in this method, and thus logged correctly. UpdateInfoStore(playerId, genericGameCache, infoStoreCollection[selectedInstanceIndex], infoProviderCollection[selectedInstanceIndex]); //Get the correct AI version and configuration for this player if (serverType == AIGeneration.Undefined || aiConfigStr == null) { cacheTracker.playerAiConfig(playerId, genericGameCache.TableId, out serverType, out aiConfigStr); } //Pick that aiServer from the available list var aiServer = from server in aiCollection[selectedInstanceIndex] where server.AiType == serverType select server; if (aiServer.Count() != 1) { throw new Exception("Unable to select correct AI from those avaialble."); } //Get the ai decision Play aiAction = aiServer.First().GetDecision(playerId, aiConfigStr, genericGameCache, infoStoreCollection[selectedInstanceIndex]); aiAction = SetDecisionTime(ValidatePlayerDecision(aiAction, genericGameCache)); //Signal this decision as finished and let another one through. lock (idlelocker) { instancesIdle = instancesIdle | (1 << selectedInstanceIndex); //aiAvailableEvent.Set(); } return(aiAction); } } catch (Exception ex) { //Reset idle instances (the locks will protected and potential multithreading problems). instancesIdle = 0; for (int i = 0; i < numInstances; i++) { instancesIdle = instancesIdle | (1 << i); } genericGameCache.readLockCounter = 0; LogAIError(ex, genericGameCache); return(new Play(PokerAction.GeneralAIError, 0, 0, genericGameCache.getCurrentHandId(), playerId, ex.ToString(), 3)); } throw new Exception("Should never get here!"); }
public AISelection(AIGeneration aiGeneration, string configStr) { this.aiGeneration = aiGeneration; this.configStr = configStr; }
/// <summary> /// Initiaties a decision but overrides the player config using the specified serverType and configStr /// </summary> /// <param name="handId"></param> /// <param name="playerId"></param> /// <param name="genericGameCache"></param> /// <returns></returns> public Play GetDecision(long playerId, databaseCache genericGameCache, AIGeneration serverType, string aiConfigStr) { try { //Sort out the cacheTracker CacheTracker.Instance.Update(playerId, genericGameCache); if (serverType == AIGeneration.Undefined || aiConfigStr == null) { CacheTracker.Instance.PlayerAiConfig(playerId, genericGameCache.TableId, out serverType, out aiConfigStr); } DecisionRequest newRequest = new DecisionRequest(playerId, genericGameCache, serverType, aiConfigStr, AIManager.RunInSafeMode); PreDecisionErrorChecking(newRequest.PlayerId, newRequest.Cache); //For now we will just use the old method //Determine an available AIInstance int selectedInstanceIndex = DetermineAvailableInstance(newRequest); //This could be done in a seperate thread if (selectedInstanceIndex == -1) { //There were no available instances so we join the queue and wait newRequest.WaitForDecision(); } else { if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore) { Task t = Task.Factory.StartNew(aiInstanceList[selectedInstanceIndex].HandleDecisionRequest, newRequest); t.Wait(); } else { aiInstanceList[selectedInstanceIndex].HandleDecisionRequest(newRequest); } } Play aiAction = newRequest.DecisionPlay; aiAction = SetDecisionTime(ValidatePlayerDecision(aiAction, newRequest.Cache)); return(aiAction); } catch (Exception ex) { instanceSelector.instancesIdle = 0; for (int i = 0; i < aiInstanceList.Count; i++) { instanceSelector.instancesIdle = instanceSelector.instancesIdle | (1 << i); } genericGameCache.readLockCounter = 0; string fileName = LogError.Log(ex, "PokerAIError"); genericGameCache.SaveToDisk("", fileName); return(new Play(PokerAction.GeneralAIError, 0, 0, genericGameCache.getCurrentHandId(), playerId, ex.ToString(), 3)); } throw new Exception("This point should never be reached."); }