forked from google-deepmind/open_spiel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-- de2e362 by Dennis Jöst <djprivat@gmail.com>: Gitignore for clion -- 8985b63 by Dennis Jöst <djprivat@gmail.com>: Create and compile Stubs -- 4f4db67 by Dennis Jöst <djprivat@gmail.com>: Add my lib -- f5f1e9e by Dennis Jöst <djprivat@gmail.com>: cmake adjustments -- 06a6f64 by Dennis Jöst <djprivat@gmail.com>: Fix unit test -- 6c50e62 by Dennis Jöst <djprivat@gmail.com>: Empty all stubs -- 913eb85 by Dennis Jöst <djprivat@gmail.com>: current compiling version with npe -- f75ddef by Dennis Jöst <djprivat@googlemail.com>: No oberservations and information sets. But unit test is running -- ad349c8 by Dennis Jöst <djprivat@gmail.com>: Auto stash before merge of "feature/universal_poker_game" and "origin/feature/universal_poker_game" -- 3473754 by Dennis Jöst <djprivat@gmail.com>: complete refactoring -- 8feded8 by Dennis Jöst <djprivat@gmail.com>: Impl with unittest done until Gamestate -- f876978 by Dennis Jöst <djprivat@gmail.com>: Deal Cards after showdown and calculate rewards -- 77a940f by Dennis Jöst <djprivat@gmail.com>: Another test -- 70794fc by Dennis Jöst <djprivat@gmail.com>: some hight level tests -- 91e0523 by Dennis Jöst <djprivat@gmail.com>: Make compatible with older cmake Versions -- c98ac92 by Dennis Jöst <djprivat@gmail.com>: Parametrize Game to fix unit tests -- 4c74256 by Dennis Jöst <djprivat@gmail.com>: Fix Memory violation -- fce45f0 by Dennis Jöst <djprivat@gmail.com>: CI fix -- a5d1286 by Dennis Jöst <djprivat@gmail.com>: Update install sh -- 176f167 by Dennis Jöst <djprivat@gmail.com>: Remove ACPC and add to gitignore -- 5339240 by Dennis Jöst <djprivat@gmail.com>: Use original ACPC in latest version as dependency only -- 8227309 by Dennis Jöst <djprivat@googlemail.com>: Fix strict compiler error PiperOrigin-RevId: 281027101 Change-Id: I4f7ef219d780aa4c4f3cece1c905e14dc007c92e
- Loading branch information
Showing
25 changed files
with
2,300 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"import os\n", | ||
"\n", | ||
"sys.path.insert(0, os.path.join(os.path.abspath(os.getcwd()), '..', '..'))\n", | ||
"sys.path.insert(0, os.path.join(os.path.abspath(os.getcwd()), '..', '..', 'build', 'python'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyspiel\n", | ||
"from open_spiel.python.algorithms import cfr, exploitability\n", | ||
"from open_spiel.python.algorithms import expected_game_score" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Registered games:\n", | ||
"[<GameType 'backgammon'>, <GameType 'blotto'>, <GameType 'breakthrough'>, <GameType 'bridge_uncontested_bidding'>, <GameType 'catch'>, <GameType 'chess'>, <GameType 'coin_game'>, <GameType 'connect_four'>, <GameType 'coop_box_pushing'>, <GameType 'first_sealed_auction'>, <GameType 'go'>, <GameType 'goofspiel'>, <GameType 'havannah'>, <GameType 'hex'>, <GameType 'kuhn_poker'>, <GameType 'laser_tag'>, <GameType 'leduc_poker'>, <GameType 'liars_dice'>, <GameType 'markov_soccer'>, <GameType 'matching_pennies_3p'>, <GameType 'matrix_cd'>, <GameType 'matrix_coordination'>, <GameType 'matrix_mp'>, <GameType 'matrix_pd'>, <GameType 'matrix_rps'>, <GameType 'matrix_sh'>, <GameType 'matrix_shapleys_game'>, <GameType 'misere'>, <GameType 'negotiation'>, <GameType 'oshi_zumo'>, <GameType 'oware'>, <GameType 'pentago'>, <GameType 'phantom_ttt'>, <GameType 'pig'>, <GameType 'quoridor'>, <GameType 'tic_tac_toe'>, <GameType 'tiny_bridge_2p'>, <GameType 'tiny_bridge_4p'>, <GameType 'tiny_hanabi'>, <GameType 'turn_based_simultaneous_game'>, <GameType 'universal_poker'>, <GameType 'y'>]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"\n", | ||
"game = pyspiel.load_game(\"universal_poker\")\n", | ||
"\n", | ||
"games_list = pyspiel.registered_games()\n", | ||
"\n", | ||
"print(\"Registered games:\")\n", | ||
"print(games_list)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\"\"\"Test that Python and C++ bots can be called by a C++ algorithm.\"\"\"\n", | ||
"\n", | ||
"from __future__ import absolute_import\n", | ||
"from __future__ import division\n", | ||
"from __future__ import print_function\n", | ||
"\n", | ||
"from absl.testing import absltest\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"from open_spiel.python.bots import uniform_random\n", | ||
"import pyspiel\n", | ||
"\n", | ||
"game = pyspiel.load_game(\"leduc_poker\")\n", | ||
"bots = [\n", | ||
" pyspiel.make_uniform_random_bot(game, 0, 1234),\n", | ||
" uniform_random.UniformRandomBot(game, 1, np.random.RandomState(4321)),\n", | ||
"]\n", | ||
"results = np.array([\n", | ||
" pyspiel.evaluate_bots(game.new_initial_state(), bots, iteration)\n", | ||
" for iteration in range(10000)\n", | ||
"])\n", | ||
"leduc_average_results = np.mean(results, axis=0)\n", | ||
"print(leduc_average_results)\n", | ||
"\n", | ||
"game = pyspiel.load_game(\"universal_poker\")\n", | ||
"bots = [\n", | ||
" pyspiel.make_uniform_random_bot(game, 0, 1234),\n", | ||
" uniform_random.UniformRandomBot(game, 1, np.random.RandomState(4321)),\n", | ||
"]\n", | ||
"results = np.array([\n", | ||
" pyspiel.evaluate_bots(game.new_initial_state(), bots, iteration)\n", | ||
" for iteration in range(10000)\n", | ||
"])\n", | ||
"universal_poker_average_results = np.mean(results, axis=0)\n", | ||
"print(universal_poker_average_results)\n", | ||
" \n", | ||
"#np.testing.assert_allclose(universal_poker_average_results, leduc_average_results, atol=0.1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"kuhnGameDesc = '''GAMEDEF\n", | ||
"limit\n", | ||
"numPlayers = 2\n", | ||
"numRounds = 1\n", | ||
"blind = 1 1\n", | ||
"raiseSize = 1\n", | ||
"firstPlayer = 1\n", | ||
"maxRaises = 1\n", | ||
"numSuits = 1\n", | ||
"numRanks = 3\n", | ||
"numHoleCards = 1\n", | ||
"numBoardCards = 0\n", | ||
"END GAMEDEF'''" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"# flags.DEFINE_integer(\"iterations\", 100, \"Number of iterations\")\n", | ||
"# flags.DEFINE_string(\"game\", \"kuhn_poker\", \"Name of the game\")\n", | ||
"# flags.DEFINE_integer(\"players\", 2, \"Number of players\")\n", | ||
"# flags.DEFINE_integer(\"print_freq\", 10, \"How often to print the exploitability\")\n", | ||
"\n", | ||
"# Compare exloitability for two games\n", | ||
"\n", | ||
"game_1 = \"leduc_poker\"\n", | ||
"game_2 = \"universal_poker\"\n", | ||
"players = 2\n", | ||
"iterations = 1000\n", | ||
"print_freq = 1\n", | ||
"\n", | ||
"def compare_exploitability(game_1 = game_1, game_2 = game_2):\n", | ||
" game_1 = pyspiel.load_game(game_1,\n", | ||
" {\"players\": pyspiel.GameParameter(players)})\n", | ||
" cfr_solver_1 = cfr.CFRSolver(game_1)\n", | ||
" game_2 = pyspiel.load_game(game_2)\n", | ||
" cfr_solver_2 = cfr.CFRSolver(game_2)\n", | ||
" \n", | ||
" for i in range(iterations):\n", | ||
" cfr_solver_1.evaluate_and_update_policy()\n", | ||
" cfr_solver_2.evaluate_and_update_policy()\n", | ||
" if i % print_freq == 0:\n", | ||
" conv_1 = exploitability.exploitability(game_1, cfr_solver_1.average_policy())\n", | ||
" conv_2 = exploitability.exploitability(game_2, cfr_solver_2.average_policy())\n", | ||
"\n", | ||
"\n", | ||
" print(\"Iteration {} exploitability of the {}: {} {}: {}\".format(i, game_1, game_2, conv_1, conv_2))\n", | ||
"\n", | ||
" print(\"Final exploitability is {}: {} {}: {}\".format(game_1, game_2, conv_1, conv_2))\n", | ||
" \n", | ||
"compare_exploitability(game_1, game_2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyspiel\n", | ||
"from open_spiel.python.visualizations import treeviz\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"game = \"universal_poker\"\n", | ||
"out = \"/tmp/gametree.png\"\n", | ||
"prog = \"dot\"\n", | ||
"group_infosets = False\n", | ||
"group_terminal = False\n", | ||
"verbose = False\n", | ||
"\n", | ||
"def _zero_sum_node_decorator(state):\n", | ||
" \"\"\"Custom node decorator that only shows the return of the first player.\"\"\"\n", | ||
" attrs = treeviz.default_node_decorator(state) # get default attributes\n", | ||
" if state.is_terminal():\n", | ||
" attrs[\"label\"] = str(int(state.returns()[0]))\n", | ||
" return attrs\n", | ||
"\n", | ||
"\n", | ||
"game = pyspiel.load_game(game, {'gameDesc': pyspiel.GameParameter(ku)} )\n", | ||
"game_type = game.get_type()\n", | ||
"\n", | ||
"if game_type.dynamics != pyspiel.GameType.Dynamics.SEQUENTIAL:\n", | ||
" raise ValueError(\"Game must be sequential, not {}\".format(\n", | ||
" game_type.dynamics))\n", | ||
"\n", | ||
"if (game_type.utility == pyspiel.GameType.Utility.ZERO_SUM and\n", | ||
" game.num_players() == 2):\n", | ||
" gametree = treeviz.GameTree(\n", | ||
" game,\n", | ||
" node_decorator=_zero_sum_node_decorator,\n", | ||
" group_infosets=group_infosets,\n", | ||
" group_terminal=group_terminal)\n", | ||
"else:\n", | ||
" gametree = treeviz.GameTree(game) # use default decorators\n", | ||
"\n", | ||
"if verbose:\n", | ||
" logging.info(\"Game tree:\\n%s\", gametree.to_string())\n", | ||
"\n", | ||
"gametree.draw(out, prog=prog)\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.