|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
| 5 | + "id": "fcb19ba2", |
5 | 6 | "metadata": {}, |
6 | 7 | "source": [ |
7 | 8 | "# Using Gambit with OpenSpiel\n", |
|
26 | 27 | }, |
27 | 28 | { |
28 | 29 | "cell_type": "code", |
29 | | - "execution_count": 1, |
| 30 | + "execution_count": null, |
30 | 31 | "id": "ebb78322", |
31 | 32 | "metadata": {}, |
32 | 33 | "outputs": [], |
33 | 34 | "source": [ |
34 | 35 | "from io import StringIO\n", |
35 | | - "import numpy as np\n", |
36 | | - "import matplotlib.pyplot as plt\n", |
37 | 36 | "\n", |
| 37 | + "import matplotlib.pyplot as plt\n", |
| 38 | + "import numpy as np\n", |
| 39 | + "import pyspiel\n", |
38 | 40 | "from open_spiel.python import rl_environment\n", |
39 | 41 | "from open_spiel.python.algorithms import tabular_qlearner\n", |
40 | 42 | "from open_spiel.python.algorithms.gambit import export_gambit\n", |
41 | 43 | "from open_spiel.python.egt import dynamics\n", |
42 | 44 | "from open_spiel.python.egt.utils import game_payoffs_array\n", |
43 | 45 | "\n", |
44 | | - "import pyspiel\n", |
45 | | - "\n", |
46 | 46 | "import pygambit as gbt" |
47 | 47 | ] |
48 | 48 | }, |
|
89 | 89 | { |
90 | 90 | "cell_type": "code", |
91 | 91 | "execution_count": 3, |
| 92 | + "id": "1d51af0a", |
92 | 93 | "metadata": {}, |
93 | 94 | "outputs": [], |
94 | 95 | "source": [ |
|
351 | 352 | }, |
352 | 353 | { |
353 | 354 | "cell_type": "code", |
354 | | - "execution_count": 11, |
| 355 | + "execution_count": null, |
355 | 356 | "id": "b9a352c5", |
356 | 357 | "metadata": {}, |
357 | 358 | "outputs": [ |
|
379 | 380 | " paper_proportions.append(x[1])\n", |
380 | 381 | " scissors_proportions.append(x[2])\n", |
381 | 382 | " if plot_average_strategy:\n", |
382 | | - " y.append([np.mean(rock_proportions), np.mean(paper_proportions), np.mean(scissors_proportions)])\n", |
| 383 | + " y.append([np.mean(rock_proportions),\n", |
| 384 | + " np.mean(paper_proportions),\n", |
| 385 | + " np.mean(scissors_proportions)\n", |
| 386 | + " ])\n", |
383 | 387 | " else:\n", |
384 | 388 | " y.append(x.copy())\n", |
385 | 389 | " y = np.array(y)\n", |
|
640 | 644 | }, |
641 | 645 | { |
642 | 646 | "cell_type": "markdown", |
| 647 | + "id": "9926fb07", |
643 | 648 | "metadata": {}, |
644 | 649 | "source": [ |
645 | 650 | "<!-- ## Extensive-form example: Silly1111 Poker -->\n", |
|
721 | 726 | }, |
722 | 727 | { |
723 | 728 | "cell_type": "code", |
724 | | - "execution_count": 21, |
| 729 | + "execution_count": null, |
725 | 730 | "id": "1ec19b1c", |
726 | 731 | "metadata": {}, |
727 | 732 | "outputs": [ |
|
740 | 745 | } |
741 | 746 | ], |
742 | 747 | "source": [ |
743 | | - "eqm['Pl0']" |
| 748 | + "eqm[\"Pl0\"]" |
744 | 749 | ] |
745 | 750 | }, |
746 | 751 | { |
|
786 | 791 | }, |
787 | 792 | { |
788 | 793 | "cell_type": "code", |
789 | | - "execution_count": 23, |
| 794 | + "execution_count": null, |
790 | 795 | "id": "8528e1bd", |
791 | 796 | "metadata": {}, |
792 | 797 | "outputs": [ |
|
805 | 810 | } |
806 | 811 | ], |
807 | 812 | "source": [ |
808 | | - "eqm['Pl1']" |
| 813 | + "eqm[\"Pl1\"]" |
809 | 814 | ] |
810 | 815 | }, |
811 | 816 | { |
|
983 | 988 | }, |
984 | 989 | { |
985 | 990 | "cell_type": "code", |
986 | | - "execution_count": 47, |
| 991 | + "execution_count": null, |
987 | 992 | "id": "77dc34c8", |
988 | 993 | "metadata": {}, |
989 | 994 | "outputs": [], |
|
1007 | 1012 | " )\n", |
1008 | 1013 | "\n", |
1009 | 1014 | "gbt_one_card_poker.append_move(\n", |
1010 | | - " [gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"], gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"]],\n", |
| 1015 | + " [\n", |
| 1016 | + " gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"],\n", |
| 1017 | + " gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"]\n", |
| 1018 | + " ],\n", |
1011 | 1019 | " player=\"Bob\",\n", |
1012 | 1020 | " actions=[\"Call\", \"Fold\"]\n", |
1013 | 1021 | ")\n", |
|
1018 | 1026 | "lose = gbt_one_card_poker.add_outcome([-1, 1], label=\"Lose\")\n", |
1019 | 1027 | "\n", |
1020 | 1028 | "# Alice folds, Bob wins small\n", |
1021 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"King\"].children[\"Fold\"], lose)\n", |
1022 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"Queen\"].children[\"Fold\"], lose)\n", |
| 1029 | + "gbt_one_card_poker.set_outcome(\n", |
| 1030 | + " gbt_one_card_poker.root.children[\"King\"].children[\"Fold\"],\n", |
| 1031 | + " lose\n", |
| 1032 | + ")\n", |
| 1033 | + "gbt_one_card_poker.set_outcome(\n", |
| 1034 | + " gbt_one_card_poker.root.children[\"Queen\"].children[\"Fold\"],\n", |
| 1035 | + " lose\n", |
| 1036 | + ")\n", |
| 1037 | + "\n", |
1023 | 1038 | "# Bob sees Alice Bet and calls, correctly believing she is bluffing, Bob wins big\n", |
1024 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"].children[\"Call\"], lose_big)\n", |
| 1039 | + "gbt_one_card_poker.set_outcome(\n", |
| 1040 | + " gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"].children[\"Call\"],\n", |
| 1041 | + " lose_big\n", |
| 1042 | + ")\n", |
1025 | 1043 | "\n", |
1026 | 1044 | "# Bob sees Alice Bet and calls, incorrectly believing she is bluffing, Alice wins big\n", |
1027 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"].children[\"Call\"], win_big)\n", |
| 1045 | + "gbt_one_card_poker.set_outcome(\n", |
| 1046 | + " gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"].children[\"Call\"],\n", |
| 1047 | + " win_big\n", |
| 1048 | + ")\n", |
1028 | 1049 | "\n", |
1029 | 1050 | "# Bob does not call Alice's Bet, Alice wins small\n", |
1030 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"].children[\"Fold\"], win)\n", |
1031 | | - "gbt_one_card_poker.set_outcome(gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"].children[\"Fold\"], win)" |
| 1051 | + "gbt_one_card_poker.set_outcome(\n", |
| 1052 | + " gbt_one_card_poker.root.children[\"King\"].children[\"Bet\"].children[\"Fold\"],\n", |
| 1053 | + " win\n", |
| 1054 | + ")\n", |
| 1055 | + "gbt_one_card_poker.set_outcome(\n", |
| 1056 | + " gbt_one_card_poker.root.children[\"Queen\"].children[\"Bet\"].children[\"Fold\"],\n", |
| 1057 | + " win\n", |
| 1058 | + ")" |
1032 | 1059 | ] |
1033 | 1060 | }, |
1034 | 1061 | { |
|
0 commit comments