From fcfd9c3583062c085028745e80628d154511b04a Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:44:38 -0500 Subject: [PATCH 1/6] asdf --- players/4/index.mjs | 154 +++++++++++++++++++++++++++++++++++++++++++- players/4/test.mjs | 3 + 2 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 players/4/test.mjs diff --git a/players/4/index.mjs b/players/4/index.mjs index f9ac453..10f4b47 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -3,7 +3,7 @@ */ export default class Player { static get name () { - return `Andy is Awesome`; + return `Team 4 rules`; } /** @@ -28,7 +28,155 @@ export default class Player { * 6 | 7 | 8 */ static makeMove(token, gameState) { - // Just pick the first open square. - return gameState.indexOf('-'); + let move; + + let antitoken; + if (token === 'X') { + antitoken = 'O' + } else { + antitoken = 'X' + } + + for (let item of gameState) { + if (gameState[item] === '-') { + neighborObject[item].forEach(neighbor => { + if (gameState[neighbor] == token) { + move = Number(item) + } + }) + } + } + + if (checkForDiagonalVic(antitoken, gameState)) { + move = checkForDiagonalVic(antitoken, gameState) + } + if (checkForHorizVic(antitoken, gameState)) { + move = checkForHorizVic(antitoken, gameState) + } + if (checkForVertVic(antitoken, gameState)) { + move = checkForVertVic(antitoken, gameState) + } + + if (checkForDiagonalVic(token, gameState)) { + move = checkForDiagonalVic(token, gameState) + } + if (checkForHorizVic(token, gameState)) { + move = checkForHorizVic(token, gameState) + } + if (checkForVertVic(token, gameState)) { + move = checkForVertVic(token, gameState) + } + + return move || gameState.indexOf('-'); } }; + +const neighborObject = { + '0': ['1','3','4'], + '1': ['0', '2', '3', '4', '5'], + '2': ['1', '4', '5'], + '3': ['0', '1', '4', '6', '7'], + '4': ['0', '1', '2', '3', '4', '5', '6', '7', '8'], + '5': ['1', '2', '4', '7', '8'], + '6': ['3', '4', '7'], + '7': ['3', '4', '5', '6', '8'], + '8': ['4', '5', '7'], +} + +// tokenObject = { +// '0': 0, +// '1': 0, +// '2': 0, +// '3': 0, +// '4': 0, +// '5': 0, +// '6': 0, +// '7': 0, +// '8': 0, +// } + +function checkForDiagonalVic(token, gameState) { + if (gameState[0] === token && gameState[4] === token) { + return 8; + } + if (gameState[0] === token && gameState[8] === token) { + return 4; + } + if (gameState[4] === token && gameState[8] === token) { + return 0; + } + + if (gameState[2] === token && gameState[4] === token) { + return 6; + } + if (gameState[2] === token && gameState[6] === token) { + return 4; + } + if (gameState[4] === token && gameState[6] === token) { + return 2; + } +} + +function checkForHorizVic(token, gameState) { + if (gameState[0] === token && gameState[1] === token) { + return 2; + } + if (gameState[0] === token && gameState[2] === token) { + return 1; + } + if (gameState[1] === token && gameState[2] === token) { + return 0; + } + + if (gameState[3] === token && gameState[4] === token) { + return 5; + } + if (gameState[3] === token && gameState[5] === token) { + return 4; + } + if (gameState[4] === token && gameState[5] === token) { + return 3; + } + + if (gameState[6] === token && gameState[7] === token) { + return 8; + } + if (gameState[6] === token && gameState[8] === token) { + return 7; + } + if (gameState[7] === token && gameState[8] === token) { + return 6; + } +} + +function checkForVertVic(token, gameState) { + if (gameState[0] === token && gameState[3] === token) { + return 6; + } + if (gameState[0] === token && gameState[6] === token) { + return 3; + } + if (gameState[3] === token && gameState[6] === token) { + return 0; + } + + if (gameState[1] === token && gameState[4] === token) { + return 7; + } + if (gameState[1] === token && gameState[7] === token) { + return 4; + } + if (gameState[4] === token && gameState[7] === token) { + return 1; + } + + if (gameState[2] === token && gameState[5] === token) { + return 8; + } + if (gameState[5] === token && gameState[8] === token) { + return 2; + } + if (gameState[2] === token && gameState[8] === token) { + return 5; + } +} \ No newline at end of file diff --git a/players/4/test.mjs b/players/4/test.mjs new file mode 100644 index 0000000..dab9cff --- /dev/null +++ b/players/4/test.mjs @@ -0,0 +1,3 @@ +import Player from './index'; + +Player.makeMove('X', ['-', '-', '-', '-', '-', '-', '-', '-', '-']) \ No newline at end of file From b073b339ffcf79d5bf4f1b95c23a9578f8d0b55e Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:49:10 -0500 Subject: [PATCH 2/6] asdf --- players/4/index.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/players/4/index.mjs b/players/4/index.mjs index 10f4b47..7309f8c 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -37,16 +37,16 @@ export default class Player { antitoken = 'X' } - for (let item of gameState) { - if (gameState[item] === '-') { - neighborObject[item].forEach(neighbor => { + gameState.forEach((item, index) => { + if (gameState[index] === '-') { + neighborObject[index].forEach(neighbor => { if (gameState[neighbor] == token) { - move = Number(item) + move = Number(index) } }) } - } - + }) + if (checkForDiagonalVic(antitoken, gameState)) { move = checkForDiagonalVic(antitoken, gameState) } @@ -67,6 +67,8 @@ export default class Player { move = checkForVertVic(token, gameState) } + console.log(move) + return move || gameState.indexOf('-'); } }; From 5ad3bf77d84ae86c6dc8a5b90d45fff8c0903b2b Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:49:43 -0500 Subject: [PATCH 3/6] Asdf --- players/4/index.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/players/4/index.mjs b/players/4/index.mjs index 7309f8c..9398d67 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -67,8 +67,6 @@ export default class Player { move = checkForVertVic(token, gameState) } - console.log(move) - return move || gameState.indexOf('-'); } }; From b4c7ce9f44c0d3c2fac51076bec8f472aea53c49 Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:55:31 -0500 Subject: [PATCH 4/6] Asdfasdf --- players/4/index.mjs | 3 ++- players/4/test.mjs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/players/4/index.mjs b/players/4/index.mjs index 9398d67..1b1decf 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -38,7 +38,8 @@ export default class Player { } gameState.forEach((item, index) => { - if (gameState[index] === '-') { + // console.log(index) + if (item === '-') { neighborObject[index].forEach(neighbor => { if (gameState[neighbor] == token) { move = Number(index) diff --git a/players/4/test.mjs b/players/4/test.mjs index dab9cff..7626d59 100644 --- a/players/4/test.mjs +++ b/players/4/test.mjs @@ -1,3 +1,3 @@ import Player from './index'; -Player.makeMove('X', ['-', '-', '-', '-', '-', '-', '-', '-', '-']) \ No newline at end of file +Player.makeMove('X', ['X', '-', '-', '-', '-', '-', '-', '-', '-']) \ No newline at end of file From 5cd06200485ec43583084082bbbde20d86e26f45 Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:56:25 -0500 Subject: [PATCH 5/6] asdf --- players/4/index.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/players/4/index.mjs b/players/4/index.mjs index 1b1decf..4028edb 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -37,6 +37,10 @@ export default class Player { antitoken = 'X' } + if (gameState[4] === '-') { + move = 4; + } + gameState.forEach((item, index) => { // console.log(index) if (item === '-') { From 6001aa84245c41d530e31d959bc9ecc1d48f34dd Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Fri, 28 Sep 2018 15:57:47 -0500 Subject: [PATCH 6/6] Asdf --- players/4/index.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/players/4/index.mjs b/players/4/index.mjs index 4028edb..e50f249 100644 --- a/players/4/index.mjs +++ b/players/4/index.mjs @@ -42,7 +42,6 @@ export default class Player { } gameState.forEach((item, index) => { - // console.log(index) if (item === '-') { neighborObject[index].forEach(neighbor => { if (gameState[neighbor] == token) {