{"action":"created","comment":{"url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/comments/227112943","pull_request_review_id":167078472,"id":227112943,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNzExMjk0Mw==","diff_hunk":"@@ -0,0 +1,253 @@\n+import {Player} from './players.js';\r\n+import {Board} from './board.js';\r\n+\r\n+function returnAccumulatedScores(data) {\r\n+\r\n+  let dataToAccumulate = [];\r\n+\r\n+  do {\r\n+\r\n+    let elementToCompare = data.shift();\r\n+    elementToCompare.apperances = 0;\r\n+    for (let i = 0; i < data.length; i++) {\r\n+      if (elementToCompare.x === data[i].x && elementToCompare.y === data[i].y) {\r\n+        elementToCompare.score += data[i].score;\r\n+        elementToCompare.apperances++;\r\n+        data.splice(i, 1);\r\n+        i--;\r\n+      }\r\n+    }\r\n+    dataToAccumulate = [\r\n+      ...dataToAccumulate,\r\n+      elementToCompare\r\n+    ];\r\n+\r\n+  } while (data.length > 0)\r\n+\r\n+  const dataToReturn = dataToAccumulate.map(element => {\r\n+    element.evaluate = (element.score / element.apperances)\r\n+    return element;\r\n+  });\r\n+\r\n+  return dataToReturn\r\n+}\r\n+\r\n+class Game {\r\n+  constructor() {\r\n+    this.board = new Board;\r\n+    this.players = this.createPlayers()\r\n+    this.ready = false;\r\n+    this.fieldsLeft = 9;\r\n+  }\r\n+\r\n+  createPlayers() {\r\n+    return [\r\n+      new Player('Player 1', 'cross', true),\r\n+      new Player('Player 2', 'circle')\r\n+    ];\r\n+\r\n+  }\r\n+\r\n+  get activePlayer() {\r\n+    return this.players.find(player => player.active);\r\n+  }\r\n+\r\n+  get unactivePlayer() {\r\n+    return this.players.find(player => !player.active);\r\n+  }\r\n+\r\n+  switchPlayers() {\r\n+    this.players.forEach(player => player.active = !player.active);\r\n+  }\r\n+\r\n+  startGame(boardDiv) {\r\n+    this.board.renderFields(boardDiv);\r\n+    this.ready = true;\r\n+  }\r\n+\r\n+  makeMove(x,y){\r\n+    const element = document.querySelector(`[data-x=\"${x}\"][data-y=\"${y}\"]`);\r\n+    const field = this.board.fields[x][y];\r\n+    field.free = false;\r\n+    field.owner = this.activePlayer;\r\n+    field.renderSymbol(element);\r\n+    this.fieldsLeft--;\r\n+\r\n+    if (this.checkForWin(this.activePlayer)){\r\n+      alert(`${this.activePlayer.name} wins`);\r\n+    }else if (this.fieldsLeft === 0) {\r\n+      alert('draw!');\r\n+    }else{\r\n+      this.switchPlayers();\r\n+      if (this.activePlayer.name === 'Player 2') this.computerMove();\r\n+      this.ready = true;\r\n+    }\r\n+  }\r\n+\r\n+  handleInteraction(e) {\r\n+    if (this.ready){\r\n+      this.ready = false;\r\n+      const element = e.target;\r\n+      const x = element.dataset.x;\r\n+      const y = element.dataset.y;\r\n+      const field = this.board.fields[x][y];\r\n+      if (!field.free) return;\r\n+      else {\r","path":"js/game.js","position":95,"original_position":95,"commit_id":"963ef060c1a6726ca87f079689134ece78fdc7fb","original_commit_id":"963ef060c1a6726ca87f079689134ece78fdc7fb","user":{"login":"cezaryB","id":20945507,"node_id":"MDQ6VXNlcjIwOTQ1NTA3","avatar_url":"https://avatars2.githubusercontent.com/u/20945507?v=4","gravatar_id":"","url":"https://api.github.com/users/cezaryB","html_url":"https://github.com/cezaryB","followers_url":"https://api.github.com/users/cezaryB/followers","following_url":"https://api.github.com/users/cezaryB/following{/other_user}","gists_url":"https://api.github.com/users/cezaryB/gists{/gist_id}","starred_url":"https://api.github.com/users/cezaryB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cezaryB/subscriptions","organizations_url":"https://api.github.com/users/cezaryB/orgs","repos_url":"https://api.github.com/users/cezaryB/repos","events_url":"https://api.github.com/users/cezaryB/events{/privacy}","received_events_url":"https://api.github.com/users/cezaryB/received_events","type":"User","site_admin":false},"body":"Gdybyś zastosował poprzedni zapis (czyli `if (!field.free) return` to ten `else` nie jest Ci potrzebny bo `return` przerwie egzekucję kodu jeśli warunek zostanie spełniony","created_at":"2018-10-22T19:48:24Z","updated_at":"2018-10-22T19:48:24Z","html_url":"https://github.com/mikolajGon/tic_tac_toe/pull/1#discussion_r227112943","pull_request_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/comments/227112943"},"html":{"href":"https://github.com/mikolajGon/tic_tac_toe/pull/1#discussion_r227112943"},"pull_request":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1","id":224615418,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0NjE1NDE4","html_url":"https://github.com/mikolajGon/tic_tac_toe/pull/1","diff_url":"https://github.com/mikolajGon/tic_tac_toe/pull/1.diff","patch_url":"https://github.com/mikolajGon/tic_tac_toe/pull/1.patch","issue_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/1","number":1,"state":"open","locked":false,"title":"Working branch","user":{"login":"mikolajGon","id":42517694,"node_id":"MDQ6VXNlcjQyNTE3Njk0","avatar_url":"https://avatars2.githubusercontent.com/u/42517694?v=4","gravatar_id":"","url":"https://api.github.com/users/mikolajGon","html_url":"https://github.com/mikolajGon","followers_url":"https://api.github.com/users/mikolajGon/followers","following_url":"https://api.github.com/users/mikolajGon/following{/other_user}","gists_url":"https://api.github.com/users/mikolajGon/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolajGon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolajGon/subscriptions","organizations_url":"https://api.github.com/users/mikolajGon/orgs","repos_url":"https://api.github.com/users/mikolajGon/repos","events_url":"https://api.github.com/users/mikolajGon/events{/privacy}","received_events_url":"https://api.github.com/users/mikolajGon/received_events","type":"User","site_admin":false},"body":"Hey,\r\n\r\nplease review:\r\ngame.js\r\nboard.js\r\nplayer.js\r\nfield.js","created_at":"2018-10-22T08:23:18Z","updated_at":"2018-10-22T19:48:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"611c230c5563d72d5c9326d0b0284787b0cd5af2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1/commits","review_comments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1/comments","review_comment_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/1/comments","statuses_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/statuses/963ef060c1a6726ca87f079689134ece78fdc7fb","head":{"label":"mikolajGon:working_branch","ref":"working_branch","sha":"963ef060c1a6726ca87f079689134ece78fdc7fb","user":{"login":"mikolajGon","id":42517694,"node_id":"MDQ6VXNlcjQyNTE3Njk0","avatar_url":"https://avatars2.githubusercontent.com/u/42517694?v=4","gravatar_id":"","url":"https://api.github.com/users/mikolajGon","html_url":"https://github.com/mikolajGon","followers_url":"https://api.github.com/users/mikolajGon/followers","following_url":"https://api.github.com/users/mikolajGon/following{/other_user}","gists_url":"https://api.github.com/users/mikolajGon/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolajGon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolajGon/subscriptions","organizations_url":"https://api.github.com/users/mikolajGon/orgs","repos_url":"https://api.github.com/users/mikolajGon/repos","events_url":"https://api.github.com/users/mikolajGon/events{/privacy}","received_events_url":"https://api.github.com/users/mikolajGon/received_events","type":"User","site_admin":false},"repo":{"id":154026481,"node_id":"MDEwOlJlcG9zaXRvcnkxNTQwMjY0ODE=","name":"tic_tac_toe","full_name":"mikolajGon/tic_tac_toe","private":false,"owner":{"login":"mikolajGon","id":42517694,"node_id":"MDQ6VXNlcjQyNTE3Njk0","avatar_url":"https://avatars2.githubusercontent.com/u/42517694?v=4","gravatar_id":"","url":"https://api.github.com/users/mikolajGon","html_url":"https://github.com/mikolajGon","followers_url":"https://api.github.com/users/mikolajGon/followers","following_url":"https://api.github.com/users/mikolajGon/following{/other_user}","gists_url":"https://api.github.com/users/mikolajGon/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolajGon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolajGon/subscriptions","organizations_url":"https://api.github.com/users/mikolajGon/orgs","repos_url":"https://api.github.com/users/mikolajGon/repos","events_url":"https://api.github.com/users/mikolajGon/events{/privacy}","received_events_url":"https://api.github.com/users/mikolajGon/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mikolajGon/tic_tac_toe","description":"tic tac toe game with AI","fork":false,"url":"https://api.github.com/repos/mikolajGon/tic_tac_toe","forks_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/forks","keys_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/teams","hooks_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/hooks","issue_events_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/events{/number}","events_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/events","assignees_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/assignees{/user}","branches_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/branches{/branch}","tags_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/tags","blobs_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/statuses/{sha}","languages_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/languages","stargazers_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/stargazers","contributors_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/contributors","subscribers_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/subscribers","subscription_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/subscription","commits_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/contents/{+path}","compare_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/merges","archive_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/downloads","issues_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues{/number}","pulls_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls{/number}","milestones_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/milestones{/number}","notifications_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/labels{/name}","releases_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/releases{/id}","deployments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/deployments","created_at":"2018-10-21T16:03:16Z","updated_at":"2018-10-21T16:03:19Z","pushed_at":"2018-10-22T08:23:20Z","git_url":"git://github.com/mikolajGon/tic_tac_toe.git","ssh_url":"git@github.com:mikolajGon/tic_tac_toe.git","clone_url":"https://github.com/mikolajGon/tic_tac_toe.git","svn_url":"https://github.com/mikolajGon/tic_tac_toe","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"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,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mikolajGon:master","ref":"master","sha":"66d391e9162af8c6a8c851d73e15a0cfdfd1bb79","user":{"login":"mikolajGon","id":42517694,"node_id":"MDQ6VXNlcjQyNTE3Njk0","avatar_url":"https://avatars2.githubusercontent.com/u/42517694?v=4","gravatar_id":"","url":"https://api.github.com/users/mikolajGon","html_url":"https://github.com/mikolajGon","followers_url":"https://api.github.com/users/mikolajGon/followers","following_url":"https://api.github.com/users/mikolajGon/following{/other_user}","gists_url":"https://api.github.com/users/mikolajGon/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolajGon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolajGon/subscriptions","organizations_url":"https://api.github.com/users/mikolajGon/orgs","repos_url":"https://api.github.com/users/mikolajGon/repos","events_url":"https://api.github.com/users/mikolajGon/events{/privacy}","received_events_url":"https://api.github.com/users/mikolajGon/received_events","type":"User","site_admin":false},"repo":{"id":154026481,"node_id":"MDEwOlJlcG9zaXRvcnkxNTQwMjY0ODE=","name":"tic_tac_toe","full_name":"mikolajGon/tic_tac_toe","private":false,"owner":{"login":"mikolajGon","id":42517694,"node_id":"MDQ6VXNlcjQyNTE3Njk0","avatar_url":"https://avatars2.githubusercontent.com/u/42517694?v=4","gravatar_id":"","url":"https://api.github.com/users/mikolajGon","html_url":"https://github.com/mikolajGon","followers_url":"https://api.github.com/users/mikolajGon/followers","following_url":"https://api.github.com/users/mikolajGon/following{/other_user}","gists_url":"https://api.github.com/users/mikolajGon/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolajGon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolajGon/subscriptions","organizations_url":"https://api.github.com/users/mikolajGon/orgs","repos_url":"https://api.github.com/users/mikolajGon/repos","events_url":"https://api.github.com/users/mikolajGon/events{/privacy}","received_events_url":"https://api.github.com/users/mikolajGon/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mikolajGon/tic_tac_toe","description":"tic tac toe game with AI","fork":false,"url":"https://api.github.com/repos/mikolajGon/tic_tac_toe","forks_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/forks","keys_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/teams","hooks_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/hooks","issue_events_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/events{/number}","events_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/events","assignees_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/assignees{/user}","branches_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/branches{/branch}","tags_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/tags","blobs_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/statuses/{sha}","languages_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/languages","stargazers_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/stargazers","contributors_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/contributors","subscribers_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/subscribers","subscription_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/subscription","commits_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/contents/{+path}","compare_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/merges","archive_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/downloads","issues_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues{/number}","pulls_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls{/number}","milestones_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/milestones{/number}","notifications_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/labels{/name}","releases_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/releases{/id}","deployments_url":"https://api.github.com/repos/mikolajGon/tic_tac_toe/deployments","created_at":"2018-10-21T16:03:16Z","updated_at":"2018-10-21T16:03:19Z","pushed_at":"2018-10-22T08:23:20Z","git_url":"git://github.com/mikolajGon/tic_tac_toe.git","ssh_url":"git@github.com:mikolajGon/tic_tac_toe.git","clone_url":"https://github.com/mikolajGon/tic_tac_toe.git","svn_url":"https://github.com/mikolajGon/tic_tac_toe","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"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,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1"},"html":{"href":"https://github.com/mikolajGon/tic_tac_toe/pull/1"},"issue":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/1"},"comments":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/mikolajGon/tic_tac_toe/statuses/963ef060c1a6726ca87f079689134ece78fdc7fb"}},"author_association":"OWNER"}}
{"actor":{"display_login":"cezaryB"}}