public void removeWaitingPlayer(PlayingUser player) { if (waitingList.Contains(player)) { waitingList.Remove(player); } }
private void ResetGame() { pot[0] = 0; bettingRound = 0; cards = null; gameDeck = new Deck(); PlayingUser dealer = players.First(); players.Remove(dealer); players.Insert(players.Count, dealer); IEnumerable <PlayingUser> QuitPlayers = players.Where(user => user.GetStatus().Equals("Quit")); foreach (PlayingUser player in QuitPlayers) { players.Remove(player); playerBets.Remove(player); } foreach (PlayingUser player in players) { player.SetStatus("Active"); playerHands.Remove(player.GetUserName()); playerBets[player] = player.GetCredit(); } }
public FoldMove(IDictionary <string, int> playerBets, PlayingUser folder) { this.playerBets = playerBets; foldingPlayer = folder.GetUserName(); //foldingPlayer.SetStatus("Fold"); base.type = "FoldMove"; }
public BetMove(IDictionary <string, int> playerBets, PlayingUser better, int amt) { this.playerBets = playerBets; bettingPlayer = better.GetUserName(); //bettingPlayer.SetStatus("Talked"); betAmount = amt; base.type = "BetMove"; }
private void PushFoldMove(PlayingUser pl) { IDictionary <string, int> playerBetsString = new Dictionary <string, int>(); foreach (PlayingUser player in playerBets.Keys) { playerBetsString.Add(player.GetUserName(), playerBets[player]); //username } PushMoveToObservers(new FoldMove(playerBetsString, pl)); }
public void AddPlayerToGame() { Game g = new Game(new GamePreferences()); UserProfile Niv = new UserProfile("Niv", "123"); PlayingUser nivPlayer = new PlayingUser(Niv.Username, 1000, g); Assert.IsEmpty(g.GetPlayers()); g.addPlayer(nivPlayer); Assert.Contains(nivPlayer, g.GetPlayers()); }
public void RemovePlayerFromGame() { Game g = new Game(new GamePreferences()); UserProfile Niv = new UserProfile("Niv", "123"); PlayingUser nivPlayer = new PlayingUser(Niv.Username, 1000, g); g.addPlayer(nivPlayer); Assert.IsNotEmpty(g.GetPlayers()); g.removePlayer(nivPlayer); Assert.IsEmpty(g.GetPlayers()); }
private void TraversePlayers(int index) { while (!EndOfBettingRound()) { Console.WriteLine(index); PlayingUser currentUser = players.ElementAt(index); int minimumBet = GetMaxBet() - playerBets[currentUser]; if (!(currentUser.GetStatus().Equals("Fold") && (currentUser.GetStatus().Equals("Quit")))) //player didn't fold { int bet = players[index].Bet(minimumBet); while (bet < minimumBet && bet >= 0) { bet = currentUser.BadBet(bet, minimumBet); } if (bet >= 0) //check|call|raise { playerBets[currentUser] += bet; bettingRound += bet; PushBetMove(currentUser, bet); } else //fold { playerBets[currentUser] = 0; playerHands.Remove(currentUser.GetUserName());//username currentUser.SetStatus("Fold"); PushFoldMove(currentUser); } if (DidEveryoneFold()) { pot[0] += bettingRound; bettingRound = 0; gameEnded = true; return; } } index++; if (index == players.Count) { index = 0; } } pot[0] += bettingRound; bettingRound = 0; foreach (PlayingUser player in players) { if (player.GetStatus() == "Talked") { player.SetStatus("Active"); } } }
public void AddPlayerToGameWaitingList() { Game g = new Game(new GamePreferences()); UserProfile Niv = new UserProfile("Niv", "123"); PlayingUser nivPlayer = new PlayingUser(Niv.Username, 1000, g); g.GetGamePref().SetStatus("Active"); Assert.IsEmpty(g.GetPlayers()); g.addPlayer(nivPlayer); Assert.False(g.GetPlayers().Contains(nivPlayer)); Assert.True(g.GetWaitingList().Contains(nivPlayer)); }
public void UpdateBestHand() { Game g = new Game(new GamePreferences()); GameLogger logger = g.GetLogger(); UserProfile Niv = new UserProfile("Niv", "123"); UserProfile Omer = new UserProfile("Omer", "456"); UserProfile Naor = new UserProfile("Naor", "789"); UserProfile Koren = new UserProfile("Koren", "9"); UserProfile Ohad = new UserProfile("Ohad", "8"); PlayingUser nivPlayer = new PlayingUser(Niv.Username, 1000, g); PlayingUser OPlayer = new PlayingUser(Omer.Username, 1000, g); PlayingUser NPlayer = new PlayingUser(Naor.Username, 1000, g); PlayingUser KPlayer = new PlayingUser(Koren.Username, 1000, g); PlayingUser OhPlayer = new PlayingUser(Ohad.Username, 1000, g); g.addPlayer(nivPlayer); g.addPlayer(OPlayer); g.addPlayer(NPlayer); g.addPlayer(KPlayer); g.addPlayer(OhPlayer); nivPlayer.SetFakeUserInput(new Queue <string>(new[] { "5", "0", "100" })); OPlayer.SetFakeUserInput(new Queue <string>(new[] { "0", "0", "100", "100", "0", "50", "Fold" })); NPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); KPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); OhPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); g.StartGame(); nivPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); OPlayer.SetFakeUserInput(new Queue <string>(new[] { "5", "0", "100" })); NPlayer.SetFakeUserInput(new Queue <string>(new[] { "0", "0", "100", "100", "0", "50", "Fold" })); KPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); OhPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "100", "100", "100" })); g.StartGame(); foreach (PlayingUser player in g.GetPlayers()) { if (player.GetCredit() > 1000) { Assert.AreNotEqual(CardAnalyzer.HandRank.HighCard, player.GetBestHand()); } } }
public void addPlayer(PlayingUser player) { if ((players.Count + waitingList.Count) == gamePref.GetMaxPlayers()) { throw new InvalidOperationException("Maximum number of players reached"); } if (gamePref.GetStatus().Equals("Active")) { waitingList.Add(player); return; } //player.GetAccount().Credit -= player.GetCredit(); //gamecenter players.Add(player); playerBets.Add(player, player.GetCredit()); if (players.Count >= gamePref.GetMinPlayers()) { Thread thread = new Thread(new ThreadStart(StartGame)); thread.Start(); } }
public void removePlayer(PlayingUser player) { if (players.Count == 0) { throw new InvalidOperationException("No players to remove"); } if (!players.Contains(player)) { throw new InvalidOperationException("Player not in game"); } if (this.gamePref.GetStatus().Equals("Inactive") || this.gamePref.GetStatus().Equals("Init")) //not in middle of round { players.Remove(player); playerBets.Remove(player); } else //in middle of round { if (playerHands.ContainsKey(player.GetUserName())) { playerHands.Remove(player.GetUserName()); //remove this now so that their hand isn't calculated in CA } player.SetStatus("Quit"); } var e = evt; if (e != null) { evt(player); } player = null; }
public void IncreaseBiggestPotWon() { Game g = new Game(new GamePreferences()); UserProfile Niv = new UserProfile("Niv", "123"); UserProfile Omer = new UserProfile("Omer", "456"); UserProfile Naor = new UserProfile("Naor", "789"); PlayingUser nivPlayer = new PlayingUser(Niv.Username, 1000, g); PlayingUser OPlayer = new PlayingUser(Omer.Username, 1000, g); PlayingUser NPlayer = new PlayingUser(Naor.Username, 1000, g); g.addPlayer(nivPlayer); g.addPlayer(OPlayer); g.addPlayer(NPlayer); nivPlayer.SetFakeUserInput(new Queue <string>(new[] { "Fold" })); OPlayer.SetFakeUserInput(new Queue <string>(new[] { "20" })); NPlayer.SetFakeUserInput(new Queue <string>(new[] { "10", "Fold" })); g.StartGame(); Assert.AreEqual(45, OPlayer.GetMostWon()); }
public void StartGame() { List <PlayingUser> winners = new List <PlayingUser>(); List <string> userNames = new List <string>(); gamePref.SetStatus("Active"); foreach (PlayingUser player in waitingList) { players.Add(player); playerBets.Add(player, player.GetCredit()); } foreach (PlayingUser player in players) { player.GainPerRound.Add(0); } waitingList.Clear(); foreach (SpectatingUser spec in specWaitingList) { spectators.Add(spec); } specWaitingList.Clear(); updatePlayerBets(0, true); //SystemLogger.Log("game started","GameLogs.log"); //if (gamePref.GetMinPlayers() > GetNumberOfPlayers()) // throw new InvalidOperationException("Can't start game with less than the minimum number of players"); Thread.Sleep(1000); int potInt = pot[0]; //announce game started gameEnded = false; gameDeck.Shuffle(); //send the array of players to all the observers PushStartGameMove(); //Thread.Sleep(2000); //waiting for observers updatePlayerBets(0, false); //request small blind PlayingUser smallBlindPlayer = players.ElementAt(0); int smallBlindBet = smallBlindPlayer.GetBlind(gamePref.GetsB()); bettingRound += smallBlindBet; playerBets[smallBlindPlayer] = smallBlindBet; //send small blind move PushBetMove(smallBlindPlayer, smallBlindBet); //request big blind PlayingUser bigBlindPlayer = players.ElementAt(1); int bigBlindBet = bigBlindPlayer.GetBlind(gamePref.GetbB()); bettingRound += bigBlindBet; playerBets[bigBlindPlayer] = bigBlindBet; //send big blind move PushBetMove(bigBlindPlayer, bigBlindBet); //draw hands foreach (PlayingUser player in players) { PlayerHand ph = gameDeck.drawPlayerHand(); player.SetHand(ph); NotificationService.Instance.setHand(player.GetUserName(), ph, id); playerHands.Add(player.GetUserName(), ph); //only username } //request bet from rest of players TraversePlayers(2 % players.Count); if (gameEnded) //WAS gameEnded { GiveWinnings(); PushMoveToObservers(new EndGameMove(playerHands)); winners = DetermineWinner(); userNames = spectators.Union(players).Select(user => user.GetUserName()).ToList(); NotificationService.Instance.pushWinners(userNames, winners.Select(winner => winner.GetUserName()).ToList(), id); //ResetGame(); goto GameEnd; } cards = new Card[5]; Card[] flop = gameDeck.drawFlop(); cards[0] = flop[0]; cards[1] = flop[1]; cards[2] = flop[2]; PushMoveToObservers(new NewCardMove(cards)); TraversePlayers(0); if (gameEnded) { GiveWinnings(); PushMoveToObservers(new EndGameMove(playerHands)); winners = DetermineWinner(); userNames = spectators.Union(players).Select(user => user.GetUserName()).ToList(); NotificationService.Instance.pushWinners(userNames, winners.Select(winner => winner.GetUserName()).ToList(), id); //ResetGame(); goto GameEnd; } cards[3] = gameDeck.DrawTableCard(); PushMoveToObservers(new NewCardMove(cards)); TraversePlayers(0); if (gameEnded) { GiveWinnings(); PushMoveToObservers(new EndGameMove(playerHands)); winners = DetermineWinner(); userNames = spectators.Union(players).Select(user => user.GetUserName()).ToList(); NotificationService.Instance.pushWinners(userNames, winners.Select(winner => winner.GetUserName()).ToList(), id); //ResetGame(); goto GameEnd; } cards[4] = gameDeck.DrawTableCard(); PushMoveToObservers(new NewCardMove(cards)); TraversePlayers(0); if (gameEnded) { GiveWinnings(); PushMoveToObservers(new EndGameMove(playerHands)); winners = DetermineWinner(); userNames = spectators.Union(players).Select(user => user.GetUserName()).ToList(); NotificationService.Instance.pushWinners(userNames, winners.Select(winner => winner.GetUserName()).ToList(), id); //ResetGame(); goto GameEnd; } PushMoveToObservers(new EndGameMove(playerHands)); winners = DetermineWinner(); userNames = spectators.Union(players).Select(user => user.GetUserName()).ToList(); NotificationService.Instance.pushWinners(userNames, winners.Select(winner => winner.GetUserName()).ToList(), id); foreach (PlayingUser player in winners) { player.ReceiveWinnings(pot[0] / winners.Count); } foreach (PlayingUser player in players) { if (!winners.Contains(player)) { player.SetRoundsLost(player.GetRoundsLost() + 1); } } GameEnd: gamePref.Status = "Inactive"; ResetGame(); Thread.Sleep(10000); if ((waitingList.Count + playerBets.Count) >= gamePref.GetMinPlayers()) { StartGame(); } }