Skip to content

Commit

Permalink
Copybara import of the project:
Browse files Browse the repository at this point in the history
--
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
DeepMind Technologies Ltd authored and jblespiau committed Nov 18, 2019
1 parent 63a20f4 commit 1adfccb
Show file tree
Hide file tree
Showing 25 changed files with 2,300 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ build/
# External git modules
open_spiel/abseil-cpp/
open_spiel/games/bridge/double_dummy_solver/
open_spiel/games/universal_poker/double_dummy_solver/
pybind11/

# Install artifacts
get-pip.py

# IDE
.idea/

open_spiel/cmake-build-debug/
8 changes: 8 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fi
[[ -d open_spiel/games/bridge/double_dummy_solver ]] || \
git clone -b 'develop' --single-branch --depth 1 https://github.com/jblespiau/dds.git \
open_spiel/games/bridge/double_dummy_solver

# `master` is a moving branch, but we never had issues. Let's use it and
# checkout a specific commit only if an issue occur one day.
[[ -d open_spiel/abseil-cpp ]] || \
Expand All @@ -64,6 +65,13 @@ if [[ ${BUILD_WITH_HANABI:-"ON"} == "ON" ]] && [[ ! -d ${DIR} ]]; then
git clone -b 'master' --single-branch --depth 1 https://github.com/deepmind/hanabi-learning-environment.git ${DIR}
fi

# The official https://github.com/ethansbrown/acpc was outdated so we forked it and updated it with
# the latest version from http://www.computerpokercompetition.org/downloads/code/competition_server/project_acpc_server_v1.0.42.tar.bz2
DIR="open_spiel/games/universal_poker/acpc"
if [[ ${BUILD_WITH_ACPC:-"ON"} == "ON" ]] && [[ ! -d ${DIR} ]]; then
git clone -b 'master' --single-branch --depth 1 https://github.com/dennisjay/acpc.git ${DIR}
fi


# 2. Install other required system-wide dependencies
if [[ "$OSTYPE" == "linux-gnu" ]]; then
Expand Down
12 changes: 12 additions & 0 deletions open_spiel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ endif()
set (BUILD_WITH_HANABI $ENV{BUILD_WITH_HANABI})
message("${BoldYellow}BUILD_WITH_HANABI: ${BUILD_WITH_HANABI} ${ColourReset}")

set (BUILD_WITH_ACPC OFF CACHE BOOL "Build against the Universal Poker library.")
if(NOT DEFINED ENV{BUILD_WITH_ACPC})
message("${BoldRed}BUILD_WITH_ACPC not set. Defaults to OFF${ColourReset}")
set (ENV{BUILD_WITH_ACPC} OFF)
endif()
set (BUILD_WITH_ACPC $ENV{BUILD_WITH_ACPC})
message("${BoldYellow}BUILD_WITH_ACPC: ${BUILD_WITH_ACPC} ${ColourReset}")

##


Expand Down Expand Up @@ -121,6 +129,10 @@ set (OPEN_SPIEL_OBJECTS
if (BUILD_WITH_HANABI)
set(OPEN_SPIEL_OBJECTS ${OPEN_SPIEL_OBJECTS} $<TARGET_OBJECTS:hanabi_learning_environment>)
endif()
if (BUILD_WITH_ACPC)
set(OPEN_SPIEL_OBJECTS ${OPEN_SPIEL_OBJECTS} $<TARGET_OBJECTS:universal_poker_clib> $<TARGET_OBJECTS:universal_poker_lib>)
endif()


# We have the parent of this directory in the include path, so that we can
# include for example "open_spiel/spiel.h" (assuming this directory is named
Expand Down
245 changes: 245 additions & 0 deletions open_spiel/colabs/test_universal_poker.ipynb
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
}
15 changes: 14 additions & 1 deletion open_spiel/games/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ set(GAME_SOURCES
if (${BUILD_WITH_HANABI})
set(GAME_SOURCES ${GAME_SOURCES} hanabi.cc hanabi.h)
endif()
add_library (games OBJECT ${GAME_SOURCES})
if (${BUILD_WITH_ACPC})
set(GAME_SOURCES ${GAME_SOURCES} universal_poker.cc universal_poker.h)
endif()

add_library (games OBJECT ${GAME_SOURCES})

target_include_directories (games PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

if (${BUILD_WITH_HANABI})
add_subdirectory (hanabi)
endif()
if (${BUILD_WITH_ACPC})
add_subdirectory(universal_poker)
endif()

# Uncomment to build the Ludii demo
# add_subdirectory (ludii)
Expand Down Expand Up @@ -290,6 +296,13 @@ add_executable(tiny_hanabi_test tiny_hanabi_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:algorithms>)
add_test(tiny_hanabi_test tiny_hanabi_test)

if (${BUILD_WITH_ACPC})
add_executable(universal_poker_test universal_poker_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:tests>
$<TARGET_OBJECTS:algorithms>)
add_test(universal_poker_test.cc universal_poker_test)
endif()

add_executable(y_test y_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:tests>)
add_test(y_test y_test)

0 comments on commit 1adfccb

Please sign in to comment.