Skip to content

Checkpoint1 towers#7

Open
shayhoffman wants to merge 5 commits intogh-pagesfrom
checkpoint1-towers
Open

Checkpoint1 towers#7
shayhoffman wants to merge 5 commits intogh-pagesfrom
checkpoint1-towers

Conversation

@shayhoffman
Copy link
Owner

checkpoint 1: Towers of Hannoi

//the above movePiece function just makes the game functional, and lets you move pieces around. It allows for the removal of the last item in the first array, or the array you want to pull from (or startStack, in this case), through popping it off the end, and pushing it to the endStack, which could be stack b or c (or a, depending on what stack you're trying to move to/from). However, this function does not ensure legality of moves or order in the arrays. It simply allows the user to pop the last value off their targeted array and move it into a different array (or stack, in this case).

const validIput = (startStack, endStack) => {
if ((startStack === 'a') && (endStack === 'b' || endStack === 'c')) {

Choose a reason for hiding this comment

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

this can be simplified

let movingPieceValue = stacks[startStack][stacks[startStack].length - 1];
let endPieceValue = stacks[endStack][stacks[endStack].length - 1];

if ((movingPieceValue < endPieceValue) || (stacks[endStack].length === 0)) {

Choose a reason for hiding this comment

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

this too can be simplified

function towersOfHanoi(startStack, endStack) {
// Your code here
const checkForWin = () => {
if (stacks.c.length === 4) {

Choose a reason for hiding this comment

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

simplify. Just return the evaluation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants