{"action":"created","comment":{"url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/comments/50025928","id":50025928,"diff_hunk":"@@ -0,0 +1,92 @@\n+require_relative '../lib/board.rb'\n+\n+class Game\n+\n+  attr_accessor :player_1, :player_2\n+\n+  WIN_COMBINATIONS= [\n+      [0,1,2],  #top row\n+      [3,4,5], #middle row\n+      [6,7,8],  #bottom row\n+      [0,3,6],  #left column\n+      [1,4,7],  #middle column\n+      [2,5,8],  #right column\n+      [0,4,8],  #diagonal 1\n+      [6,4,2]   #diagonal 2\n+  ]\n+\n+  def initialize(player_1 =  Human.new('X'), player_2 = Human.new('O'), board = Board.new)\n+    @board = board\n+    @player_1 = player_1\n+    @player_2 = player_2\n+  end\n+\n+  def cells=(set_cells)\n+    @board.cells = set_cells\n+  end\n+\n+  def cells\n+    (@board.cells == []) ? @board.cells : @board\n+  end\n+\n+  def won?\n+    $winner = nil\n+    returnable = []\n+    WIN_COMBINATIONS.each do |win_combo|\n+      if @board.cells[win_combo[0]] == 'X' && @board.cells[win_combo[1]] == 'X' && @board.cells[win_combo[2]] == 'X'\n+        $winner = player_1.token\n+        returnable = win_combo\n+        break\n+      elsif @board.cells[win_combo[0]] == 'O' && @board.cells[win_combo[1]] == 'O' && @board.cells[win_combo[2]] == 'O'\n+        $winner = player_2.token\n+        returnable = win_combo\n+        break\n+      else\n+        returnable = false\n+      end\n+    end\n+    returnable","path":"lib/game.rb","position":48,"original_position":48,"commit_id":"e0b1b15272ae5e5f19ca3f2e44d75fad47d8ff30","original_commit_id":"e0b1b15272ae5e5f19ca3f2e44d75fad47d8ff30","user":{"login":"aviflombaum","id":4515,"avatar_url":"https://avatars.githubusercontent.com/u/4515?v=3","gravatar_id":"","url":"https://api.github.com/users/aviflombaum","html_url":"https://github.com/aviflombaum","followers_url":"https://api.github.com/users/aviflombaum/followers","following_url":"https://api.github.com/users/aviflombaum/following{/other_user}","gists_url":"https://api.github.com/users/aviflombaum/gists{/gist_id}","starred_url":"https://api.github.com/users/aviflombaum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviflombaum/subscriptions","organizations_url":"https://api.github.com/users/aviflombaum/orgs","repos_url":"https://api.github.com/users/aviflombaum/repos","events_url":"https://api.github.com/users/aviflombaum/events{/privacy}","received_events_url":"https://api.github.com/users/aviflombaum/received_events","type":"User","site_admin":false},"body":"You should never `return` from within a loop. If you need a return value from within a loop you need to use a higher level iterator or some sort of local variable. \r\n\r\nConsider this solution to a simpler problem of finding the even number in an array.\r\n\r\n```ruby\r\nthe_even_number = nil\r\n[1,2,3].each do |i|\r\n  if i.even?\r\n    the_even_number = i\r\n  end\r\nend\r\nthe_even_number\r\n```\r\n\r\nInstead of returning from within that loop, we flip the switch local variable `the_even_number` to the element in the array that made the if statement true. Then we leave `the_even_number` as the last line to ensure the return value. If no even numbers are present, `the_even_number` will remain nil.\r\n\r\nBut better, let's just use [`Enumerable#detect`](http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-detect)\r\n\r\n```ruby\r\nthe_even_number = [1,2,3].detect do |i|\r\n  i.even?\r\nend\r\n```\r\n","created_at":"2016-01-18T17:40:15Z","updated_at":"2016-01-18T17:40:15Z","html_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35#discussion_r50025928","pull_request_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/comments/50025928"},"html":{"href":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35#discussion_r50025928"},"pull_request":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35","id":55860197,"html_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35","diff_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35.diff","patch_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35.patch","issue_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/35","number":35,"state":"closed","locked":false,"title":"tictac toe with AI","user":{"login":"kylegraydev","id":10456984,"avatar_url":"https://avatars.githubusercontent.com/u/10456984?v=3","gravatar_id":"","url":"https://api.github.com/users/kylegraydev","html_url":"https://github.com/kylegraydev","followers_url":"https://api.github.com/users/kylegraydev/followers","following_url":"https://api.github.com/users/kylegraydev/following{/other_user}","gists_url":"https://api.github.com/users/kylegraydev/gists{/gist_id}","starred_url":"https://api.github.com/users/kylegraydev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylegraydev/subscriptions","organizations_url":"https://api.github.com/users/kylegraydev/orgs","repos_url":"https://api.github.com/users/kylegraydev/repos","events_url":"https://api.github.com/users/kylegraydev/events{/privacy}","received_events_url":"https://api.github.com/users/kylegraydev/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-13T06:45:56Z","updated_at":"2016-01-18T17:40:15Z","closed_at":"2016-01-13T06:47:21Z","merged_at":null,"merge_commit_sha":"80b075009663d4bd43998ee4ad743b20e8d2f2e4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35/commits","review_comments_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35/comments","review_comment_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/comments{/number}","comments_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/35/comments","statuses_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/statuses/e0b1b15272ae5e5f19ca3f2e44d75fad47d8ff30","head":{"label":"kylegraydev:master","ref":"master","sha":"e0b1b15272ae5e5f19ca3f2e44d75fad47d8ff30","user":{"login":"kylegraydev","id":10456984,"avatar_url":"https://avatars.githubusercontent.com/u/10456984?v=3","gravatar_id":"","url":"https://api.github.com/users/kylegraydev","html_url":"https://github.com/kylegraydev","followers_url":"https://api.github.com/users/kylegraydev/followers","following_url":"https://api.github.com/users/kylegraydev/following{/other_user}","gists_url":"https://api.github.com/users/kylegraydev/gists{/gist_id}","starred_url":"https://api.github.com/users/kylegraydev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylegraydev/subscriptions","organizations_url":"https://api.github.com/users/kylegraydev/orgs","repos_url":"https://api.github.com/users/kylegraydev/repos","events_url":"https://api.github.com/users/kylegraydev/events{/privacy}","received_events_url":"https://api.github.com/users/kylegraydev/received_events","type":"User","site_admin":false},"repo":{"id":49315001,"name":"ttt-with-ai-project-v-000","full_name":"kylegraydev/ttt-with-ai-project-v-000","owner":{"login":"kylegraydev","id":10456984,"avatar_url":"https://avatars.githubusercontent.com/u/10456984?v=3","gravatar_id":"","url":"https://api.github.com/users/kylegraydev","html_url":"https://github.com/kylegraydev","followers_url":"https://api.github.com/users/kylegraydev/followers","following_url":"https://api.github.com/users/kylegraydev/following{/other_user}","gists_url":"https://api.github.com/users/kylegraydev/gists{/gist_id}","starred_url":"https://api.github.com/users/kylegraydev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylegraydev/subscriptions","organizations_url":"https://api.github.com/users/kylegraydev/orgs","repos_url":"https://api.github.com/users/kylegraydev/repos","events_url":"https://api.github.com/users/kylegraydev/events{/privacy}","received_events_url":"https://api.github.com/users/kylegraydev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kylegraydev/ttt-with-ai-project-v-000","description":null,"fork":true,"url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000","forks_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/forks","keys_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/teams","hooks_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/hooks","issue_events_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/issues/events{/number}","events_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/events","assignees_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/assignees{/user}","branches_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/branches{/branch}","tags_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/tags","blobs_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/git/refs{/sha}","trees_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/statuses/{sha}","languages_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/languages","stargazers_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/stargazers","contributors_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/contributors","subscribers_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/subscribers","subscription_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/subscription","commits_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/commits{/sha}","git_commits_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/git/commits{/sha}","comments_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/comments{/number}","issue_comment_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/issues/comments{/number}","contents_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/contents/{+path}","compare_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/merges","archive_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/downloads","issues_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/issues{/number}","pulls_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/pulls{/number}","milestones_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/milestones{/number}","notifications_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/labels{/name}","releases_url":"https://api.github.com/repos/kylegraydev/ttt-with-ai-project-v-000/releases{/id}","created_at":"2016-01-09T07:19:30Z","updated_at":"2016-01-13T06:44:59Z","pushed_at":"2016-01-13T08:06:55Z","git_url":"git://github.com/kylegraydev/ttt-with-ai-project-v-000.git","ssh_url":"git@github.com:kylegraydev/ttt-with-ai-project-v-000.git","clone_url":"https://github.com/kylegraydev/ttt-with-ai-project-v-000.git","svn_url":"https://github.com/kylegraydev/ttt-with-ai-project-v-000","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"learn-co-students:master","ref":"master","sha":"8323dbabbe4087a3987d6fc26fa444695e75f6c2","user":{"login":"learn-co-students","id":8825476,"avatar_url":"https://avatars.githubusercontent.com/u/8825476?v=3","gravatar_id":"","url":"https://api.github.com/users/learn-co-students","html_url":"https://github.com/learn-co-students","followers_url":"https://api.github.com/users/learn-co-students/followers","following_url":"https://api.github.com/users/learn-co-students/following{/other_user}","gists_url":"https://api.github.com/users/learn-co-students/gists{/gist_id}","starred_url":"https://api.github.com/users/learn-co-students/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learn-co-students/subscriptions","organizations_url":"https://api.github.com/users/learn-co-students/orgs","repos_url":"https://api.github.com/users/learn-co-students/repos","events_url":"https://api.github.com/users/learn-co-students/events{/privacy}","received_events_url":"https://api.github.com/users/learn-co-students/received_events","type":"Organization","site_admin":false},"repo":{"id":46080145,"name":"ttt-with-ai-project-v-000","full_name":"learn-co-students/ttt-with-ai-project-v-000","owner":{"login":"learn-co-students","id":8825476,"avatar_url":"https://avatars.githubusercontent.com/u/8825476?v=3","gravatar_id":"","url":"https://api.github.com/users/learn-co-students","html_url":"https://github.com/learn-co-students","followers_url":"https://api.github.com/users/learn-co-students/followers","following_url":"https://api.github.com/users/learn-co-students/following{/other_user}","gists_url":"https://api.github.com/users/learn-co-students/gists{/gist_id}","starred_url":"https://api.github.com/users/learn-co-students/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learn-co-students/subscriptions","organizations_url":"https://api.github.com/users/learn-co-students/orgs","repos_url":"https://api.github.com/users/learn-co-students/repos","events_url":"https://api.github.com/users/learn-co-students/events{/privacy}","received_events_url":"https://api.github.com/users/learn-co-students/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000","description":null,"fork":false,"url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000","forks_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/forks","keys_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/keys{/key_id}","collaborators_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/teams","hooks_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/hooks","issue_events_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/events{/number}","events_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/events","assignees_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/assignees{/user}","branches_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/branches{/branch}","tags_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/tags","blobs_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/git/refs{/sha}","trees_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/git/trees{/sha}","statuses_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/statuses/{sha}","languages_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/languages","stargazers_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/stargazers","contributors_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/contributors","subscribers_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/subscribers","subscription_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/subscription","commits_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/commits{/sha}","git_commits_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/git/commits{/sha}","comments_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/comments{/number}","issue_comment_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/comments{/number}","contents_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/contents/{+path}","compare_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/compare/{base}...{head}","merges_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/merges","archive_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/downloads","issues_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues{/number}","pulls_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls{/number}","milestones_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/milestones{/number}","notifications_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/labels{/name}","releases_url":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/releases{/id}","created_at":"2015-11-12T20:52:43Z","updated_at":"2015-11-12T20:52:52Z","pushed_at":"2016-01-16T23:57:02Z","git_url":"git://github.com/learn-co-students/ttt-with-ai-project-v-000.git","ssh_url":"git@github.com:learn-co-students/ttt-with-ai-project-v-000.git","clone_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000.git","svn_url":"https://github.com/learn-co-students/ttt-with-ai-project-v-000","homepage":null,"size":92,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":33,"forks":52,"open_issues":33,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35"},"html":{"href":"https://github.com/learn-co-students/ttt-with-ai-project-v-000/pull/35"},"issue":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/35"},"comments":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/learn-co-students/ttt-with-ai-project-v-000/statuses/e0b1b15272ae5e5f19ca3f2e44d75fad47d8ff30"}}}}