Package: texasholdem
texasholdemA python package for Texas Hold 'Em Poker providing:Fast evaluation of hand strengthsExport & import human-readable game historyGUIs to view games and game historySimple & complex agentsCompliance with World Series of Poker Official RulesAnd moreVersion NameLatest TagRelease NotesPatch NotesDocumentationRelease DateEnd Support Date0.10v0.10.0Release NotesPatch NotesDocumentation3 July 20230.9v0.9.0Release NotesPatch NotesDocumentation14 March 20230.8v0.8.1Release NotesPatch NotesDocumentation6 November 202230 June 20230.7v0.7.3Release NotesPatch NotesDocumentation16 April 202230 June 2023Current Roadmapv1.0.0Changelog v0.10FeaturesAbility to create a copy of the TexasHoldEm object. You can do a simpledeepcopy()orcopy()of a TexasHoldEm object. It will give you another TexasHoldEm with the exact game state.
Or you can also usecopy()method which will construct a copy of the game state.Added available actions printing in the TextGUI.ContributingWant a new feature, found a bug, or have questions? Feel free to add to our issue board on Github!Open Issues.We welcome any developer who enjoys the package enough to contribute! Please message me atevyn.machi@gmail.comif you want to be added as a contributor and check out theDeveloper's Guide.InstallThe package is available on pypi and can be installed withpipinstalltexasholdemFor the latest experimental versionpipinstalltexasholdem--preQuickstartPlay a game from the command line and take turns for every player out of the box.fromtexasholdem.game.gameimportTexasHoldEmfromtexasholdem.gui.text_guiimportTextGUIgame=TexasHoldEm(buyin=500,big_blind=5,small_blind=2,max_players=6)gui=TextGUI(game=game)whilegame.is_game_running():game.start_hand()whilegame.is_hand_running():gui.run_step()path=game.export_history('./pgns')# save historygui.replay_history(path)# replay historyOverviewThe following is a quick summary of what's in the package. Please see thedocsfor all the details.Game InformationGet game information and take actions through intuitive attributes.fromtexasholdemimportTexasHoldEm,HandPhase,ActionTypegame=TexasHoldEm(buyin=500,big_blind=5,small_blind=2,max_players=9)game.start_hand()assertgame.hand_phase==HandPhase.PREFLOPassertHandPhase.PREFLOP.next_phase()==HandPhase.FLOPassertgame.chips_to_call(game.current_player)==game.big_blindassertlen(game.get_hand(game.current_player))==2game.take_action(ActionType.CALL)player_id=game.current_playergame.take_action(ActionType.RAISE,total=10)assertgame.player_bet_amount(player_id)==10assertgame.chips_at_stake(player_id)==20# total amount in all pots the player is inassertgame.chips_to_call(game.current_player)==10-game.big_blindCardsThe card module represents cards as 32-bit integers for simple and fast hand
evaluations.fromtexasholdemimportCardcard=Card("Kd")# King of Diamondsassertisinstance(card,int)# Trueassertcard.rank==11# 2nd highest rank (0-12)assertcard.pretty_string=="[ K ♦ ]"AgentsThe package also comes with basic agents includingcall_agentandrandom_agentfromtexasholdemimportTexasHoldEmfromtexasholdem.agentsimportrandom_agent,call_agentgame=TexasHoldEm(buyin=500,big_blind=5,small_blind=2)game.start_hand()whilegame.is_hand_running():ifgame.current_player%2==0:game.take_action(*random_agent(game))else:game.take_action(*call_agent(game))Game HistoryExport and import the history of hands to files.fromtexasholdemimportTexasHoldEmfromtexasholdem.guiimportTextGUIgame=TexasHoldEm(buyin=500,big_blind=5,small_blind=2)game.start_hand()whilegame.is_hand_running():game.take_action(*some_strategy(game))# export to filegame.export_history("./pgns/my_game.pgn")# import and replaygui=TextGUI()gui.replay_history("./pgns/my_game.pgn")PGN files also support single line and end of line comments starting with "#".Poker EvaluatorThe evaluator module returns the rank of the best 5-card hand from a list of 5 to 7 cards.
The rank is a number from 1 (strongest) to 7462 (weakest).fromtexasholdemimportCardfromtexasholdem.evaluatorimportevaluate,rank_to_stringassertevaluate(cards=[Card("Kd"),Card("5d")],board=[Card("Qd"),Card("6d"),Card("5s"),Card("2d"),Card("5h")])==927assertrank_to_string(927)=="Flush, King High"GUIsThe GUI package currently comes with a text-based GUI to play games from the command line. Coming later
will be web-app based GUIs.