Skip to content
Open
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
35 changes: 30 additions & 5 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,49 @@ function printStacks() {
console.log("c: " + stacks.c);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing readme code plan file, but i will take the comments for part of it.

function movePiece() {
function movePiece(startStack, endStack) {
// Your code here

//moving one piece to another postion/array
let moveStack = stacks[startStack]
let twoStack = stacks[endStack]
let piece = moveStack.pop(); // piece equals the last index of the choosen array
twoStack.push(piece); // twoStack is pushing the piece to the array that was choosen
//twoStack.push(moveStack.pop())
console.log(piece)
}

function isLegal() {
function isLegal(startStack, endStack) {
// Your code here
let moveStack = stacks[startStack] // stacks a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows moving from an empty stack

let twoStack = stacks[endStack] //stack b
let moveStackPiece = moveStack[moveStack.length - 1] // stack at "a" will be the last index
let twoStackPiece = twoStack[twoStack.length -1] // stack at "b" will be the last index
console.log(twoStackPiece,"twostackpiece")
//When moving a piece to a postion that is blank the computer does know no less the postion is undefined
if(moveStackPiece < twoStackPiece || twoStackPiece == undefined){
return true
}
else{
return false
}

}

function checkForWin() {
// Your code here

if(stacks.b.length === 4){
return true;
}
else{
return false;
}
}

function towersOfHanoi(startStack, endStack) {
// Your code here

if (isLegal(startStack, endStack)){
movePiece(startStack, endStack);
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing additional tests

function getPrompt() {
Expand Down