private static void TestGame() { Deck d = new Deck(); Player p = new Player("Robot1", "Robot1"); Player q = new Player("Robot2", "Robot2"); p.SetPocket(d.Draw(), d.Draw()); q.SetPocket(d.Draw(), d.Draw()); Card[] community = { d.Draw(), d.Draw(), d.Draw(), d.Draw(), d.Draw() }; Console.WriteLine(p.FindBestHand(SerializeCommunity(community)).Description); Console.WriteLine(q.FindBestHand(SerializeCommunity(community)).Description); }
public bool Join(Player p) { if (this.started) { if (this.waitList.FirstOrDefault(test => (test == p)) == null) { this.waitList.Enqueue(p); return false; } } if (this.players.Find(test => (test == p)) == null) { this.players.Add(p); } return true; }
private void HandleLeave(Player player) { this.players.Remove(player); if (this.players.Count == 1) { // Everybody left, scrap this game this.Dispose(); } else if (this.CreatorUuid == player.Uuid) { this.CreatorUuid = this.players[0].Uuid; } }
private void HandleRaise(Player player, int bet) { int moneyAdded = player.RemoveFunds(bet - player.Bet); player.Bet += moneyAdded; player.HighestBet = Math.Max(player.HighestBet, player.Bet); this.pot += moneyAdded; this.currBet = player.Bet; this.minRaise = this.currBet + moneyAdded; this.lastAct = String.Format("{0} raises ${1}", player.Name, this.currBet); Console.WriteLine("{0}: {1}", this, this.lastAct); }
private void HandleFold(Player player) { player.Folded = true; this.lastAct = String.Format("{0} folds", player.Name); // If the last person who needs to act is also the last man standing, he doesn't need to take his turn if (this.needToAct.Count == 1 && this.players.Count(p => !p.Folded) == 1) { this.needToAct.Clear(); } }
private void HandleCall(Player player) { int moneyAdded = player.RemoveFunds(this.currBet - player.Bet); player.Bet = this.currBet; this.pot += moneyAdded; this.lastAct = String.Format("{0} calls ${1}", player.Name, this.currBet); Console.WriteLine("{0}: {1}", this, this.lastAct); }
/// <summary> /// Sends a message indicating the hand has ended, and who takes the pot /// </summary> /// <param name="winner"></param> private void DeclareWinner(Player winner) { Dictionary<string, string> end = new Dictionary<string, string>(2); end["type"] = "end"; end["winner"] = winner.Name; end["message"] = this.lastAct; string comm = this.SerializeCommunity(); //end["hands"] = String.Join("\n", this.players.Select(p => p.FindBestHand(comm).Description)); winner.Funds += this.pot; winner.HandsWon++; Database db = Database.getInstance(); this.responsesExpected = 0; foreach (Player p in this.players) { p.HandsPlayed++; db.savePlayer(p); p.Responded = false; this.responsesExpected++; } Player waiting; while (this.waitList.Count > 0) { waiting = this.waitList.Dequeue(); waiting.Responded = true; this.Join(waiting); } this.SendToPlayers(end); this.started = false; }
private void RemovePairs(Player person) { throw new NotImplementedException(); }
public Player loadPlayer(string uuid) { SQLiteConnection conn = new SQLiteConnection(this.dataSource); SQLiteCommand cmd = new SQLiteCommand(conn); Player loaded = null; try { cmd.CommandText = String.Format("SELECT * FROM users WHERE uuid='{0}';", uuid); cmd.Prepare(); conn.Open(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { loaded = new Player(reader.GetString(reader.GetOrdinal("name")), uuid, reader.GetInt32(reader.GetOrdinal("funds")), reader.GetInt32(reader.GetOrdinal("handsWon")), reader.GetInt32(reader.GetOrdinal("lifetimeWinnings")), reader.GetInt32(reader.GetOrdinal("handsPlayed")), reader.GetInt32(reader.GetOrdinal("highestBet"))); } reader.Close(); } catch (SQLiteException e) { Console.WriteLine("SQLite exception: {0}", e); } finally { conn.Close(); } return loaded; }
public bool savePlayer(Player p) { return (this.execNonQuery(String.Format("UPDATE users SET funds={1}, handsWon={2}, handsPlayed={3}, lifetimeWinnings={4}, highestBet={5} WHERE uuid='{0}';", p.Uuid, p.Funds, p.HandsWon, p.HandsPlayed, p.LifetimeWinnings, p.HighestBet)) == 1); }