From 42d3e63466e5ec85561e0d2a06c614f0ab42a80c Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 7 Dec 2014 12:21:55 +0000 Subject: [PATCH] Ignoring existing ipynb checkpoint files --- .../hangman-better-checkpoint.ipynb | 1221 ----------------- .../hangman-both-checkpoint.ipynb | 778 ----------- .../hangman-guesser-checkpoint.ipynb | 180 --- .../hangman-setter-checkpoint.ipynb | 9 - 4 files changed, 2188 deletions(-) delete mode 100644 .ipynb_checkpoints/hangman-better-checkpoint.ipynb delete mode 100644 .ipynb_checkpoints/hangman-both-checkpoint.ipynb delete mode 100644 .ipynb_checkpoints/hangman-guesser-checkpoint.ipynb delete mode 100644 .ipynb_checkpoints/hangman-setter-checkpoint.ipynb diff --git a/.ipynb_checkpoints/hangman-better-checkpoint.ipynb b/.ipynb_checkpoints/hangman-better-checkpoint.ipynb deleted file mode 100644 index 141a668..0000000 --- a/.ipynb_checkpoints/hangman-better-checkpoint.ipynb +++ /dev/null @@ -1,1221 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:e848b3bb14cbbc0d122596bd49c2e49d1d795881920f1f2a98206e14ff6b2b0a" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import re\n", - "import random\n", - "import string\n", - "import collections" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 27 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "WORDS = [w.strip() for w in open('/usr/share/dict/british-english').readlines() \n", - " if re.match(r'^[a-z]*$', w.strip())]" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "STARTING_LIVES = 10" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "class Game:\n", - " def __init__(self, target, player=None, lives=STARTING_LIVES):\n", - " self.lives = lives\n", - " self.player = player\n", - " self.target = target\n", - " self.discovered = list('_' * len(target))\n", - " self.wrong_letters = []\n", - " self.game_finished = False\n", - " self.game_won = False\n", - " self.game_lost = False\n", - " \n", - " def find_all(self, letter):\n", - " locations = []\n", - " starting=0\n", - " location = self.target.find(letter)\n", - " while location > -1:\n", - " locations += [location]\n", - " starting = location + 1\n", - " location = self.target.find(letter, starting)\n", - " return locations\n", - " \n", - " def update_discovered_word(self, guessed_letter):\n", - " locations = self.find_all(guessed_letter)\n", - " for location in locations:\n", - " self.discovered[location] = guessed_letter\n", - " return self.discovered\n", - " \n", - " def do_turn(self):\n", - " if self.player:\n", - " guess = self.player.guess(self.discovered, self.wrong_letters, self.lives)\n", - " else:\n", - " guess = self.ask_for_guess()\n", - " if guess in self.target:\n", - " self.update_discovered_word(guess)\n", - " else:\n", - " self.lives -= 1\n", - " if guess not in self.wrong_letters:\n", - " self.wrong_letters += [guess]\n", - " if self.lives == 0:\n", - " self.game_finished = True\n", - " self.game_lost = True\n", - " if '_' not in self.discovered:\n", - " self.game_finished = True\n", - " self.game_won = True\n", - " \n", - " def ask_for_guess(self):\n", - " print('Word:', ' '.join(self.discovered), \n", - " ' : Lives =', self.lives, \n", - " ', wrong guesses:', ' '.join(sorted(self.wrong_letters)))\n", - " guess = input('Enter letter: ').strip().lower()[0]\n", - " return guess\n", - " \n", - " def play_game(self):\n", - " self.do_turn()\n", - " while not self.game_finished:\n", - " self.do_turn()\n", - " if not self.player:\n", - " self.report_on_game()\n", - " return self.game_won\n", - " \n", - " def report_on_game(self):\n", - " if self.game_won:\n", - " print('You won! The word was', self.target)\n", - " else:\n", - " print('You lost. The word was', self.target)\n", - " return self.game_won" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 24 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS))" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 6 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.target" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 7, - "text": [ - "'gastronomy'" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 8, - "text": [ - "['_', '_', '_', '_', '_', '_', '_', '_', '_', '_']" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.do_turn()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: e\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.lives" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 10, - "text": [ - "9" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.wrong_letters" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 11, - "text": [ - "['e']" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.do_turn()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ _ _ : Lives = 9 , wrong guesses: e\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: a\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.lives" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 13, - "text": [ - "9" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 14, - "text": [ - "['_', 'a', '_', '_', '_', '_', '_', '_', '_', '_']" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.wrong_letters" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 15, - "text": [ - "['e']" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS))\n", - "g.play_game()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: e\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ : Lives = 9 , wrong guesses: e\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: a\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ _ _ : Lives = 9 , wrong guesses: e\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: t\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ _ _ : Lives = 8 , wrong guesses: e t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: i\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ _ _ : Lives = 7 , wrong guesses: e i t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: o\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 7 , wrong guesses: e i t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: s\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 6 , wrong guesses: e i s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: n\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 5 , wrong guesses: e i n s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: h\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 4 , wrong guesses: e h i n s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: r\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 3 , wrong guesses: e h i n r s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: d\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a _ _ o _ : Lives = 2 , wrong guesses: d e h i n r s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: l\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a l l o _ : Lives = 2 , wrong guesses: d e h i n r s t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: y\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: a l l o _ : Lives = 1 , wrong guesses: d e h i n r s t y\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: w\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "You won! The word was allow\n" - ] - }, - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 16, - "text": [ - "True" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS))\n", - "g.play_game()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: e\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: a\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e _ _ _ : Lives = 9 , wrong guesses: a\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: i\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e i _ _ : Lives = 9 , wrong guesses: a\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: n\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e i n _ : Lives = 9 , wrong guesses: a\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: g\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e i n g : Lives = 9 , wrong guesses: a\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: u\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ e e i n g : Lives = 8 , wrong guesses: a u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: s\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ _ e e i n g : Lives = 8 , wrong guesses: a u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: h\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ _ e e i n g : Lives = 7 , wrong guesses: a h u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: c\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ _ e e i n g : Lives = 6 , wrong guesses: a c h u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: t\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ _ e e i n g : Lives = 5 , wrong guesses: a c h t u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: r\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ r e e i n g : Lives = 5 , wrong guesses: a c h t u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: c\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: s _ r e e i n g : Lives = 4 , wrong guesses: a c h t u\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: p\n" - ] - }, - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 38, - "text": [ - "True" - ] - } - ], - "prompt_number": 38 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.target" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 39, - "text": [ - "'spreeing'" - ] - } - ], - "prompt_number": 39 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "class PlayerAlphabetical:\n", - " def guess(self, discovered, missed, lives):\n", - " guessed_letters = [l.lower() for l in discovered + missed if l in string.ascii_letters]\n", - " return self.ordered_subtract(string.ascii_lowercase, guessed_letters)[0]\n", - " \n", - " def ordered_subtract(self, ordered_list, to_remove):\n", - " for r in to_remove:\n", - " if r in ordered_list:\n", - " ri = ordered_list.index(r)\n", - " ordered_list = ordered_list[:ri] + ordered_list[ri+1:]\n", - " return ordered_list" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 43 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerAlphabetical())" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 44 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.play_game()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 45, - "text": [ - "False" - ] - } - ], - "prompt_number": 45 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 46, - "text": [ - "['d', 'e', '_', 'i', 'a', 'n', '_', '_']" - ] - } - ], - "prompt_number": 46 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.target" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 47, - "text": [ - "'deviants'" - ] - } - ], - "prompt_number": 47 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerAlphabetical())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: peoples ; Discovered: ['_', 'e', '_', '_', '_', 'e', '_'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 54 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "LETTER_COUNTS = collections.Counter(l.lower() for l in open('sherlock-holmes.txt').read() if l in string.ascii_letters)\n", - "LETTERS_IN_ORDER = [p[0] for p in LETTER_COUNTS.most_common()]\n", - "\n", - "class PlayerFreqOrdered:\n", - " def guess(self, discovered, missed, lives):\n", - " guessed_letters = [l.lower() for l in discovered + missed if l in string.ascii_letters]\n", - " return self.ordered_subtract(LETTERS_IN_ORDER, guessed_letters)[0]\n", - " \n", - " def ordered_subtract(self, ordered_list, to_remove):\n", - " for r in to_remove:\n", - " if r in ordered_list:\n", - " ri = ordered_list.index(r)\n", - " ordered_list = ordered_list[:ri] + ordered_list[ri+1:]\n", - " return ordered_list" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 55 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: wadding ; Discovered: ['w', 'a', 'd', 'd', 'i', 'n', '_'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 56 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: pharmacopoeias ; Discovered: ['p', 'h', 'a', 'r', 'm', 'a', 'c', 'o', 'p', 'o', 'e', 'i', 'a', 's'] ; Lives remaining: 1\n" - ] - } - ], - "prompt_number": 57 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: forklift ; Discovered: ['_', 'o', 'r', '_', 'l', 'i', '_', 't'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 58 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "class PlayerFixedOrder:\n", - " def __init__(self, ordered_letters):\n", - " self.ordered_letters = ordered_letters\n", - " \n", - " def guess(self, discovered, missed, lives):\n", - " guessed_letters = [l.lower() for l in discovered + missed if l in string.ascii_letters]\n", - " self.ordered_subtract(guessed_letters)\n", - " return self.ordered_letters[0]\n", - "\n", - " def ordered_subtract(self, to_remove):\n", - " for r in to_remove:\n", - " if r in self.ordered_letters:\n", - " ri = self.ordered_letters.index(r)\n", - " self.ordered_letters = self.ordered_letters[:ri] + self.ordered_letters[ri+1:]" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 65 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "class PlayerAlphabetical(PlayerFixedOrder):\n", - " def __init__(self):\n", - " super().__init__(string.ascii_lowercase)\n", - "\n", - "class PlayerFreqOrdered(PlayerFixedOrder):\n", - " def __init__(self):\n", - " super().__init__(LETTERS_IN_ORDER)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 66 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: nods ; Discovered: ['n', 'o', 'd', 's'] ; Lives remaining: 4\n" - ] - } - ], - "prompt_number": 67 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: firsthand ; Discovered: ['f', 'i', 'r', 's', 't', 'h', 'a', 'n', 'd'] ; Lives remaining: 2\n" - ] - } - ], - "prompt_number": 68 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerAlphabetical())\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: lawbreakers ; Discovered: ['l', 'a', '_', 'b', '_', 'e', 'a', 'k', 'e', '_', '_'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 69 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFixedOrder(list(reversed(string.ascii_lowercase))))\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: chilblains ; Discovered: ['_', '_', '_', '_', '_', '_', '_', '_', '_', 's'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 74 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS), player=PlayerFixedOrder(list(reversed(string.ascii_lowercase))))\n", - "g.play_game()\n", - "print('Target:', g.target, '; Discovered:', g.discovered, '; Lives remaining:', g.lives)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Target: talks ; Discovered: ['t', '_', '_', '_', 's'] ; Lives remaining: 0\n" - ] - } - ], - "prompt_number": 75 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "wins = 0\n", - "for _ in range(1000):\n", - " g = Game(random.choice(WORDS), player=PlayerAlphabetical())\n", - " g.play_game()\n", - " if g.game_won:\n", - " wins += 1\n", - "print(wins)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "42\n" - ] - } - ], - "prompt_number": 77 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "wins = 0\n", - "for _ in range(1000):\n", - " g = Game(random.choice(WORDS), player=PlayerFreqOrdered())\n", - " g.play_game()\n", - " if g.game_won:\n", - " wins += 1\n", - "print(wins)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "319\n" - ] - } - ], - "prompt_number": 78 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "wins = 0\n", - "for _ in range(1000):\n", - " g = Game(random.choice(WORDS), player=PlayerFixedOrder(list(reversed(string.ascii_lowercase))))\n", - " g.play_game()\n", - " if g.game_won:\n", - " wins += 1\n", - "print(wins)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - } - ], - "prompt_number": 80 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/.ipynb_checkpoints/hangman-both-checkpoint.ipynb b/.ipynb_checkpoints/hangman-both-checkpoint.ipynb deleted file mode 100644 index 532998b..0000000 --- a/.ipynb_checkpoints/hangman-both-checkpoint.ipynb +++ /dev/null @@ -1,778 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:3fd62f8c6cf4619b87bb367305e68080edd846095261b09f98699554a3e60841" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import re\n", - "import random" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "WORDS = [w.strip() for w in open('/usr/share/dict/british-english').readlines() \n", - " if re.match(r'^[a-z]*$', w.strip())]" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "STARTING_LIVES = 10\n", - "lives = 0" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "wrong_letters = []" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "len(WORDS)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 5, - "text": [ - "62856" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "WORDS[30000:30010]" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 6, - "text": [ - "['jotted',\n", - " 'jotting',\n", - " 'jottings',\n", - " 'joule',\n", - " 'joules',\n", - " 'jounce',\n", - " 'jounced',\n", - " 'jounces',\n", - " 'jouncing',\n", - " 'journal']" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "target = random.choice(WORDS)\n", - "target" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 14, - "text": [ - "'rebounds'" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "discovered = list('_' * len(target))\n", - "discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 8, - "text": [ - "['_', '_', '_', '_', '_', '_']" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "letter = input('Enter letter: ').strip().lower()[0]\n", - "letter" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: sdfsdfs\n" - ] - }, - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 9, - "text": [ - "'s'" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def find_all(string, letter):\n", - " locations = []\n", - " starting=0\n", - " location = string.find(letter)\n", - " while location > -1:\n", - " locations += [location]\n", - " starting = location + 1\n", - " location = string.find(letter, starting)\n", - " return locations" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 11 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "find_all('happy', 'q')" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 12, - "text": [ - "[]" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "guessed_letter = 'e'\n", - "locations = find_all(target, guessed_letter)\n", - "for location in locations:\n", - " discovered[location] = guessed_letter\n", - "discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 15, - "text": [ - "['_', 'e', '_', '_', '_', '_']" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def updated_discovered_word(discovered, guessed_letter):\n", - " locations = find_all(target, guessed_letter)\n", - " for location in locations:\n", - " discovered[location] = guessed_letter\n", - " return discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 18 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def initialise():\n", - " global lives, target, discovered, wrong_letters\n", - " lives = STARTING_LIVES\n", - " target = random.choice(WORDS)\n", - " discovered = list('_' * len(target))\n", - " wrong_letters = []" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 19 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def do_turn():\n", - " global discovered, lives, wrong_letters\n", - " print('Word:', ' '.join(discovered), ' : Lives =', lives, ', wrong guesses:', ' '.join(sorted(wrong_letters)))\n", - " guess = input('Enter letter: ').strip().lower()[0]\n", - " if guess in target:\n", - " updated_discovered_word(discovered, guess)\n", - " else:\n", - " lives -= 1\n", - " if guess not in wrong_letters:\n", - " wrong_letters += [guess]" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 27 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def play_game():\n", - " global discovered, lives\n", - " initialise()\n", - " game_finished = False\n", - " do_turn()\n", - " while not game_finished:\n", - " if '_' not in discovered:\n", - " print('You won! The word was', target)\n", - " game_finished = True\n", - " elif lives <= 0:\n", - " print('You lost. The word was', target)\n", - " game_finished = True\n", - " else:\n", - " do_turn()" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 25 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "play_game()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: e\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e _ _ _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: a\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e _ _ a _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: i\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e _ _ a _ _ _ _ _ i _ i _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: o\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e _ _ a _ _ _ o _ i _ i _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: t\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e _ _ a _ _ _ o _ i t i _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: r\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: n\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 9 , wrong guesses: n\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: s\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: h\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: h e r _ a _ h r o _ i t i _ : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: c\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: h e r _ a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: c\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: h e r _ a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: m\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: h e r m a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: p\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: h e r m a p h r o _ i t i c : Lives = 8 , wrong guesses: n s\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: d\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "You won! The word was hermaphroditic\n" - ] - } - ], - "prompt_number": 30 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "class Game:\n", - " def __init__(self, target, lives=STARTING_LIVES):\n", - " self.lives = lives\n", - " self.target = target\n", - " self.discovered = list('_' * len(target))\n", - " self.wrong_letters = []\n", - " self.game_finished = False\n", - " self.game_won = False\n", - " self.game_lost = False\n", - " \n", - " def find_all(self, letter):\n", - " locations = []\n", - " starting=0\n", - " location = self.target.find(letter)\n", - " while location > -1:\n", - " locations += [location]\n", - " starting = location + 1\n", - " location = self.target.find(letter, starting)\n", - " return locations\n", - " \n", - " def updated_discovered_word(self, guessed_letter):\n", - " locations = find_all(guessed_letter)\n", - " for location in locations:\n", - " self.discovered[location] = guessed_letter\n", - " return self.discovered\n", - " \n", - " def do_turn(self):\n", - " print('Word:', ' '.join(self.discovered), \n", - " ' : Lives =', self.lives, \n", - " ', wrong guesses:', ' '.join(sorted(self.wrong_letters)))\n", - " guess = input('Enter letter: ').strip().lower()[0]\n", - " if guess in self.target:\n", - " updated_discovered_word(self, guess)\n", - " else:\n", - " self.lives -= 1\n", - " if guess not in self.wrong_letters:\n", - " self.wrong_letters += [guess]\n", - " if self.lives == 0:\n", - " self.game_finished = True\n", - " self.game_lost = True\n", - " if '_' not in self.discovered:\n", - " self.game_finished = True\n", - " self.game_won = True\n", - " \n", - " def play_game(self):\n", - " do_turn()\n", - " while not self.game_finished:\n", - " if self.game_won:\n", - " print('You won! The word was', self.target)\n", - " elif self.game_lost:\n", - " print('You lost. The word was', self.target)\n", - " else:\n", - " do_turn()\n", - " return self.game_won" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 47 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g = Game(random.choice(WORDS))" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 48 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.target" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 49, - "text": [ - "'paintbrush'" - ] - } - ], - "prompt_number": 49 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.discovered" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 50, - "text": [ - "['_', '_', '_', '_', '_', '_', '_', '_', '_', '_']" - ] - } - ], - "prompt_number": 50 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.do_turn()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: x\n" - ] - } - ], - "prompt_number": 51 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.lives" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 52, - "text": [ - "9" - ] - } - ], - "prompt_number": 52 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.wrong_letters" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 53, - "text": [ - "['x']" - ] - } - ], - "prompt_number": 53 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "g.do_turn()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Word: _ _ _ _ _ _ _ _ _ _ : Lives = 9 , wrong guesses: x\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter letter: t\n" - ] - }, - { - "ename": "TypeError", - "evalue": "'Game' object does not support item assignment", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdo_turn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36mdo_turn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 31\u001b[0m \u001b[0mguess\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Enter letter: '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mguess\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtarget\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 33\u001b[1;33m \u001b[0mupdated_discovered_word\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mguess\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 34\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 35\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlives\u001b[0m \u001b[1;33m-=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36mupdated_discovered_word\u001b[1;34m(discovered, guessed_letter)\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mlocations\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfind_all\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtarget\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mguessed_letter\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mlocation\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mlocations\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mdiscovered\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mlocation\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mguessed_letter\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mdiscovered\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mTypeError\u001b[0m: 'Game' object does not support item assignment" - ] - } - ], - "prompt_number": 54 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/.ipynb_checkpoints/hangman-guesser-checkpoint.ipynb b/.ipynb_checkpoints/hangman-guesser-checkpoint.ipynb deleted file mode 100644 index 1dd623b..0000000 --- a/.ipynb_checkpoints/hangman-guesser-checkpoint.ipynb +++ /dev/null @@ -1,180 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:576842385a8db766a7dd158b6bf837c2e7ee16dd3fc6409d40e92cc57bfaacb3" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import string\n", - "import collections" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "letter_counts = collections.Counter(l.lower() for l in open('sherlock-holmes.txt').read() if l in string.ascii_letters)\n", - "letter_counts" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 4, - "text": [ - "Counter({'e': 53111, 't': 38981, 'a': 35137, 'o': 33512, 'i': 30140, 'h': 29047, 'n': 28682, 's': 27194, 'r': 24508, 'd': 18563, 'l': 17145, 'u': 13116, 'm': 11787, 'w': 11266, 'c': 10499, 'y': 9431, 'f': 8975, 'g': 7887, 'p': 6835, 'b': 6362, 'v': 4452, 'k': 3543, 'x': 549, 'j': 452, 'q': 426, 'z': 149})" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "letters_in_order = [p[0] for p in letter_counts.most_common()]\n", - "letters_in_order" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 9, - "text": [ - "['e',\n", - " 't',\n", - " 'a',\n", - " 'o',\n", - " 'i',\n", - " 'h',\n", - " 'n',\n", - " 's',\n", - " 'r',\n", - " 'd',\n", - " 'l',\n", - " 'u',\n", - " 'm',\n", - " 'w',\n", - " 'c',\n", - " 'y',\n", - " 'f',\n", - " 'g',\n", - " 'p',\n", - " 'b',\n", - " 'v',\n", - " 'k',\n", - " 'x',\n", - " 'j',\n", - " 'q',\n", - " 'z']" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def read_game():\n", - " discovered = input('Enter the discovered word: ')\n", - " missed = input('Enter the wrong guesses: ')\n", - " guessed_letters = [l.lower() for l in discovered + missed if l in string.ascii_letters]\n", - " unguessed_letters_in_order = ordered_subtract(letters_in_order, guessed_letters)\n", - " print('My guess is:', unguessed_letters_in_order[0])" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 10 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def ordered_subtract(ordered_list, to_remove):\n", - " for r in to_remove:\n", - " if r in ordered_list:\n", - " ordered_list.remove(r)\n", - " return ordered" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 13 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "letters_in_order" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 12, - "text": [ - "['e',\n", - " 't',\n", - " 'a',\n", - " 'o',\n", - " 'i',\n", - " 'h',\n", - " 'n',\n", - " 's',\n", - " 'r',\n", - " 'd',\n", - " 'l',\n", - " 'u',\n", - " 'm',\n", - " 'w',\n", - " 'c',\n", - " 'y',\n", - " 'f',\n", - " 'g',\n", - " 'p',\n", - " 'b',\n", - " 'v',\n", - " 'k',\n", - " 'x',\n", - " 'j',\n", - " 'q',\n", - " 'z']" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "ordered_subtract(letters_in_order, ['etaoin'])" - ], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/.ipynb_checkpoints/hangman-setter-checkpoint.ipynb b/.ipynb_checkpoints/hangman-setter-checkpoint.ipynb deleted file mode 100644 index 6d3684e..0000000 --- a/.ipynb_checkpoints/hangman-setter-checkpoint.ipynb +++ /dev/null @@ -1,9 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:0b98cca3e07675475eac1f4392386d85d54a09969d7a15a459759e6560551a0d" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [] -} \ No newline at end of file -- 2.34.1