From fd6d2d6bc0c5f289b15d2a1263d73e4314d83d77 Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Sun, 14 Jun 2020 22:48:44 -0500 Subject: [PATCH 1/2] changes --- 03week/ticTacToe.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..8a68f3e4b 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -13,6 +13,7 @@ let board = [ ]; let playerTurn = 'X'; +let Otherplayer = 'O'; function printBoard() { console.log(' 0 1 2'); @@ -22,25 +23,49 @@ function printBoard() { console.log(' ---------'); console.log('2 ' + board[2].join(' | ')); } - +/* +*if a player won horizontally on any row, return true +*Otherwise return false +*/ function horizontalWin() { - // Your code here + if(board[0][1] === playerTurn) } - +/* +*if a player won vertically on any row, return true +*Otherwise return false +* +*/ function verticalWin() { // Your code here } +/* +*if a player won diagonally on any row, return true +*Otherwise return false + */ function diagonalWin() { // Your code here } - +// if they won H V D return true else return false function checkForWin() { - // Your code here + // code should call each check for types of wins } function ticTacToe(row, column) { - // Your code here + // check that row and column are valid(optional) + // check that row and column are empty(optional) + + //update the board + board[row][column] = playerTurn; + // + //check if they won? if they did print nice message, (optional) + //maybe clear board(optional) + // set the player turn to be the other player(still need to figure out how to swap) + + + + //code here should set marker on the board(CHECK) + // then check for win } function getPrompt() { From 398406e7d599796e8faa934f0c9b2fc00bde5a39 Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Thu, 18 Jun 2020 18:28:47 -0500 Subject: [PATCH 2/2] changes --- 03week/ticTacToe.js | 69 +++++++++++++++++++++++++++++++++++++++++++-- JS211_ArrayPractice | 1 + 2 files changed, 67 insertions(+), 3 deletions(-) create mode 160000 JS211_ArrayPractice diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 8a68f3e4b..4fb3fcf0b 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -2,6 +2,7 @@ const assert = require('assert'); const readline = require('readline'); +const { truncate } = require('fs'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout @@ -13,7 +14,7 @@ let board = [ ]; let playerTurn = 'X'; -let Otherplayer = 'O'; + function printBoard() { console.log(' 0 1 2'); @@ -28,8 +29,34 @@ function printBoard() { *Otherwise return false */ function horizontalWin() { - if(board[0][1] === playerTurn) -} + if(board[0][0] === "X" && board[0][1] === "X" && board[0][2] === "X"){ + return true + } else if (board[0][0] === "O" && board[0][1] === "O" && board[0][2] === "O"){ + return true + } else if (board[1][0] === "X" && board[1][1] === "X" && board[1][2] === "X"){ + return true + } else if(board[1][0] === "O" && board[1][1] === "O" && board[1][2] === "O"){ + return true + } else if(board[2][0] === "X" && board[2][1] === "X" && board[2][2] === "X"){ + return true + } else if(board[2][0] === "O" && board[2][1] === "O" && board[2][2] === "O"){ + return true + } else{ + return false + } + + } + + + + + + + + + + + /* *if a player won vertically on any row, return true *Otherwise return false @@ -37,6 +64,21 @@ function horizontalWin() { */ function verticalWin() { // Your code here + if(board[0][0] === "X" && board[1][0] === "X" && board[2][0] === "X"){ + return true + } else if (board[0][0] === "O" && board[1][0] === "O" && board[2][0] === "O"){ + return true + } else if (board[0][1] === "X" && board[1][1] === "X" && board[2][1] === "X"){ + return true + } else if(board[0][1] === "O" && board[1][1] === "O" && board[2][1] === "O"){ + return true + } else if(board[0][2] === "X" && board[1][2] === "X" && board[2][2] === "X"){ + return true + } else if(board[0][2] === "O" && board[1][2] === "O" && board[2][2] === "O"){ + return true + } else{ + return false + } } /* *if a player won diagonally on any row, return true @@ -45,10 +87,27 @@ function verticalWin() { function diagonalWin() { // Your code here + if(board[0][0] === "X" && board[1][1] === "X" && board[2][2] === "X"){ + return true + } else if (board[0][0] === "O" && board[1][1] === "O" && board[2][2] === "O"){ + return true + } else if(board[0][2] === "X" && board[1][1] === "X" && board[0][2] === "X"){ + return true + } else if (board[0][2] === "O" && board[1][1] === "O" && board[0][2] === "O"){ + return true + } else { + return false + } + } // if they won H V D return true else return false function checkForWin() { // code should call each check for types of wins + if(horizontalWin() == true || verticalWin() == true || diagonalWin == true ){ + return true + } else { + return false + } } function ticTacToe(row, column) { @@ -57,6 +116,10 @@ function ticTacToe(row, column) { //update the board board[row][column] = playerTurn; + if(playerTurn == "x") { + playerTurn = "O" + } + checkForWin() // //check if they won? if they did print nice message, (optional) //maybe clear board(optional) diff --git a/JS211_ArrayPractice b/JS211_ArrayPractice new file mode 160000 index 000000000..1e00855c6 --- /dev/null +++ b/JS211_ArrayPractice @@ -0,0 +1 @@ +Subproject commit 1e00855c6576c929c7efa4a62225a720d36dd08a