Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Your checkpoint is really a terminal app; which is what you'll be graded on. However, you should push to use the DOM and create a GUI for this game.

## Checklist

<!--Santize inputs and use the correct notation -->
<!-- This is for their personal navigation through the project. They can go through and make sure they get each thing and can comb over it later. -->

1. 20pts - **Code Plan** - Include this in a `README.md` file in your folder with comments in your code
Expand Down
59 changes: 55 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,86 @@ const printStacks = () => {
}

// Next, what do you think this function should do?
const movePiece = () => {
const movePiece = (x,y) => {
if(isLegal(x,y)){
// console.log(stacks[x],stacks[y])//had issue with dot notation being undefined
stacks[y].push(stacks[x].pop())
// console.log(stacks)
// Your code here
}
else{

}

}

// Before you move, should you check if the move it actually allowed? Should 3 be able to be stacked on 2
const isLegal = () => {
const isLegal = (x,y) => {
//first test is x's stack is not empty then check for size of object being moved
//changed first test is actually for checking for correct inputs
if((x==="a"||x==="b"||x==="c")&&(y==="a"||y==="b"||y==="c")){
if(stacks[x][0]===undefined){
return false
}
else if(stacks[x][stacks[x].length-1]>stacks[y][stacks[y].length-1]){
return false
}
else{
return true
}
}
else{
return false
}
// Your code here
//i should not be also be able to pop from an empty array and not be able to stack a larger number to a smaller one

}

// What is a win in Towers of Hanoi? When should this function run?
//it should run after you move
const checkForWin = () => {
let arr="4,3,2,1"
// console.log(stacks.b.toString())
if(stacks.b.toString()==arr){
return true;
}
else if(stacks.c.toString()==arr){
return true
}
else{
return false
}
// Your code here

}

// When is this function called? What should it do with its argument?
const towersOfHanoi = (startStack, endStack) => {
// Your code here

movePiece(startStack,endStack)
// checkForWin();
}

const getPrompt = () => {
printStacks();
rl.question('start stack: ', (startStack) => {
rl.question('end stack: ', (endStack) => {
towersOfHanoi(startStack, endStack);
getPrompt();
if(checkForWin()){
printStacks();
console.log("You Won")
console.log("Play Again? Or Exit with Ctrl-C")
stacks = {
a: [4, 3, 2, 1],
b: [],
c: []
};
getPrompt();
}
else{
getPrompt();
}
});
});
}
Expand Down