-
Notifications
You must be signed in to change notification settings - Fork 0
Class5tictactoe #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,26 +23,66 @@ function printBoard() { | |
| console.log('2 ' + board[2].join(' | ')); | ||
| } | ||
|
|
||
| function horizontalWin() { | ||
| // Your code here | ||
| // Check for winning horizontal with if | ||
| // 00 01 02 | ||
| // 10 11 12 | ||
| // 20 21 22 | ||
| const horizontalWin = () => { | ||
| if ((board[0][0] === board[0][1] && board[0][1] === board[0][2]) || (board[1][0] === board[1][1] && board[1][1] === board[1][2]) || (board[2][0] === board[2][1] && | ||
| board[2][1] === board[2][2])) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| function verticalWin() { | ||
| // Your code here | ||
| //Check for winning vertical with if | ||
| //00 10 20 | ||
| //01 11 21 | ||
| //02 12 22 | ||
| const verticalWin = () => { | ||
| if ((board[0][0] === board[1][0] && board[1][0] === board[2][0]) || (board[0][1] === board[1][1] && board[1][1] === board[2][1]) || (board[0][2] === board[1][2] && | ||
| board[1][2] === board[2][2])) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| function diagonalWin() { | ||
| // Your code here | ||
| // Check for winning diagonalWin with if | ||
| // 00 11 22 | ||
| // 02 11 20 | ||
| const diagonalWin = () => { | ||
| if (board[0][0] === board[1][1] && board[1][1] === board[2][2] || (board[0][2] === board[1][1] && board[1][1] === board[2][0])) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| function checkForWin() { | ||
| // Your code here | ||
| // Got help from eddy, I do not completely understand yet | ||
| const checkForWin = () => { | ||
| // if (horizontalWin() || verticalWin() || diagonalWin()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do it! This logic is correct, keep going! Just ignore the turncount thing, and if you look at the tests below, they expect checkForWin() to return either true or false. |
||
| // console.log(`Player ${playerTurn} Wins!`); | ||
| // } else if (turnCount === 9) { | ||
| // console.log("It's a tie!") | ||
| // } else { | ||
| // return false; | ||
| //} | ||
|
|
||
| } | ||
|
|
||
| // Got help from eddy, I do not completely understand yet | ||
| function ticTacToe(row, column) { | ||
| // Your code here | ||
| // | ||
| // if (playerTurn === 'X') { | ||
| // playerTurn = 'O'; | ||
| // } else { | ||
| // playerTurn = 'X'; | ||
| // } | ||
| // if (board[row][column] === ' ') { | ||
| // board[row].splice(column, 1, playerTurn); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using unnecessary methods, set that value = to playerTurn. |
||
| // } | ||
| // return false; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| function getPrompt() { | ||
| printBoard(); | ||
| console.log("It's Player " + playerTurn + "'s turn."); | ||
|
|
@@ -68,7 +108,7 @@ if (typeof describe === 'function') { | |
| }); | ||
| it('should alternate between players', () => { | ||
| ticTacToe(0, 0); | ||
| assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); | ||
| assert.deepEqual(board, [ ['O', '', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put the space back! The tests need it! (In board[0][1], I think you accidentally took it out). |
||
| }); | ||
| it('should check for vertical wins', () => { | ||
| board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', 'X', ' '] ]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Yes yes! You got the short way to reference three cells. Nice work! I mean, SOLID work!