-
Notifications
You must be signed in to change notification settings - Fork 0
Checkpoint1 towers #7
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
d38165d
ec7127b
32a0a00
5ff550a
6104136
b2c2b78
0b6fef4
0ac0894
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,26 +19,54 @@ function printStacks() { | |
| console.log("c: " + stacks.c); | ||
| } | ||
|
|
||
| function movePiece() { | ||
| // Your code here | ||
| // RUBRIC | ||
| // Move piece from stack to stack 17 | ||
| // Working is legal function 17 | ||
| // Working check for win function 17 | ||
| // Working reset function 17 | ||
| // Clean PR , es6 syntax/linting 8 | ||
| // Function plan in comments (each function has a stated purpose and method) 16 | ||
| // At least 2 tests 8 | ||
|
|
||
| } | ||
| // es6 notation fat arrow everything//const everything | ||
|
|
||
| function isLegal() { | ||
| // Your code here | ||
| // movePiece should use array method and dot method to select last index and grab it through push and pop | ||
| const movePiece = (startStack, endStack) => { | ||
| stacks[endStack].push(stacks[startStack].pop()); | ||
| } | ||
|
|
||
| // Hierarchy of logic, if the stack has nothing in it, legal move, else the starting index popped should be less then the pop of the end stack. Or else move will not work. | ||
| const isLegal = (startStack, endStack) => { | ||
| if (stacks[endStack].length === 0) { | ||
|
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. What happens if the startStack is empty? |
||
| return true; | ||
| } else if (stacks[startStack].pop() < stacks[endStack].pop()) { | ||
|
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. .pop() changes the array, we just want to check the value of the last item in the stack if there is one ( array[array.length - 1] ). |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function checkForWin() { | ||
| // Your code here | ||
|
|
||
| // checkforwin should use dot method in if statement, legal function should protect argument from c having out of order values. | ||
| // length of c === 4 should result in win | ||
| const checkForWin = () => { | ||
| if (stacks.c.length === 4) { | ||
| console.log('Winner, Winner, Chicken Dinner!!'); | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function towersOfHanoi(startStack, endStack) { | ||
| // Your code here | ||
|
|
||
| // use previous functions to put game together | ||
| // if move function is valid run call back legal function, if nothing else run win function. | ||
| const towersOfHanoi = (startStack, endStack) => { | ||
| if (movePiece(startStack, endStack)) { | ||
|
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. movePiece() doesn't check anything, it moves pieces. Here, you're moving the pieces, and since movePiece will return undefines, isLegal won't even run. |
||
| isLegal(startStack, endStack) | ||
| } | ||
| checkForWin(); | ||
| } | ||
|
|
||
|
|
||
| function getPrompt() { | ||
| printStacks(); | ||
| rl.question('start stack: ', (startStack) => { | ||
|
|
@@ -52,3 +80,28 @@ function getPrompt() { | |
| getPrompt(); | ||
|
|
||
|
|
||
| // Moving stack should be from (a,c) should end a: 4,3,2 | b: | c: 1 | ||
| describe('#towersOfHanoi()', () => { | ||
| it('should be able to move a block', () => { | ||
| towersOfHanoi('a', 'c'); | ||
| assert.deepEqual(stacks, { a: [4, 3, 2], b: [], c: [1] }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#checkForWin()', () => { | ||
| it('should recognize a win', () => { | ||
| let stacks = { | ||
| a: [], | ||
| b: [], | ||
| c: [4,3,2,1] | ||
| }; | ||
| assert.equal(checkForWin(), true); | ||
| }); | ||
| }); | ||
|
|
||
| // Test for legal move where [startStack] < [endStack] where a larger number cant follow a smaller number | ||
| // Win function recognizing key c = 4,3,2,1 printing 'YOU WIN!' | ||
| // guard against random letters and redundancies | ||
| // checking against different data type | ||
| // Moving stack should be from (a,c) should end a: 4,3,2 | b: | c: 1 | ||
| // top disc | ||
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Very concise!