{"action":"created","comment":{"url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/comments/153035982","pull_request_review_id":78993364,"id":153035982,"diff_hunk":"@@ -0,0 +1,111 @@\n+import numpy as np\n+\n+class TicTacToeEnv(object):\n+    def __init__(self):\n+        \"\"\"\n+        state space: 2x3x3\n+        action space: 18 possible values\n+            action: make actions a single integer -- in range(0, 18)\n+        assume x's always go first\n+        \"\"\"\n+\n+        self.action_dims = (2, 3, 3)\n+\n+    # The following 4 methods are called outside of the environment\n+    def get_next_state(self, state, action_int):\n+        action_array = self.convert_int_to_action(action_int)\n+        next_state = state + action_array\n+        return next_state\n+\n+    def get_legal_actions(self, state):\n+        turn = self.get_turn_tictactoe(state)\n+        # legal_actions = np.zeros((2, 3, 3), dtype=int)\n+        legal_actions = []\n+        for i in range(3):\n+            for j in range(3):\n+                if state[:, i, j].sum() == 0:\n+                    action_array = np.zeros((2, 3, 3), dtype=int)\n+                    action_array[turn, i, j] = 1\n+                    action_int = self.convert_action_to_int(action_array)\n+                    legal_actions.append(action_int)\n+        return np.array(legal_actions)\n+\n+\n+    def is_game_over(self, state):\n+        result = self.outcome(state)\n+        if result == 2:\n+            return 0\n+        else:\n+            return 1\n+\n+    def outcome(self, state):\n+        \"\"\"\n+        1 is a win for x's\n+        -1 is a win for o's\n+        0 is a tie\n+        2: the game is not over\n+        \"\"\"\n+        for turn in range(2):\n+            if all([state[turn, 0, 0] == 1, state[turn, 1, 1] == 1, state[turn, 2, 2] == 1]):\n+                return self.convert_turn_to_winner(turn)\n+            if all([state[turn, 2, 0] == 1, state[turn, 1, 1] == 1, state[turn, 0, 2] == 1]):\n+                return self.convert_turn_to_winner(turn)\n+            for i in range(3):\n+                if state[turn, 0, i] == 1 and state[turn, 1, i] == 1 and state[turn, 2, i] == 1:\n+                    return self.convert_turn_to_winner(turn)\n+            for j in range(3):\n+                if state[turn, j, 0] == 1 and state[turn, j, 1] == 1 and state[turn, j, 2] == 1:\n+                    return self.convert_turn_to_winner(turn)\n+        if state.sum() >= 9:\n+            return 0\n+        # if we reach this point, the game is not over.  return 2\n+        return 2\n+\n+    def print_board(self, state):\n+        for i in range(3):\n+            row = ''\n+            for j in range(3):\n+                if state[0, i, j] == 1:\n+                    row += 'x '\n+                elif state[1, i, j] == 1:\n+                    row += 'o '\n+                else:\n+                    row += '* '\n+            print(row)\n+\n+    def convert_action_to_int(self, action_array):\n+        \"\"\"\n+        action_array is 2x3x3\n+        \"\"\"\n+        action_array = np.reshape(action_array, -1)\n+        return np.where(action_array == 1)[0]\n+\n+    def convert_int_to_action(self, action_int):\n+        action_array = np.zeros((self.action_dims), dtype=int)\n+        action_array = np.reshape(action_array, -1)\n+        action_array[action_int] = 1\n+        action_array = np.reshape(action_array, (self.action_dims))\n+        return action_array\n+\n+    def get_turn_tictactoe(self, state):\n+        \"\"\"\n+        return 0 if x's turn\n+        return 1 if o's turn\n+        \"\"\"\n+        num_xs = state[0, :, :].sum()\n+        num_os = state[1, :, :].sum()\n+        if num_os == num_xs:\n+            return 0\n+        elif num_xs > num_os:\n+            return 1\n+        else:\n+            return -1\n+\n+\n+    def convert_turn_to_winner(self, turn):","path":"tictactoe_env.py","position":105,"original_position":105,"commit_id":"01d73ed0aefa9b839a959d3e8b9a583d1a09a35f","original_commit_id":"01d73ed0aefa9b839a959d3e8b9a583d1a09a35f","user":{"login":"captaincapsaicin","id":10425351,"avatar_url":"https://avatars1.githubusercontent.com/u/10425351?v=4","gravatar_id":"","url":"https://api.github.com/users/captaincapsaicin","html_url":"https://github.com/captaincapsaicin","followers_url":"https://api.github.com/users/captaincapsaicin/followers","following_url":"https://api.github.com/users/captaincapsaicin/following{/other_user}","gists_url":"https://api.github.com/users/captaincapsaicin/gists{/gist_id}","starred_url":"https://api.github.com/users/captaincapsaicin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captaincapsaicin/subscriptions","organizations_url":"https://api.github.com/users/captaincapsaicin/orgs","repos_url":"https://api.github.com/users/captaincapsaicin/repos","events_url":"https://api.github.com/users/captaincapsaicin/events{/privacy}","received_events_url":"https://api.github.com/users/captaincapsaicin/received_events","type":"User","site_admin":false},"body":"Call me silly, but how about lets make \r\n\r\n0 indicate x's turn, and if x won\r\n1 indicate o's turn, and if o won.\r\n\r\n-1 can be a draw\r\n2 can be game is not over.\r\n\r\nAnd then we can just return the `turn` directly and not do this somewhat confusing algebra","created_at":"2017-11-25T02:06:35Z","updated_at":"2017-11-25T02:06:40Z","html_url":"https://github.com/captaincapsaicin/castle/pull/7#discussion_r153035982","pull_request_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/comments/153035982"},"html":{"href":"https://github.com/captaincapsaicin/castle/pull/7#discussion_r153035982"},"pull_request":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7","id":153767181,"html_url":"https://github.com/captaincapsaicin/castle/pull/7","diff_url":"https://github.com/captaincapsaicin/castle/pull/7.diff","patch_url":"https://github.com/captaincapsaicin/castle/pull/7.patch","issue_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/7","number":7,"state":"open","locked":false,"title":"Tic Tac Toe environment","user":{"login":"rajivsambharya","id":10658795,"avatar_url":"https://avatars0.githubusercontent.com/u/10658795?v=4","gravatar_id":"","url":"https://api.github.com/users/rajivsambharya","html_url":"https://github.com/rajivsambharya","followers_url":"https://api.github.com/users/rajivsambharya/followers","following_url":"https://api.github.com/users/rajivsambharya/following{/other_user}","gists_url":"https://api.github.com/users/rajivsambharya/gists{/gist_id}","starred_url":"https://api.github.com/users/rajivsambharya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rajivsambharya/subscriptions","organizations_url":"https://api.github.com/users/rajivsambharya/orgs","repos_url":"https://api.github.com/users/rajivsambharya/repos","events_url":"https://api.github.com/users/rajivsambharya/events{/privacy}","received_events_url":"https://api.github.com/users/rajivsambharya/received_events","type":"User","site_admin":false},"body":"tictactoe environment added with tests","created_at":"2017-11-21T00:14:31Z","updated_at":"2017-11-25T02:06:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de51546f7051c24b906b50896cfc92c4b0e563f9","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7/commits","review_comments_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7/comments","review_comment_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/7/comments","statuses_url":"https://api.github.com/repos/captaincapsaicin/castle/statuses/01d73ed0aefa9b839a959d3e8b9a583d1a09a35f","head":{"label":"captaincapsaicin:tictactoe_v2","ref":"tictactoe_v2","sha":"01d73ed0aefa9b839a959d3e8b9a583d1a09a35f","user":{"login":"captaincapsaicin","id":10425351,"avatar_url":"https://avatars1.githubusercontent.com/u/10425351?v=4","gravatar_id":"","url":"https://api.github.com/users/captaincapsaicin","html_url":"https://github.com/captaincapsaicin","followers_url":"https://api.github.com/users/captaincapsaicin/followers","following_url":"https://api.github.com/users/captaincapsaicin/following{/other_user}","gists_url":"https://api.github.com/users/captaincapsaicin/gists{/gist_id}","starred_url":"https://api.github.com/users/captaincapsaicin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captaincapsaicin/subscriptions","organizations_url":"https://api.github.com/users/captaincapsaicin/orgs","repos_url":"https://api.github.com/users/captaincapsaicin/repos","events_url":"https://api.github.com/users/captaincapsaicin/events{/privacy}","received_events_url":"https://api.github.com/users/captaincapsaicin/received_events","type":"User","site_admin":false},"repo":{"id":108606402,"name":"castle","full_name":"captaincapsaicin/castle","owner":{"login":"captaincapsaicin","id":10425351,"avatar_url":"https://avatars1.githubusercontent.com/u/10425351?v=4","gravatar_id":"","url":"https://api.github.com/users/captaincapsaicin","html_url":"https://github.com/captaincapsaicin","followers_url":"https://api.github.com/users/captaincapsaicin/followers","following_url":"https://api.github.com/users/captaincapsaicin/following{/other_user}","gists_url":"https://api.github.com/users/captaincapsaicin/gists{/gist_id}","starred_url":"https://api.github.com/users/captaincapsaicin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captaincapsaicin/subscriptions","organizations_url":"https://api.github.com/users/captaincapsaicin/orgs","repos_url":"https://api.github.com/users/captaincapsaicin/repos","events_url":"https://api.github.com/users/captaincapsaicin/events{/privacy}","received_events_url":"https://api.github.com/users/captaincapsaicin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/captaincapsaicin/castle","description":"AlphaGo-inspired agent for playing chess. CS 294-112 final project.","fork":false,"url":"https://api.github.com/repos/captaincapsaicin/castle","forks_url":"https://api.github.com/repos/captaincapsaicin/castle/forks","keys_url":"https://api.github.com/repos/captaincapsaicin/castle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/captaincapsaicin/castle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/captaincapsaicin/castle/teams","hooks_url":"https://api.github.com/repos/captaincapsaicin/castle/hooks","issue_events_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/events{/number}","events_url":"https://api.github.com/repos/captaincapsaicin/castle/events","assignees_url":"https://api.github.com/repos/captaincapsaicin/castle/assignees{/user}","branches_url":"https://api.github.com/repos/captaincapsaicin/castle/branches{/branch}","tags_url":"https://api.github.com/repos/captaincapsaicin/castle/tags","blobs_url":"https://api.github.com/repos/captaincapsaicin/castle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/captaincapsaicin/castle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/captaincapsaicin/castle/git/refs{/sha}","trees_url":"https://api.github.com/repos/captaincapsaicin/castle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/captaincapsaicin/castle/statuses/{sha}","languages_url":"https://api.github.com/repos/captaincapsaicin/castle/languages","stargazers_url":"https://api.github.com/repos/captaincapsaicin/castle/stargazers","contributors_url":"https://api.github.com/repos/captaincapsaicin/castle/contributors","subscribers_url":"https://api.github.com/repos/captaincapsaicin/castle/subscribers","subscription_url":"https://api.github.com/repos/captaincapsaicin/castle/subscription","commits_url":"https://api.github.com/repos/captaincapsaicin/castle/commits{/sha}","git_commits_url":"https://api.github.com/repos/captaincapsaicin/castle/git/commits{/sha}","comments_url":"https://api.github.com/repos/captaincapsaicin/castle/comments{/number}","issue_comment_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/comments{/number}","contents_url":"https://api.github.com/repos/captaincapsaicin/castle/contents/{+path}","compare_url":"https://api.github.com/repos/captaincapsaicin/castle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/captaincapsaicin/castle/merges","archive_url":"https://api.github.com/repos/captaincapsaicin/castle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/captaincapsaicin/castle/downloads","issues_url":"https://api.github.com/repos/captaincapsaicin/castle/issues{/number}","pulls_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls{/number}","milestones_url":"https://api.github.com/repos/captaincapsaicin/castle/milestones{/number}","notifications_url":"https://api.github.com/repos/captaincapsaicin/castle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/captaincapsaicin/castle/labels{/name}","releases_url":"https://api.github.com/repos/captaincapsaicin/castle/releases{/id}","deployments_url":"https://api.github.com/repos/captaincapsaicin/castle/deployments","created_at":"2017-10-27T23:59:41Z","updated_at":"2017-11-02T23:09:47Z","pushed_at":"2017-11-25T01:35:07Z","git_url":"git://github.com/captaincapsaicin/castle.git","ssh_url":"git@github.com:captaincapsaicin/castle.git","clone_url":"https://github.com/captaincapsaicin/castle.git","svn_url":"https://github.com/captaincapsaicin/castle","homepage":"","size":73,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"captaincapsaicin:master","ref":"master","sha":"a7aeaa09b359c9e096d2762b6c3049bea40d1475","user":{"login":"captaincapsaicin","id":10425351,"avatar_url":"https://avatars1.githubusercontent.com/u/10425351?v=4","gravatar_id":"","url":"https://api.github.com/users/captaincapsaicin","html_url":"https://github.com/captaincapsaicin","followers_url":"https://api.github.com/users/captaincapsaicin/followers","following_url":"https://api.github.com/users/captaincapsaicin/following{/other_user}","gists_url":"https://api.github.com/users/captaincapsaicin/gists{/gist_id}","starred_url":"https://api.github.com/users/captaincapsaicin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captaincapsaicin/subscriptions","organizations_url":"https://api.github.com/users/captaincapsaicin/orgs","repos_url":"https://api.github.com/users/captaincapsaicin/repos","events_url":"https://api.github.com/users/captaincapsaicin/events{/privacy}","received_events_url":"https://api.github.com/users/captaincapsaicin/received_events","type":"User","site_admin":false},"repo":{"id":108606402,"name":"castle","full_name":"captaincapsaicin/castle","owner":{"login":"captaincapsaicin","id":10425351,"avatar_url":"https://avatars1.githubusercontent.com/u/10425351?v=4","gravatar_id":"","url":"https://api.github.com/users/captaincapsaicin","html_url":"https://github.com/captaincapsaicin","followers_url":"https://api.github.com/users/captaincapsaicin/followers","following_url":"https://api.github.com/users/captaincapsaicin/following{/other_user}","gists_url":"https://api.github.com/users/captaincapsaicin/gists{/gist_id}","starred_url":"https://api.github.com/users/captaincapsaicin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captaincapsaicin/subscriptions","organizations_url":"https://api.github.com/users/captaincapsaicin/orgs","repos_url":"https://api.github.com/users/captaincapsaicin/repos","events_url":"https://api.github.com/users/captaincapsaicin/events{/privacy}","received_events_url":"https://api.github.com/users/captaincapsaicin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/captaincapsaicin/castle","description":"AlphaGo-inspired agent for playing chess. CS 294-112 final project.","fork":false,"url":"https://api.github.com/repos/captaincapsaicin/castle","forks_url":"https://api.github.com/repos/captaincapsaicin/castle/forks","keys_url":"https://api.github.com/repos/captaincapsaicin/castle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/captaincapsaicin/castle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/captaincapsaicin/castle/teams","hooks_url":"https://api.github.com/repos/captaincapsaicin/castle/hooks","issue_events_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/events{/number}","events_url":"https://api.github.com/repos/captaincapsaicin/castle/events","assignees_url":"https://api.github.com/repos/captaincapsaicin/castle/assignees{/user}","branches_url":"https://api.github.com/repos/captaincapsaicin/castle/branches{/branch}","tags_url":"https://api.github.com/repos/captaincapsaicin/castle/tags","blobs_url":"https://api.github.com/repos/captaincapsaicin/castle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/captaincapsaicin/castle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/captaincapsaicin/castle/git/refs{/sha}","trees_url":"https://api.github.com/repos/captaincapsaicin/castle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/captaincapsaicin/castle/statuses/{sha}","languages_url":"https://api.github.com/repos/captaincapsaicin/castle/languages","stargazers_url":"https://api.github.com/repos/captaincapsaicin/castle/stargazers","contributors_url":"https://api.github.com/repos/captaincapsaicin/castle/contributors","subscribers_url":"https://api.github.com/repos/captaincapsaicin/castle/subscribers","subscription_url":"https://api.github.com/repos/captaincapsaicin/castle/subscription","commits_url":"https://api.github.com/repos/captaincapsaicin/castle/commits{/sha}","git_commits_url":"https://api.github.com/repos/captaincapsaicin/castle/git/commits{/sha}","comments_url":"https://api.github.com/repos/captaincapsaicin/castle/comments{/number}","issue_comment_url":"https://api.github.com/repos/captaincapsaicin/castle/issues/comments{/number}","contents_url":"https://api.github.com/repos/captaincapsaicin/castle/contents/{+path}","compare_url":"https://api.github.com/repos/captaincapsaicin/castle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/captaincapsaicin/castle/merges","archive_url":"https://api.github.com/repos/captaincapsaicin/castle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/captaincapsaicin/castle/downloads","issues_url":"https://api.github.com/repos/captaincapsaicin/castle/issues{/number}","pulls_url":"https://api.github.com/repos/captaincapsaicin/castle/pulls{/number}","milestones_url":"https://api.github.com/repos/captaincapsaicin/castle/milestones{/number}","notifications_url":"https://api.github.com/repos/captaincapsaicin/castle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/captaincapsaicin/castle/labels{/name}","releases_url":"https://api.github.com/repos/captaincapsaicin/castle/releases{/id}","deployments_url":"https://api.github.com/repos/captaincapsaicin/castle/deployments","created_at":"2017-10-27T23:59:41Z","updated_at":"2017-11-02T23:09:47Z","pushed_at":"2017-11-25T01:35:07Z","git_url":"git://github.com/captaincapsaicin/castle.git","ssh_url":"git@github.com:captaincapsaicin/castle.git","clone_url":"https://github.com/captaincapsaicin/castle.git","svn_url":"https://github.com/captaincapsaicin/castle","homepage":"","size":73,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7"},"html":{"href":"https://github.com/captaincapsaicin/castle/pull/7"},"issue":{"href":"https://api.github.com/repos/captaincapsaicin/castle/issues/7"},"comments":{"href":"https://api.github.com/repos/captaincapsaicin/castle/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/captaincapsaicin/castle/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/captaincapsaicin/castle/statuses/01d73ed0aefa9b839a959d3e8b9a583d1a09a35f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"captaincapsaicin"}}