Created
August 8, 2017 15:40
-
-
Save drvinceknight/ab7d35d8235d4c46a979bcf633a9b5c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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": 1, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import axelrod as axl" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "titfortat = axl.TitForTat()\n", | |
| "alternator = axl.Alternator()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "match = axl.Match((titfortat, alternator), turns=10)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[(C, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, D)]" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "match.play()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(2.3, 2.8)" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "match.final_score_per_turn()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "random = axl.Random()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[(C, D),\n", | |
| " (D, D),\n", | |
| " (D, C),\n", | |
| " (C, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, D),\n", | |
| " (D, C),\n", | |
| " (C, C),\n", | |
| " (C, D)]" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "axl.seed(0)\n", | |
| "match = axl.Match((titfortat, random), turns=10)\n", | |
| "match.play()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(2.2, 2.7)" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "match.final_score_per_turn()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[(C, C),\n", | |
| " (C, D),\n", | |
| " (D, D),\n", | |
| " (D, C),\n", | |
| " (C, C),\n", | |
| " (C, C),\n", | |
| " (C, D),\n", | |
| " (D, D),\n", | |
| " (D, C),\n", | |
| " (C, C)]" | |
| ] | |
| }, | |
| "execution_count": 10, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "axl.seed(1)\n", | |
| "match = axl.Match((titfortat, random), turns=10)\n", | |
| "match.play()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(2.4, 2.4)" | |
| ] | |
| }, | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "match.final_score_per_turn()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 23, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "C, D = axl.Action.C, axl.Action.D\n", | |
| "\n", | |
| "class OurPlayer(axl.Player):\n", | |
| "\n", | |
| " def strategy(self, opponent):\n", | |
| " \"\"\"This is the actual strategy\"\"\"\n", | |
| " if len(self.history) == 0:\n", | |
| " return C\n", | |
| " if opponent.history == D:\n", | |
| " return self.history[-1]\n", | |
| " return D" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 25, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[(C, C),\n", | |
| " (D, C),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D),\n", | |
| " (D, D)]" | |
| ] | |
| }, | |
| "execution_count": 25, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "ourplayer = OurPlayer()\n", | |
| "match = axl.Match((ourplayer, titfortat), turns=10)\n", | |
| "match.play()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "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