{"action":"created","comment":{"url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/comments/186600172","pull_request_review_id":118209378,"id":186600172,"diff_hunk":"@@ -0,0 +1,377 @@\n+-- |\n+-- Module: Exercises\n+--\n+-- = Exercise 1\n+-- Using the function @gametree@, verify that there are 549,946 nodes\n+-- in the complete game tree for a 3 x 3 tic-tac-toe game starting from\n+-- the empty grid, and that the maximum depth of this tree is 9.\n+--\n+-- == Answer\n+-- See the spec file\n+--\n+-- = Exercise 2\n+-- Our tic-tac-toe program always chooses the first move from the list\n+-- of best moves. Modify the final program to choose a random move from\n+-- the list of best moves, using the funciton @randomRIO :: (Int,Int) -> Io Int@\n+-- from @System.Random@ to generate a random integer in the given range.\n+--\n+-- = Exercise 3\n+-- Alternatively, modify the final program to choose a move\n+-- that attempts to take the quickest route to a win, by calculating the depths\n+-- of resulting game trees and selecting a move that results in a tree\n+-- with the smallest depth.\n+--\n+-- = Exercise 4\n+-- Modify the final program to:\n+--\n+-- * let the user decide if they wish to\n+-- * allow the length of a winning line to also be changed;\n+-- * generate the game tree once, rather than for each move;\n+-- * reduce the size of game tree using alpha-beta prunning.\n+\n+module Exercises\n+  ( -- * Exercise 2\n+    bestmove2\n+  , play2\n+  , play2'\n+  , tictactoeNPC2\n+    -- * Exercise 3\n+  , bestmove3\n+  , minV\n+  , nullOnly\n+  , nullExists\n+  , isNull\n+  , rmExceptNull\n+  , play3\n+  , play3'\n+  , tictactoeNPC3\n+  , -- * Exercise 4.a\n+    tictactoeNPC4a\n+    -- * Exercise 4.b\n+  , tictactoeNPC4b\n+    -- * Exercise 4.c\n+  , tictactoeNPC4c\n+  , play4\n+  , play4'\n+  , findNodeHasG\n+  , bestmove4\n+    -- * Exercise 4.d\n+  , alphabeta\n+  , tictactoeNPC4d\n+  ) where\n+\n+import Examples\n+  ( Player(..)\n+  , Grid\n+  , Tree(..)\n+  , prune\n+  , depth\n+  , gametree\n+  , minimax\n+  , next\n+  , empty\n+  , move\n+  , getNat\n+  , prompt\n+  , wins\n+  , full\n+  , cls\n+  , goto\n+  , putGrid\n+  , turn\n+  )\n+\n+import System.Random ( randomRIO )\n+import Data.Char ( isDigit )\n+import Data.List ( find )\n+import Data.Maybe ( fromJust )\n+\n+------------------------------------------------------------\n+-- Exercise 2\n+------------------------------------------------------------\n+\n+-- |\n+-- 'bestmove'' chooses a random move from the list of\n+-- best moves.\n+bestmove2 :: Grid -> Player -> IO Grid\n+bestmove2 g p = do\n+  let gs = [g' | Node (g',p') _ <- ts, p' == best]\n+  r <- randomRIO (0,length gs - 1)\n+  return (gs !! r)\n+  where\n+    tree = prune depth (gametree g p)\n+    Node (_,best) ts = minimax tree","path":"Programming_in_Haskell_2nd/chap11/src/Exercises.hs","position":103,"original_position":103,"commit_id":"ba29d166273d0cf3f0dd6e1d0593b6885687d6e4","original_commit_id":"ba29d166273d0cf3f0dd6e1d0593b6885687d6e4","user":{"login":"pythonissam","id":13606968,"avatar_url":"https://avatars1.githubusercontent.com/u/13606968?v=4","gravatar_id":"","url":"https://api.github.com/users/pythonissam","html_url":"https://github.com/pythonissam","followers_url":"https://api.github.com/users/pythonissam/followers","following_url":"https://api.github.com/users/pythonissam/following{/other_user}","gists_url":"https://api.github.com/users/pythonissam/gists{/gist_id}","starred_url":"https://api.github.com/users/pythonissam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pythonissam/subscriptions","organizations_url":"https://api.github.com/users/pythonissam/orgs","repos_url":"https://api.github.com/users/pythonissam/repos","events_url":"https://api.github.com/users/pythonissam/events{/privacy}","received_events_url":"https://api.github.com/users/pythonissam/received_events","type":"User","site_admin":false},"body":"次の手の中からランダムに選ぶので、リストのサイズが必要になってくるんですよね... かといってそのリストを `bestmove` の外に出すのは違うような...","created_at":"2018-05-08T02:05:39Z","updated_at":"2018-05-08T02:05:39Z","html_url":"https://github.com/e-bigmoon/Documents/pull/18#discussion_r186600172","pull_request_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/comments/186600172"},"html":{"href":"https://github.com/e-bigmoon/Documents/pull/18#discussion_r186600172"},"pull_request":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18"}},"in_reply_to_id":186279939},"pull_request":{"url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18","id":186187587,"html_url":"https://github.com/e-bigmoon/Documents/pull/18","diff_url":"https://github.com/e-bigmoon/Documents/pull/18.diff","patch_url":"https://github.com/e-bigmoon/Documents/pull/18.patch","issue_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/18","number":18,"state":"open","locked":false,"title":"Pinh chap11","user":{"login":"pythonissam","id":13606968,"avatar_url":"https://avatars1.githubusercontent.com/u/13606968?v=4","gravatar_id":"","url":"https://api.github.com/users/pythonissam","html_url":"https://github.com/pythonissam","followers_url":"https://api.github.com/users/pythonissam/followers","following_url":"https://api.github.com/users/pythonissam/following{/other_user}","gists_url":"https://api.github.com/users/pythonissam/gists{/gist_id}","starred_url":"https://api.github.com/users/pythonissam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pythonissam/subscriptions","organizations_url":"https://api.github.com/users/pythonissam/orgs","repos_url":"https://api.github.com/users/pythonissam/repos","events_url":"https://api.github.com/users/pythonissam/events{/privacy}","received_events_url":"https://api.github.com/users/pythonissam/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-06T04:23:04Z","updated_at":"2018-05-08T02:05:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a095fd495d532709a7bf2b1d57fcef7817c01309","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18/commits","review_comments_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18/comments","review_comment_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls/comments{/number}","comments_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/18/comments","statuses_url":"https://api.github.com/repos/e-bigmoon/Documents/statuses/ba29d166273d0cf3f0dd6e1d0593b6885687d6e4","head":{"label":"e-bigmoon:pinh-chap11","ref":"pinh-chap11","sha":"ba29d166273d0cf3f0dd6e1d0593b6885687d6e4","user":{"login":"e-bigmoon","id":22908044,"avatar_url":"https://avatars3.githubusercontent.com/u/22908044?v=4","gravatar_id":"","url":"https://api.github.com/users/e-bigmoon","html_url":"https://github.com/e-bigmoon","followers_url":"https://api.github.com/users/e-bigmoon/followers","following_url":"https://api.github.com/users/e-bigmoon/following{/other_user}","gists_url":"https://api.github.com/users/e-bigmoon/gists{/gist_id}","starred_url":"https://api.github.com/users/e-bigmoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-bigmoon/subscriptions","organizations_url":"https://api.github.com/users/e-bigmoon/orgs","repos_url":"https://api.github.com/users/e-bigmoon/repos","events_url":"https://api.github.com/users/e-bigmoon/events{/privacy}","received_events_url":"https://api.github.com/users/e-bigmoon/received_events","type":"Organization","site_admin":false},"repo":{"id":77590912,"name":"Documents","full_name":"e-bigmoon/Documents","owner":{"login":"e-bigmoon","id":22908044,"avatar_url":"https://avatars3.githubusercontent.com/u/22908044?v=4","gravatar_id":"","url":"https://api.github.com/users/e-bigmoon","html_url":"https://github.com/e-bigmoon","followers_url":"https://api.github.com/users/e-bigmoon/followers","following_url":"https://api.github.com/users/e-bigmoon/following{/other_user}","gists_url":"https://api.github.com/users/e-bigmoon/gists{/gist_id}","starred_url":"https://api.github.com/users/e-bigmoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-bigmoon/subscriptions","organizations_url":"https://api.github.com/users/e-bigmoon/orgs","repos_url":"https://api.github.com/users/e-bigmoon/repos","events_url":"https://api.github.com/users/e-bigmoon/events{/privacy}","received_events_url":"https://api.github.com/users/e-bigmoon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/e-bigmoon/Documents","description":null,"fork":false,"url":"https://api.github.com/repos/e-bigmoon/Documents","forks_url":"https://api.github.com/repos/e-bigmoon/Documents/forks","keys_url":"https://api.github.com/repos/e-bigmoon/Documents/keys{/key_id}","collaborators_url":"https://api.github.com/repos/e-bigmoon/Documents/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/e-bigmoon/Documents/teams","hooks_url":"https://api.github.com/repos/e-bigmoon/Documents/hooks","issue_events_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/events{/number}","events_url":"https://api.github.com/repos/e-bigmoon/Documents/events","assignees_url":"https://api.github.com/repos/e-bigmoon/Documents/assignees{/user}","branches_url":"https://api.github.com/repos/e-bigmoon/Documents/branches{/branch}","tags_url":"https://api.github.com/repos/e-bigmoon/Documents/tags","blobs_url":"https://api.github.com/repos/e-bigmoon/Documents/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/e-bigmoon/Documents/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/e-bigmoon/Documents/git/refs{/sha}","trees_url":"https://api.github.com/repos/e-bigmoon/Documents/git/trees{/sha}","statuses_url":"https://api.github.com/repos/e-bigmoon/Documents/statuses/{sha}","languages_url":"https://api.github.com/repos/e-bigmoon/Documents/languages","stargazers_url":"https://api.github.com/repos/e-bigmoon/Documents/stargazers","contributors_url":"https://api.github.com/repos/e-bigmoon/Documents/contributors","subscribers_url":"https://api.github.com/repos/e-bigmoon/Documents/subscribers","subscription_url":"https://api.github.com/repos/e-bigmoon/Documents/subscription","commits_url":"https://api.github.com/repos/e-bigmoon/Documents/commits{/sha}","git_commits_url":"https://api.github.com/repos/e-bigmoon/Documents/git/commits{/sha}","comments_url":"https://api.github.com/repos/e-bigmoon/Documents/comments{/number}","issue_comment_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/comments{/number}","contents_url":"https://api.github.com/repos/e-bigmoon/Documents/contents/{+path}","compare_url":"https://api.github.com/repos/e-bigmoon/Documents/compare/{base}...{head}","merges_url":"https://api.github.com/repos/e-bigmoon/Documents/merges","archive_url":"https://api.github.com/repos/e-bigmoon/Documents/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/e-bigmoon/Documents/downloads","issues_url":"https://api.github.com/repos/e-bigmoon/Documents/issues{/number}","pulls_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls{/number}","milestones_url":"https://api.github.com/repos/e-bigmoon/Documents/milestones{/number}","notifications_url":"https://api.github.com/repos/e-bigmoon/Documents/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/e-bigmoon/Documents/labels{/name}","releases_url":"https://api.github.com/repos/e-bigmoon/Documents/releases{/id}","deployments_url":"https://api.github.com/repos/e-bigmoon/Documents/deployments","created_at":"2016-12-29T07:02:06Z","updated_at":"2018-03-25T09:18:39Z","pushed_at":"2018-05-06T04:23:04Z","git_url":"git://github.com/e-bigmoon/Documents.git","ssh_url":"git@github.com:e-bigmoon/Documents.git","clone_url":"https://github.com/e-bigmoon/Documents.git","svn_url":"https://github.com/e-bigmoon/Documents","homepage":null,"size":1173,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"base":{"label":"e-bigmoon:master","ref":"master","sha":"15e56da9ec7803678fd468311c93109be49806bd","user":{"login":"e-bigmoon","id":22908044,"avatar_url":"https://avatars3.githubusercontent.com/u/22908044?v=4","gravatar_id":"","url":"https://api.github.com/users/e-bigmoon","html_url":"https://github.com/e-bigmoon","followers_url":"https://api.github.com/users/e-bigmoon/followers","following_url":"https://api.github.com/users/e-bigmoon/following{/other_user}","gists_url":"https://api.github.com/users/e-bigmoon/gists{/gist_id}","starred_url":"https://api.github.com/users/e-bigmoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-bigmoon/subscriptions","organizations_url":"https://api.github.com/users/e-bigmoon/orgs","repos_url":"https://api.github.com/users/e-bigmoon/repos","events_url":"https://api.github.com/users/e-bigmoon/events{/privacy}","received_events_url":"https://api.github.com/users/e-bigmoon/received_events","type":"Organization","site_admin":false},"repo":{"id":77590912,"name":"Documents","full_name":"e-bigmoon/Documents","owner":{"login":"e-bigmoon","id":22908044,"avatar_url":"https://avatars3.githubusercontent.com/u/22908044?v=4","gravatar_id":"","url":"https://api.github.com/users/e-bigmoon","html_url":"https://github.com/e-bigmoon","followers_url":"https://api.github.com/users/e-bigmoon/followers","following_url":"https://api.github.com/users/e-bigmoon/following{/other_user}","gists_url":"https://api.github.com/users/e-bigmoon/gists{/gist_id}","starred_url":"https://api.github.com/users/e-bigmoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-bigmoon/subscriptions","organizations_url":"https://api.github.com/users/e-bigmoon/orgs","repos_url":"https://api.github.com/users/e-bigmoon/repos","events_url":"https://api.github.com/users/e-bigmoon/events{/privacy}","received_events_url":"https://api.github.com/users/e-bigmoon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/e-bigmoon/Documents","description":null,"fork":false,"url":"https://api.github.com/repos/e-bigmoon/Documents","forks_url":"https://api.github.com/repos/e-bigmoon/Documents/forks","keys_url":"https://api.github.com/repos/e-bigmoon/Documents/keys{/key_id}","collaborators_url":"https://api.github.com/repos/e-bigmoon/Documents/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/e-bigmoon/Documents/teams","hooks_url":"https://api.github.com/repos/e-bigmoon/Documents/hooks","issue_events_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/events{/number}","events_url":"https://api.github.com/repos/e-bigmoon/Documents/events","assignees_url":"https://api.github.com/repos/e-bigmoon/Documents/assignees{/user}","branches_url":"https://api.github.com/repos/e-bigmoon/Documents/branches{/branch}","tags_url":"https://api.github.com/repos/e-bigmoon/Documents/tags","blobs_url":"https://api.github.com/repos/e-bigmoon/Documents/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/e-bigmoon/Documents/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/e-bigmoon/Documents/git/refs{/sha}","trees_url":"https://api.github.com/repos/e-bigmoon/Documents/git/trees{/sha}","statuses_url":"https://api.github.com/repos/e-bigmoon/Documents/statuses/{sha}","languages_url":"https://api.github.com/repos/e-bigmoon/Documents/languages","stargazers_url":"https://api.github.com/repos/e-bigmoon/Documents/stargazers","contributors_url":"https://api.github.com/repos/e-bigmoon/Documents/contributors","subscribers_url":"https://api.github.com/repos/e-bigmoon/Documents/subscribers","subscription_url":"https://api.github.com/repos/e-bigmoon/Documents/subscription","commits_url":"https://api.github.com/repos/e-bigmoon/Documents/commits{/sha}","git_commits_url":"https://api.github.com/repos/e-bigmoon/Documents/git/commits{/sha}","comments_url":"https://api.github.com/repos/e-bigmoon/Documents/comments{/number}","issue_comment_url":"https://api.github.com/repos/e-bigmoon/Documents/issues/comments{/number}","contents_url":"https://api.github.com/repos/e-bigmoon/Documents/contents/{+path}","compare_url":"https://api.github.com/repos/e-bigmoon/Documents/compare/{base}...{head}","merges_url":"https://api.github.com/repos/e-bigmoon/Documents/merges","archive_url":"https://api.github.com/repos/e-bigmoon/Documents/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/e-bigmoon/Documents/downloads","issues_url":"https://api.github.com/repos/e-bigmoon/Documents/issues{/number}","pulls_url":"https://api.github.com/repos/e-bigmoon/Documents/pulls{/number}","milestones_url":"https://api.github.com/repos/e-bigmoon/Documents/milestones{/number}","notifications_url":"https://api.github.com/repos/e-bigmoon/Documents/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/e-bigmoon/Documents/labels{/name}","releases_url":"https://api.github.com/repos/e-bigmoon/Documents/releases{/id}","deployments_url":"https://api.github.com/repos/e-bigmoon/Documents/deployments","created_at":"2016-12-29T07:02:06Z","updated_at":"2018-03-25T09:18:39Z","pushed_at":"2018-05-06T04:23:04Z","git_url":"git://github.com/e-bigmoon/Documents.git","ssh_url":"git@github.com:e-bigmoon/Documents.git","clone_url":"https://github.com/e-bigmoon/Documents.git","svn_url":"https://github.com/e-bigmoon/Documents","homepage":null,"size":1173,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18"},"html":{"href":"https://github.com/e-bigmoon/Documents/pull/18"},"issue":{"href":"https://api.github.com/repos/e-bigmoon/Documents/issues/18"},"comments":{"href":"https://api.github.com/repos/e-bigmoon/Documents/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/e-bigmoon/Documents/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/e-bigmoon/Documents/statuses/ba29d166273d0cf3f0dd6e1d0593b6885687d6e4"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"pythonissam"}}