From 41254f56428fd770dffd69e3f776803380cece5b Mon Sep 17 00:00:00 2001 From: Olena Reukova Date: Tue, 20 Dec 2022 18:17:37 +0000 Subject: [PATCH 1/5] move maker added function validateMove(move, board) for validation of numbers and free space --- move-maker.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/move-maker.js b/move-maker.js index b462350..e8d8b56 100644 --- a/move-maker.js +++ b/move-maker.js @@ -16,10 +16,30 @@ ]; */ function validateMove(move, board) { - // Implement this at the end if you have time, otherwise you can help your teammates! + // Implement this at the end if you have time, otherwise you can help your teammates! + if (move[0] !== "1" || move[0] !== "2" || move[0] !== "3") { + console.log("Try again..."); + return false; + } else if (move[2] !== "1" || move[2] !== "2" || move[2] !== "3") { + console.log("Try again..."); + return false; + } else if (move[1] !== ",") { + console.log("Try again..."); + return false; + } + return true; +} +// clean version validateMove +/* +function validateMove(move, board){ + if(move.length !=3 || move[0]<'1' || move[0]>'3' || move[2]<'1' || move[2]>'3' || move[1] !==',' || board [move[0]-1][move[2]-1] !=='_'){ + console.log('Try again...'); + return false; + } return true; } + /* Given 3 parameters: - a board (an array of arrays) @@ -32,5 +52,5 @@ function validateMove(move, board) { - Return true */ export function makeMove(board, move, player) { - return false; + return false; } From e2db4eb5ce172ef432811ac69d797075cb671330 Mon Sep 17 00:00:00 2001 From: Olena Reukova Date: Tue, 20 Dec 2022 18:18:51 +0000 Subject: [PATCH 2/5] board -printer changed values in array of array by using indexes --- board-printer.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/board-printer.js b/board-printer.js index e11a262..1f34e29 100644 --- a/board-printer.js +++ b/board-printer.js @@ -15,13 +15,36 @@ ================= Test your function by calling it with an example tic-tac-toe board. */ -export function printBoard(board) { -} + +let board = [ + ["X", "0", "X"], + ["X", "0", "X"], + ["0", "X", "0"], +]; +console.log(board); + +// we change 'X' into '_' in the first row and second column place (index [0][1] in array) +board[0][1] = "_"; +// we change 'X' into '_' in the first row and third column place (index [0][2] in array) +board[0][2] = "_"; +// we change 'X' into '_' in the second row and first column place (index [1][0] in array) +board[1][0] = "_"; +// we change '0' into 'X' in the second row and second column place (index [1][1] in array) +board[1][1] = "X"; +// we change 'X' into '_' in the second row and third column place (index [1][2] in array) +board[1][2] = "_"; +// we change 'X' into '0' in the third row and second column place (index [2][1] in array) +board[2][1] = "0"; +// we change '0' into 'X' in the third row and third column place (index [2][2] in array) +board[2][2] = "X"; + +console.log(board); + +export function printBoard(board) {} /* Given a tic-tac-toe board (an array of arrays), - return true if there are no moves left to make (there are no more '_' values) - return false if there are still moves that can be made */ -export function checkIfNoMovesLeft(board) { -} +export function checkIfNoMovesLeft(board) {} From 691a94752cb5efec24652a5ca19b08b01cb728da Mon Sep 17 00:00:00 2001 From: Farnoosh <91014204+Farnooshmo@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:16:09 +0000 Subject: [PATCH 3/5] should be checked --- board-printer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board-printer.js b/board-printer.js index 1f34e29..8c2e941 100644 --- a/board-printer.js +++ b/board-printer.js @@ -15,7 +15,7 @@ ================= Test your function by calling it with an example tic-tac-toe board. */ - +//It needs to be checked let board = [ ["X", "0", "X"], ["X", "0", "X"], From b6dac3201bc0004dde0e9fa2c35eb462855d88e5 Mon Sep 17 00:00:00 2001 From: Inna Poliakova Date: Thu, 12 Jan 2023 20:41:50 +0000 Subject: [PATCH 4/5] Update status-checker.js --- status-checker.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/status-checker.js b/status-checker.js index 7df4962..d3a9fbf 100644 --- a/status-checker.js +++ b/status-checker.js @@ -18,8 +18,15 @@ import { checkIfNoMovesLeft } from './board-printer.js'; Otherwise, return false */ function checkRow(board, player, rowNumber) { + + for (let rowNumber of board) { + if ((board[rowNumber] === 0 && board[rowNumber] === player) + && (board[rowNumber] === 1 && board[rowNumber] === player) + && (board[rowNumber] === 2 && board[rowNumber] === player)) { + return true; + } return false; +} } - /* Given 3 parameters: - a tic-tac-toe board (array of arrays) @@ -29,8 +36,14 @@ function checkRow(board, player, rowNumber) { Otherwise, return false */ function checkColumn(board, player, columnNumber) { + for (let columnNumber of board) { + if ((board[columnNumber] === 0 && board[columnNumber] === player) + && (board[columnNumber] === 1 && board[columnNumber] === player) + && (board[columnNumber] === 2 && board[columnNumber] === player)) { + return true; + } return false; +} } - /* Given 2 parameters: - a tic-tac-toe board (array of arrays) @@ -40,9 +53,20 @@ function checkColumn(board, player, columnNumber) { */ function checkDiagonal(board, player) { // It may be easier to use an if statement than a loop here + if ( + board[0][0] === player && + board[1][1] === player && + board[2][2] === player || + board[0][2] === player && + board[1][1] === player && + board[2][0] === player + ) { + return true; + } else { + return false; + } } - /* There is no need to change any code below this line. */ From 11470c2391b8cde4e02ae6e8c3102ff973da65af Mon Sep 17 00:00:00 2001 From: Farnoosh <91014204+Farnooshmo@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:14:50 +0000 Subject: [PATCH 5/5] Update board-printer.js --- board-printer.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/board-printer.js b/board-printer.js index 8c2e941..916a18d 100644 --- a/board-printer.js +++ b/board-printer.js @@ -40,11 +40,27 @@ board[2][2] = "X"; console.log(board); -export function printBoard(board) {} +export function printBoard(board) { + for(let i = 0; i < board.length; i++){ + console.log(board[i].join(" | ")); + if(i !== board.length - 1){ + console.log("================="); + } + } +} /* Given a tic-tac-toe board (an array of arrays), - return true if there are no moves left to make (there are no more '_' values) - return false if there are still moves that can be made */ -export function checkIfNoMovesLeft(board) {} +export function checkIfNoMovesLeft(board) { + for(let i = 0; i < board.length; i++){ + for(let j = 0; j < board[i].length; j++){ + if(board[i][j] === '_'){ + return false; + } + } + } + return true; +}