Created
October 17, 2017 08:26
-
-
Save drvinceknight/ff4d524ef60a525925947819cecf5d43 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import itertools # I'm going to use itertools just to get the full set of possible plays\n", | |
"import random # Just using this to randomly pick C or D for the purpose of the example\n", | |
"\n", | |
"import axelrod as axl\n", | |
"assert axl.__version__ == \"3.8.1\" # Just confirming the version this works for" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"We will use the `LookerUp` class:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"axelrod.strategies.lookerup.LookerUp" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"axl.LookerUp" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Let me build up the inputs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"C, D = axl.Action.C, axl.Action.D\n", | |
"player_histories = itertools.product((C, D), repeat=3)\n", | |
"opponent_histories = itertools.product((C, D), repeat=3)\n", | |
"both_histories = itertools.product(player_histories, opponent_histories)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"plays = [axl.lookerup.Plays(self_plays=self_plays, op_plays=op_plays, op_openings=()) \n", | |
" for self_plays, op_plays in both_histories]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"I'm going to create some random action for each set of plays." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{Plays(self_plays=(D, D, C), op_plays=(C, D, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(C, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(D, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(C, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(D, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(D, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(D, D, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(D, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(C, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(D, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(C, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(C, C, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(D, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(C, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(C, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(D, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(C, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(C, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(C, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(D, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(D, D, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(C, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(D, C, D), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(C, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(D, D, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(C, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(C, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(C, C, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(D, C, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(D, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(C, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, D, C), op_plays=(D, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(D, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(C, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(D, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(D, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(D, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(C, D, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(C, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(D, D, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(C, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(D, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(D, C, C), op_openings=()): C,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(D, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(D, C, D), op_plays=(D, D, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(C, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, D), op_plays=(C, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, C), op_plays=(C, C, D), op_openings=()): D,\n", | |
" Plays(self_plays=(C, C, D), op_plays=(C, D, C), op_openings=()): C,\n", | |
" Plays(self_plays=(D, C, C), op_plays=(C, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(D, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(D, C, C), op_openings=()): D,\n", | |
" Plays(self_plays=(C, D, C), op_plays=(D, C, D), op_openings=()): C,\n", | |
" Plays(self_plays=(D, D, D), op_plays=(C, D, D), op_openings=()): C}" | |
] | |
}, | |
"execution_count": 32, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"random.seed(0)\n", | |
"lookup_dict = {play: random.choice([C, D]) for play in plays}\n", | |
"lookup_dict" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"new_player = axl.LookerUp(lookup_dict=lookup_dict)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[(C, C),\n", | |
" (D, C),\n", | |
" (C, C),\n", | |
" (D, C),\n", | |
" (C, D),\n", | |
" (D, C),\n", | |
" (C, C),\n", | |
" (D, D),\n", | |
" (C, C),\n", | |
" (D, C)]" | |
] | |
}, | |
"execution_count": 34, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"match = axl.Match((axl.Alternator(), new_player), turns=10)\n", | |
"match.play()" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [conda root]", | |
"language": "python", | |
"name": "conda-root-py" | |
}, | |
"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.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment