{"id":20833475,"url":"https://github.com/bupticybee/texasholdemsolverjava","last_synced_at":"2025-04-12T19:44:26.759Z","repository":{"id":37101153,"uuid":"217973708","full_name":"bupticybee/TexasHoldemSolverJava","owner":"bupticybee","description":"A Java implemented Texas holdem and short deck Solver","archived":false,"fork":false,"pushed_at":"2023-07-24T00:41:35.000Z","size":74229,"stargazers_count":853,"open_issues_count":4,"forks_count":192,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-03T22:09:29.226Z","etag":null,"topics":["holdem-poker","piosolver","shortdeck","solver","texas-holdem","texas-holdem-poker"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bupticybee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-10-28T05:40:16.000Z","updated_at":"2025-03-28T04:03:47.000Z","dependencies_parsed_at":"2024-03-12T19:08:10.430Z","dependency_job_id":"9724bdc8-e310-4855-9c00-cc5aede429e4","html_url":"https://github.com/bupticybee/TexasHoldemSolverJava","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bupticybee%2FTexasHoldemSolverJava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bupticybee%2FTexasHoldemSolverJava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bupticybee%2FTexasHoldemSolverJava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bupticybee%2FTexasHoldemSolverJava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bupticybee","download_url":"https://codeload.github.com/bupticybee/TexasHoldemSolverJava/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625479,"owners_count":21135512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["holdem-poker","piosolver","shortdeck","solver","texas-holdem","texas-holdem-poker"],"created_at":"2024-11-18T00:15:41.442Z","updated_at":"2025-04-12T19:44:26.735Z","avatar_url":"https://github.com/bupticybee.png","language":"Java","readme":"# TexasHoldemSolverJava\n\n[![release](https://img.shields.io/github/v/release/bupticybee/TexasHoldemSolverJava?label=release\u0026style=flat-square)](https://github.com/bupticybee/TexasHoldemSolverJava/releases)\n[![license](https://img.shields.io/github/license/bupticybee/TexasHoldemSolverJava?style=flat-square)](https://github.com/bupticybee/TexasHoldemSolverJava/blob/master/LICENSE)\n\nREADME [English](README.md) | [中文](README.zh-CN.md)\n\n:rotating_light: This project still works but it's no longer maintained. Please check our latest C++ version [TexasSolver](https://github.com/bupticybee/TexasSolver).\n\n## Introduction\n\nA open sourced, efficient Texas Hold'em and short deck solver. See this [Introduction video](https://www.youtube.com/watch?v=beqabWkOSRM) for more.\n\n![algs](img/solvergui.gif)\n\nThis is a java-based Texas Hold'em solver, fully open source, have a pio-solver-like gui and supports cross-language calls (supports python and command-line calls by default). Support standard Texas Hold'em and it's popular variant short-deck.\n\nSimilar to common commercial Texas Hold'ems solvers such as piosolver, TexasHoldemSolverJava focusing on solving post-flop situations, and it's result is aligned with piosolver. On ~~turn and~~ river it's speed is even faster than piosolver, but on flop is slower than piosolver.\n\nFeatures:\n\n- Efficient, ~~turn and~~ river calculation speed exceeds piosolver\n- Accurate, the results are almost the same as piosolver\n- Fully open source and free\n- Have a simple gui\n- Support standard Texas Hold'em and it's popular variant short-deck\n- Focus on post-flop situations \n- Supports command line and python calls\n\n\nThis project is suitable for:\n- high-level Texas Hold'em players\n- Scholars in the field of incomplete information games\n\n## install\n\nInstall 64bit [Java Runtime Environment](https://www.oracle.com/java/technologies/javase-jre8-downloads.html) first.\n\nDownload the [release package](https://github.com/bupticybee/TexasHoldemSolverJava/releases) unzip it, you will get a folder look like this:\n\n```\n--- Solver\n |- resources\n |- java_interface.py\n |- RiverSolver.jar\n |- riversolver.sh\n```\n\nInstall is done. It's that simple.\n\n```RiverSolver.jar``` is the solver program file,```java_interface.py``` is the sample code for calling solver trough python calls. It contains the following test cases:\n\n- testcase for short flop situation\n- testcase for short turn situation\n- testcase for short river situation\n- testcase for holdem turn situation\n- testcase for holdem river situation\n\n```riversolver.sh``` contains sample code for command line calls.\n\nafter download the release package, run ```python3 java_interface.py``` to run all the testcases.\n\nIn addition to downloading the software itself, Texas Holdem solver Java also relies on JRE 11.0.2 as it's e runtime. Please install Java JRE 11.0.2 in advance.\n\n\n## Usage\n\n### gui\n\nMake sure the right version of java is installed in your computer(64bit,java 10.x / java 11.x)\n\nDouble click the ```riversolver.jar``` to open gui.\n\n### python api\n\nAdditional python requirements should also be installed through pip:\n\n```bash\npip3 install jpype\npip3 install numpy\npip3 install yaml\npip3 install networkx\npip3 install matplotlib\n```\n\nAlthrough written in java. TexasHoldemSolverJava is by default called through python.\n\nSample code involves python calls can be found in ```java_interface.py```. Here we briefly introduce the procedure of calling the solver and some basic parameters.\n\nWhen running python codes, make sure resource folder and jar file(can be [downloaded](https://github.com/bupticybee/TexasHoldemSolverJava/releases)) are placed in work dir. After that import all dependencies through the code below:\n\n```python\nfrom jpype import *\nimport yaml\nimport numpy as np\nimport sys\nsys.path.append(\"resources\")\nfrom python.TreeBuilder import *\n```\n\nNext, start the JVM and load the solver class:\n\n```python\nstartJVM(getDefaultJVMPath(), \"-ea\", \"-Djava.class.path=%s\" % \"./RiverSolver.jar\")\nPokerSolver = JClass('icybee.solver.runtime.PokerSolver')\n```\n\nInitialize PokerSolver class, PokerSolver is used to do the optimal strategy finding(solving) job.\n\n```python\nps_holdem = PokerSolver(\"Dic5Compairer\",\n    \"./resources/compairer/card5_dic_sorted.txt\", # Load hand compair dictionary file. Holdem and shortdeck use different dictionary file\n    2598961, # valid line of dictionary file\n    ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3'], # figure of cards\n    ['h', 's', 'd', 'c'] # pattern of cards\n)\n```\n\nLike in piosolver, when solving a specific holdem/shortdeck scenario (for example in turn), a game tree should be built first: \n\n```python\n# Load some general rules of texas holdem. e.g. you can check/raise after a check, you can raise/call/fold after a raise.\nwith open('resources/yamls/general_rule.yaml') as fhdl:\n    conf = yaml.load(fhdl)\n# Use RulesBuilder to convert these rules to game tree.\nrule = RulesBuilder(\n    conf,\n    current_commit = [2,2], # current bets of both players(p0 and p1)\n    current_round =  3, # current round of the game, 1 for preflop, 2 for flop,3 for turn,4 for river\n    raise_limit = 3, # the limit of numbers of raises\n    check_limit = 2, # how many times you can check, in 2-player texas holdem, it's 2\n    small_blind = 0.5, # amount of small blind (SB)\n    big_blind = 1, # amount of big blind (BB)\n    stack = 10, # the amount of chips for both sides. If two player have different chip amount, fill in the smaller number here. For example player1 have $100 chip and player2 have $150, fill in 100 here.\n    bet_sizes = [\"0.5_pot\",\"1_pot\",\"2_pot\",\"all-in\"], # bet sizes and raise sizes considered in the game tree,can be number e.g. 1,1.5 or in the proportion of the pot e.g. \"0.5_pot\",\"1_pot\"\n)\n# build the game tree according to the settings above\ngameTree = PartGameTreeBuilder(rule)\n# save the game tree to disk\ngameTree.gen_km_json(\"./.tree.km\",limit=np.inf,ret_json=True)\n```\n\nRead the game tree in solver and construct the game tree in memory.\n\n```python\nps_holdem.build_game_tree(\"./.tree.km\")\n```\n\nInput all the parameters and start solving.\n\n```python\nresult = ps_holdem.train(\n    \"AA:0.5,KK:0.9,QQ:0.8,97,96,87,86,76\", # player1's range, seperate by ','; you can write range in two ways: (1) \"KK:0.5\" stands for player have K-pair weighted 0.5 (2) \"KK\" stands for player have a K-pair weighted 1\n    \"AA:0.8,KK:0.2,QQ:0.3,86,76:0.9\", # player2's range\n    \"Kd,Jd,Td,7s\", # the revealed public cards. In turn there are four. \n    50, # the iterations for cfr algorithm\n    10, # the gap to print exploitability\n    False, # whether to print debug info\n    True, # whether to use parallel technology\n    \"output_strategy.json\", # for to write output strategy. When set to None the strategy json will be returned in result of this method.\n    \"log.txt\", # log file \n    \"discounted_cfr\", # the solver algorithm ,support \"cfr\" vanilla cfr algorithm, \"cfr_plus\" faster cfr+ algorithm,\"discounted_cfr\" discounted cfr ++ algorithm we proposed here\n    \"none\", # whether to use monte coral sampling algorithm,useful when the game tree is extremely big,got two options： \"none\" means do not use monte coral algorithm, \"public\" use public chance monte coral algorithm\n    -1, # threads number ,1 for single thread,2 for two threads...,-1 means use all possible cpu\n    1, # action fork probability, relevant to solver multithread performance ,should be between 0～1\n    1, # chance fork probability, relevant to solver multithread performance ,should be between 0～1\n    1, # fork every tree depth, relevant to solver multithread performance , should be \u003e 0\n    4, # fork minimal size, relevant to solver multithread performance , should be \u003e 0\n)\n```\n\nThe solver will start to work after executing the above code. Time required for solving is affected by game tree size, range complicity, and computer hardware. In my mac book pro, river can be solved in less than 1 second, turn can be solved usually within 10 seconds.\n\n### command line api\n\nPlease refer to code in ```riversolver.sh``` in [release package](https://github.com/bupticybee/TexasHoldemSolverJava/releases). The parameters are the same to the python code.\n\n### Reading the Solver's output\nWhen running, the solver would generate logs like this:\n```text\nIter: 0\nplayer 0 exploitability 1.653075\nplayer 1 exploitability 2.146374\nTotal exploitability 47.493111 precent\n-------------------\nIter: 11\nplayer 0 exploitability 0.040586\nplayer 1 exploitability 0.322102\nTotal exploitability 4.533607 precent\n-------------------\n......\n-------------------\nIter: 41\nplayer 0 exploitability -0.114473\nplayer 1 exploitability 0.168947\nTotal exploitability 0.680923 precent\n.Using 4 threads\n```\nBe ware how the exploitability converges, normally a strategy with an exploitability \u003c 0.5 is more than enough to serve as an optimal strategy.\n\nAn ```output_strategy.json``` file will be generated by the solver after solving. It can be read by any language and you can directly opened by firefox(yes, the famous browser）. The size of the file varies between a few Kb to dozens of Gb.\n\nIf opened by firefox, you are excepted to see something looks like this：\n\n![algs](img/strategy1.png)\n\n\n```text\nplayer : 1\n```\n\nThis field indicates player1 is making his move.\n\n```text\nactions:\n    0: \"CHECK\"\n    1: \"BET 4.0\"\n```\n\n\"actions\" field contains player1's moves considered by the solver. \n\nStrategy field contains optimal strategy for player1 with different hands:\n\n![algs](img/strategy2.png)\n\nEach specific item of strategy contains the \"optimal strategy\" of specific hand calculated by the solver.\n\n![algs](img/strategy3.png)\n\nFor example, the figure above represents that when player 1 gets the hand of qd7c (square Q, plum 7), the optimal strategy is to check with 34% probability and bet with 65% probability.\n\n## Compile the release package\nNormally compiling the release package manually is not required. It can be directly downloaded [here](https://github.com/bupticybee/TexasHoldemSolverJava/releases)\nHowever if you intend to modify this project, recompiling is required. TexasHoldemSolverJava is a IDEA project, an IDEA environment is required to compile the release package, if you want to compile the release package, please follow the following instruction：\n1. install IntellIJ IDEA\n2. download TexasHoldemSolverJava from github and load to IntellIJ IDEA\n3. press build -\u003e build project to compile the projet from source\n4. press build -\u003e build artifacts -\u003e all artifacts -\u003e build to generate the release package\n5. the release package can be found in the ```out``` folder in project root\n\n## benchmarks\n\nThe speed compair with piosolver listed below, turn and river's speed is comparable with piosolver , flop is much slower due to game tree and lack of optimization.\n\n|                       | flop sample | turn sample | river sample |\n| --------------------- | ----------- | ----------- | ------------ |\n| piosolver             | 7.91s       | 1.5s        | 0.56s        |\n| TexasHoldemSolverJava | 98s         | 4.21s       | 0.06s        |\n\nInput of the above benchmark and result compair with piosolver is listed below.\n\n|                | flop sample | turn sample | river sample |\n| -------------- | ----------- | ----------- | ------------ |\n| input (in text format)        |   [flop](benchmarks/benchmark_flop.txt)          | [turn](benchmarks/benchmark_turn.txt)            |        [river](benchmarks/benchmark_river.txt)      |\n| input (in image format)         |   ![flop](img/flop_setting.jpeg)          | ![turn](img/turn_setting.jpeg)            |       ![river](img/river_setting.jpeg)       | \n| result compair         |   ![flop](img/flop_result.jpeg)          | ![turn](img/turn_result.jpeg)            |       ![river](img/river_result.jpeg)       | \n\nThe slight different between Piosolver and TexasHoldemSolverJava is due to different tree construction logic and insufficient CFR converge for both software.\n\n## Algorithm\nAs shown in the figure below, thanks to the implementation of the latest algorithm variant discounted CFR ++, algorithm used in this project can be a lot faster than traditional algorithms such as CFR +.\n![algs](img/algs.png)\n\n## c++ version\n\nIf you somehow feel our java version is not fast enough,here is a ported [c++ version](https://github.com/bupticybee/TexasSolver) ,c++ version is faster than java version in turn and river, however still contains certain problems：\n\n- ~~supports only Linux machine~~\n- ~~manually compile is reqiured before use~~\n- ~~c++ version's code is not well optimized~~, it's ~~slower~~ 5x faster than the java version on flop.\n\n## License\n\n[MIT](LICENSE) © bupticybee\n\n## Contact\n\nicybee@yeah.net\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbupticybee%2Ftexasholdemsolverjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbupticybee%2Ftexasholdemsolverjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbupticybee%2Ftexasholdemsolverjava/lists"}