diff --git a/agents.ipynb b/agents.ipynb index ee6807c1d..e6e185e06 100644 --- a/agents.ipynb +++ b/agents.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/csp.ipynb b/csp.ipynb index d82e1a6fd..0d2aa513a 100644 --- a/csp.ipynb +++ b/csp.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/games.ipynb b/games.ipynb index ab333022a..3aec144ab 100644 --- a/games.ipynb +++ b/games.ipynb @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "collapsed": true }, @@ -208,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "collapsed": false }, @@ -227,44 +227,22 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "'a2'" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "random_player(game52, 'A')" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "'a1'" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "random_player(game52, 'A')" ] @@ -278,21 +256,11 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a1\n", - "b1\n", - "c1\n" - ] - } - ], + "outputs": [], "source": [ "print( alphabeta_player(game52, 'A') )\n", "print( alphabeta_player(game52, 'B') )\n", @@ -308,44 +276,22 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "'a1'" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "minimax_decision('A', game52)" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "'a1'" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "alphabeta_full_search('A', game52)" ] @@ -359,9 +305,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { - "collapsed": true + "collapsed": false }, "outputs": [], "source": [ @@ -377,21 +323,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ". . . \n", - ". . . \n", - ". . . \n" - ] - } - ], + "outputs": [], "source": [ "ttt.display(ttt.initial)" ] @@ -407,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "collapsed": false }, @@ -433,21 +369,11 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "X O X \n", - "O . O \n", - "X . . \n" - ] - } - ], + "outputs": [], "source": [ "ttt.display(my_state)" ] @@ -461,44 +387,22 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "(3, 3)" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "random_player(ttt, my_state)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "(2, 2)" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "random_player(ttt, my_state)" ] @@ -512,22 +416,11 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "(2, 2)" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "alphabeta_player(ttt, my_state)" ] @@ -541,22 +434,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(ttt, alphabeta_player, random_player)" ] @@ -572,28 +454,11 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "0\n", - "0\n", - "0\n", - "0\n", - "0\n", - "0\n", - "0\n", - "0\n", - "0\n" - ] - } - ], + "outputs": [], "source": [ "for _ in range(10):\n", " print(play_game(ttt, alphabeta_player, alphabeta_player))" @@ -608,28 +473,11 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-1\n", - "-1\n", - "-1\n", - "0\n", - "-1\n", - "0\n", - "-1\n", - "0\n", - "-1\n", - "-1\n" - ] - } - ], + "outputs": [], "source": [ "for _ in range(10):\n", " print(play_game(ttt, random_player, alphabeta_player))" @@ -644,40 +492,11 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ". . . \n", - ". . . \n", - ". . . \n", - "Your move? (3,1)\n", - ". . . \n", - ". . O \n", - "X . . \n", - "Your move? (2,2)\n", - ". . . \n", - ". X O \n", - "X O . \n", - "Your move? (1,3)\n" - ] - }, - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(ttt, query_player, random_player)" ] @@ -691,48 +510,11 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ". . . \n", - ". . . \n", - ". . . \n", - "Your move? (1,1)\n", - "X . . \n", - ". O . \n", - ". . . \n", - "Your move? (3,3)\n", - "X O . \n", - ". O . \n", - ". . X \n", - "Your move? (3,2)\n", - "X O . \n", - ". O . \n", - "O X X \n", - "Your move? (1,3)\n", - "X O X \n", - ". O O \n", - "O X X \n", - "Your move? (2,1)\n" - ] - }, - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(ttt, query_player, alphabeta_player)" ] @@ -746,104 +528,44 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(game52, alphabeta_player, alphabeta_player)" ] }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "8" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(game52, alphabeta_player, random_player)" ] }, { "cell_type": "code", - "execution_count": 59, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "A\n", - "Your move? a3\n" - ] - }, - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(game52, query_player, alphabeta_player)" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "B\n", - "Your move? b2\n" - ] - }, - { - "data": { - "text/plain": [ - "12" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "play_game(game52, alphabeta_player, query_player)" ] @@ -872,7 +594,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.4" + "version": "3.5.1" } }, "nbformat": 4, diff --git a/games.py b/games.py index ba842e2f5..689caaa27 100644 --- a/games.py +++ b/games.py @@ -135,7 +135,7 @@ def min_value(state, alpha, beta, depth): def query_player(game, state): "Make a move by querying standard input." - game.display(state) + # game.display(state) move_string = input('Your move? ') try: move = eval(move_string) @@ -157,11 +157,18 @@ def play_game(game, *players): """Play an n-person, move-alternating game.""" state = game.initial + print("Initial state:") + game.display(state) while True: for player in players: move = player(game, state) state = game.result(state, move) + print("State after %s's move:" % player.__name__) + game.display(state) if game.terminal_test(state): + print("\nGame's over!") + print("Final state:") + game.display(state) return game.utility(state, game.to_move(game.initial)) # ______________________________________________________________________________ diff --git a/grid.ipynb b/grid.ipynb index fe4e11a77..4e3bbd7e5 100644 --- a/grid.ipynb +++ b/grid.ipynb @@ -2,19 +2,11 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "25\n" - ] - } - ], + "outputs": [], "source": [ "import grid\n", "\n", diff --git a/intro.ipynb b/intro.ipynb index 1b2b3663c..ce9020e95 100644 --- a/intro.ipynb +++ b/intro.ipynb @@ -55,7 +55,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.4" + "version": "3.5.1" } }, "nbformat": 4, diff --git a/learning.ipynb b/learning.ipynb index 90d7746f7..4798f2914 100644 --- a/learning.ipynb +++ b/learning.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/logic.ipynb b/logic.ipynb index a3f85d38b..79595ac5d 100644 --- a/logic.ipynb +++ b/logic.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/logic.py b/logic.py index 74f7f5589..7b196db3e 100644 --- a/logic.py +++ b/logic.py @@ -56,7 +56,7 @@ def tell(self, sentence): def ask(self, query): """Return a substitution that makes the query true, or, failing that, return False.""" - for first(self.ask_generator(query), default=False) + return first(self.ask_generator(query), default=False) def ask_generator(self, query): "Yield all the substitutions that make query true." diff --git a/mdp.ipynb b/mdp.ipynb index d40f6030c..ed0bd9783 100644 --- a/mdp.ipynb +++ b/mdp.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/nlp.ipynb b/nlp.ipynb index 70bf2d974..1a2da9488 100644 --- a/nlp.ipynb +++ b/nlp.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/planning.ipynb b/planning.ipynb index 0c04c559b..d5a5eb25d 100644 --- a/planning.ipynb +++ b/planning.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/probability.ipynb b/probability.ipynb index 48de9e035..446fc11fb 100644 --- a/probability.ipynb +++ b/probability.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/rl.ipynb b/rl.ipynb index d68ea9693..005e7b7f9 100644 --- a/rl.ipynb +++ b/rl.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false }, diff --git a/search.ipynb b/search.ipynb index fb76f5ff4..18b22c045 100644 --- a/search.ipynb +++ b/search.ipynb @@ -39,7 +39,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "collapsed": false }, @@ -81,7 +81,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "collapsed": true }, @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "collapsed": false }, @@ -149,22 +149,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "['Cat', 'Monkey']" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "bfs_node = breadth_first_search(monkey_problem)\n", "bfs_node.solution()" @@ -193,22 +182,11 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "['Dog', 'Bear', 'Monkey']" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "ucs_node = uniform_cost_search(monkey_problem)\n", "ucs_node.solution()" @@ -223,22 +201,11 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "(18, 17)" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "bfs_node.path_cost, ucs_node.path_cost" ] @@ -267,7 +234,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.1" } }, "nbformat": 4, diff --git a/text.ipynb b/text.ipynb index a7b29bc44..37e4d0b63 100644 --- a/text.ipynb +++ b/text.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": false },