Skip to content

Instantly share code, notes, and snippets.

@theref
Last active November 6, 2016 11:58
Show Gist options
  • Save theref/121dadfd5efb05a20af0dfdd7b73f1e3 to your computer and use it in GitHub Desktop.
Save theref/121dadfd5efb05a20af0dfdd7b73f1e3 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import random\n",
"import axelrod as axl"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.5377108697815238"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = random.random()\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[8, 6, 0, 7, 7, 0, 7, 0, 2, 4]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random.seed(a)\n",
"b = [random.randrange(10) for k in range(10)]\n",
"b"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[8, 6, 0, 7, 7, 0, 7, 0, 2, 4]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random.seed(a)\n",
"c = [random.randrange(10) for k in range(10)]\n",
"c"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.9975325860980032, 0.418264640562788, 0.5739864708065124, 0.743492113976725, 0.3785425110442352, 0.5106940489690212, 0.43726513642323783, 0.08062536089202466, 0.11723277252092867, 0.4391259006756808]\n",
"['C', 'D', 'C', 'C', 'D', 'C', 'C', 'D', 'C', 'C'] Win-Stay Lose-Shift\n",
"['C', 'D', 'C', 'C', 'D', 'C', 'C', 'D', 'C', 'C'] Win-Stay Lose-Shift\n",
"['C', 'C', 'D', 'D', 'C', 'C', 'D', 'D', 'C', 'C'] Dual Win-Stay Lose-Shift\n",
"['C', 'C', 'D', 'D', 'D', 'D', 'D', 'C', 'D', 'D'] Tit For Tat\n"
]
}
],
"source": [
"p1 = axl.WinStayLoseShift()\n",
"p2 = axl.strategy_transformers.DualTransformer()(axl.WinStayLoseShift)()\n",
"p4 = axl.TitForTat()\n",
"# get a random seed\n",
"seeds = [random.random() for k in range(10)]\n",
"print(seeds)\n",
"\n",
"p3 = axl.Random()\n",
"\n",
"for x in seeds:\n",
" random.seed(x)\n",
" p1.play(p3)\n",
"print(p3.history, p1)\n",
"\n",
"p3.reset()\n",
"for x in seeds:\n",
" random.seed(x)\n",
" p1.play(p3)\n",
"print(p3.history, p1)\n",
"p3.reset()\n",
"\n",
"for x in seeds:\n",
" random.seed(x)\n",
" p2.play(p3) \n",
"print(p3.history, p2)\n",
" \n",
"p3.reset()\n",
"for x in seeds:\n",
" random.seed(x)\n",
" p4.play(p3)\n",
"print(p3.history, p4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [Root]",
"language": "python",
"name": "Python [Root]"
},
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment