public PokerServer(Guid id, IList <string> cardSet) { Id = id; Players = new ConcurrentDictionary <string, Player>(); CurrentSession = new PokerSession(cardSet); Created = DateTime.UtcNow; }
protected void GameStart_OnClick(object sender, EventArgs e) { // Get the number of the players in the poker session List <Player> gamePlayers = new List <Player>(); Player computerPlayer = new Player(txtComputer1.Text); Player humanPlayer = new Player(txtPlayer.Text); gamePlayers.Add(computerPlayer); gamePlayers.Add(humanPlayer); // Initialize poker session and poker game classes PokerSession pokerSession = new PokerSession(gamePlayers); Session["PokerSession"] = pokerSession; StartGame(); // Disable editing of player names txtComputer1.Enabled = txtPlayer.Enabled = false; // Hide start button and show game stats btnStartGame.Visible = false; // Show Evaluate button btnEvaluateHands.Visible = true; }
public string UpdatedPokerSession(string sessionName) { PokerSession pokerSession = hTTPHelper.GetCurrentSession(sessionName); var json = JsonConvert.SerializeObject(pokerSession); return(json); }
public void InsertPokerSession(PokerSession session) { _client = new MongoClient(db); _database = _client.GetDatabase("local"); var collection = _database.GetCollection <PokerSession>("test"); collection.InsertOne(session); }
private static IDictionary <string, string> MapVotes(PokerSession session) { var votes = session.IsShown ? session.Votes.ToDictionary(pair => pair.Key.ToString(), pair => pair.Value.ToString()) : session.Votes.ToDictionary(pair => pair.Key.ToString(), pair => "?"); return(votes); }
internal static void RemovePlayer(PokerSession session, int playerPublicId) { session.Votes.Remove(playerPublicId); if (!session.Votes.Any()) { session.IsShown = false; } }
public void CreatePokerSession(string sessionName) { PokerSession newPokerSession = new PokerSession() { Name = sessionName }; dbHandler.InsertPokerSession(newPokerSession); }
public PokerSession GetPokerSession(string session) { _client = new MongoClient(db); _database = _client.GetDatabase("local"); var collection = _database.GetCollection <PokerSession>("test"); PokerSession pokerSession = collection.Find(x => x.Name == session).First(); return(pokerSession); }
public void PokerSession_ValidateAddPlayers() { List <Player> minplayerList = CreatePlayerList(PokerSession.minPlayers); PokerSession minPlayerPokerSession = CreatePokerSession(minplayerList); Assert.AreEqual(PokerSession.minPlayers, minPlayerPokerSession.sessionPlayers.Count); Assert.AreNotEqual(PokerSession.maxPlayers, minPlayerPokerSession.sessionPlayers.Count); List <Player> maxPlayerlist = CreatePlayerList(PokerSession.maxPlayers); PokerSession maxPlayerPokerSession = CreatePokerSession(maxPlayerlist); Assert.AreEqual(PokerSession.maxPlayers, maxPlayerPokerSession.sessionPlayers.Count); }
public virtual Task RenderStatusInformation(PokerSession sessionInformation) { Console.Clear(); OutputShortProgramHeader(); Console.WriteLine($"Current session: {sessionInformation.SessionId}"); foreach (var user in sessionInformation.Participants) { Console.WriteLine($"{user.Name} - {user.CurrentVoteDescription}"); } return(Task.CompletedTask); }
public static PokerSessionViewModel Map(this PokerSession session, IDictionary <string, Player> participants) { var votes = MapVotes(session); var viewModel = new PokerSessionViewModel { Votes = votes, IsShown = session.IsShown, CanClear = session.CanClear, CanShow = session.CanShow(participants), CanVote = session.CanVote, CardSet = session.CardSet }; return(viewModel); }
protected void EvaluateHands_OnClick(object sender, EventArgs e) { PokerSession pokerSession = (PokerSession)Session["PokerSession"]; List <Player> gameWinners; PokerSessionGame currentGame = pokerSession.gamesPlayed.Where(g => g.isActive).SingleOrDefault(); string strgameWinners = string.Empty; try { gameWinners = PokerHandEvaluator.EvaluateHands(pokerSession.sessionPlayers); lblCompHand.Text = EnumHelper.GetDescription(pokerSession.sessionPlayers[0].hand.handCombination); lblPlayerHand.Text = EnumHelper.GetDescription(pokerSession.sessionPlayers[1].hand.handCombination); foreach (Player winner in gameWinners) { strgameWinners = strgameWinners + winner.name + ", "; } strgameWinners = strgameWinners.Remove(strgameWinners.LastIndexOf(',')); lblDisplayWinner.Text = "Game Winner/s: " + strgameWinners; currentGame.winningHand = EnumHelper.GetDescription(gameWinners.First().hand.handCombination); currentGame.gameWinner = strgameWinners; currentGame.isActive = false; btnEvaluateHands.Visible = false; btnNewGame.Visible = true; gvSessionStats.DataSource = pokerSession.gamesPlayed; gvSessionStats.DataBind(); for (int i = 1; i <= 5; i++) { Button btnComputerRedraw = (Button)ucComputerHand.FindControl("btnRedraw" + i); Button btnPlayerRedraw = (Button)ucPlayerHand.FindControl("btnRedraw" + i); btnComputerRedraw.Enabled = btnPlayerRedraw.Enabled = false; } } catch (Exception ex) { // General exception catch lblDisplayError.Text = "Error occured: " + ex.Message; } }
private void StartGame() { try { PokerSession currentPokerSession = (PokerSession)Session["PokerSession"]; PokerSessionGame newPokerGame = new PokerSessionGame(); currentPokerSession.gamesPlayed.Add(newPokerGame); newPokerGame.gameNumber = currentPokerSession.gamesPlayed.Count; // Draw the initial 5 cards for each player foreach (Player player in currentPokerSession.sessionPlayers) { player.hand = new PokerHand(newPokerGame); } // Display drawn hands ucComputerHand.hand = currentPokerSession.sessionPlayers[0].hand; ucPlayerHand.hand = currentPokerSession.sessionPlayers[1].hand; ucComputerHand.DisplayPokerHand(); ucPlayerHand.DisplayPokerHand(); // Assign current game to user control ucComputerHand.currentGame = ucPlayerHand.currentGame = newPokerGame; for (int i = 1; i <= 5; i++) { Button btnComputerRedraw = (Button)ucComputerHand.FindControl("btnRedraw" + i); Button btnPlayerRedraw = (Button)ucPlayerHand.FindControl("btnRedraw" + i); btnComputerRedraw.Visible = btnPlayerRedraw.Visible = true; btnComputerRedraw.Enabled = btnPlayerRedraw.Enabled = true; } } catch (Exception ex) { // General exception catch lblDisplayError.Text = "Error occured: " + ex.Message; } }
public static void PokerSessionShouldDistributePotsCorrectly(DistributePotTestCase testCase) { var players = testCase.Players.Select(p => new Player { PlayerPot = testCase.PlayerPot, Cards = CardParser.ParseCards(p.Cards).ToList(), Strategy = p.Folds ? (IPlayerStrategy) new FoldAlwaysStategy() : new AllInStrategy() }).ToList(); var session = new PokerSession(players); session.CheatCommunityCards(CardParser.ParseCards(testCase.CommunityCards).ToList()); session.Simulate(); CollectionAssert.AreEqual( expected: testCase.Players.Select(p => p.ExpectedPot).ToList(), actual: players.Select(p => p.PlayerPot) ); }
protected void btnRedraw_Click(object sender, EventArgs e) { // Get the order number of the card to redraw Button senderButton = (Button)sender; string buttonID = senderButton.ID; int sortOrder = Convert.ToInt32(buttonID.Substring(buttonID.Length - 1, 1)); PokerSession pokerSession = (PokerSession)Session["PokerSession"]; PokerSessionGame currentGame = pokerSession.gamesPlayed.Where(g => g.isActive).FirstOrDefault(); Card drawnCard = currentGame.gameCardDeck.GetCardsFromDeck(1)[0]; // Redraw from computer hand if (senderButton.Parent.ID.ToLower().Contains("computer")) { pokerSession.sessionPlayers[0].hand.cardHands[sortOrder - 1] = drawnCard; this.hand = pokerSession.sessionPlayers[0].hand; } else if (senderButton.Parent.ID.ToLower().Contains("player")) { pokerSession.sessionPlayers[1].hand.cardHands[sortOrder - 1] = drawnCard; this.hand = pokerSession.sessionPlayers[1].hand; } senderButton.Visible = false; this.hand.redrawCount++; if (this.hand.redrawCount == 3) { for (int i = 1; i <= 5; i++) { this.FindControl("btnRedraw" + i).Visible = false; } } DisplayPokerHand(); }
private Task RenderInSessionOptions(PokerSession sessionInformation) { //if(sessionInformation.StoryPointType) throw new NotImplementedException(); }
private void SessionInformationUpdated(PokerSession sessionInformation) { _pokerTerminal.RenderStatusInformation(sessionInformation); }
private IntermediateSimulationResult ComputeChances(SimulationOptions options, IList <Card> cards) { var runner = new BenchmarkRunner(); var result = runner.Run(new BenchmarkOptions <IntermediateSimulationResult> { BatchSize = 16, Seed = new IntermediateSimulationResult { Draw = 0, Runs = 0, Won = 0, WonSingle = 0, Balance = 0 }, RunOnce = () => { var startingPot = 1; var playerIndex = 0; var players = MakePlayers(options, startingPot); var session = new PokerSession(players); session.CheatPlayerCards(session.Players[playerIndex], cards); session.Simulate(); var won = session.Winners.Contains(session.Players[playerIndex]); var wonSingle = won && session.Winners.Count == 1; var balance = -startingPot + session.Players[0].PlayerPot; return(new IntermediateSimulationResult { Draw = (session.Winners.Count == session.Players.Count) ? 1 : 0, WonSingle = (won && session.Winners.Count == 1) ? 1 : 0, Won = won ? 1 : 0, Balance = balance, Runs = 1 }); }, Combine = (a, b) => { return(new IntermediateSimulationResult { Won = (a.Won + b.Won), WonSingle = (a.WonSingle + b.WonSingle), Draw = (a.Draw + b.Draw), Balance = (a.Balance + b.Balance), Runs = (a.Runs + b.Runs) }); }, QuantifiedValues = new List <QuantifiedValueOptions <IntermediateSimulationResult> > { new QuantifiedValueOptions <IntermediateSimulationResult> { GetQuantifiedValue = a => (double)a.Won / a.Runs, ConfidenceLevel = options.ConfidenceLevel, DesiredRelativeError = options.WinLoseRatesDesiredRelativeError }, new QuantifiedValueOptions <IntermediateSimulationResult> { GetQuantifiedValue = a => (double)a.WonSingle / a.Runs, ConfidenceLevel = options.ConfidenceLevel, DesiredRelativeError = options.WinLoseRatesDesiredRelativeError }, new QuantifiedValueOptions <IntermediateSimulationResult> { GetQuantifiedValue = a => (double)(a.Runs - a.Won) / a.Runs, ConfidenceLevel = options.ConfidenceLevel, DesiredRelativeError = options.WinLoseRatesDesiredRelativeError }, new QuantifiedValueOptions <IntermediateSimulationResult> { GetQuantifiedValue = a => (double)a.Balance / a.Runs, ConfidenceLevel = options.ConfidenceLevel, DesiredAbsoluteError = options.BalanceDesiredAbsoluteError } } }); return(result); }
public PokerSession GetCurrentSession(string sessionName) { PokerSession pokerSession = dbHandler.GetPokerSession(sessionName); return(pokerSession); }
internal static void SetVote(PokerSession session, int playerPublicId, string vote) { session.Votes[playerPublicId] = vote; }
public static bool HasVoted(PokerSession session, int playerPublicId) { return(session.Votes.ContainsKey(playerPublicId)); }
internal static void Show(PokerSession session) { session.IsShown = true; }
internal static void Clear(PokerSession session) { session.Votes = new Dictionary <int, string>(); session.IsShown = false; }
internal static void RemoveVote(PokerSession session, int playerPublicId) { session.Votes.Remove(playerPublicId); }