-
Notifications
You must be signed in to change notification settings - Fork 447
Expand file tree
/
Copy pathreadme
More file actions
61 lines (52 loc) · 1.14 KB
/
readme
File metadata and controls
61 lines (52 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function movePiece(startStack, endStack) {
// Your code here, gives the move a variable
let currentPiece = stacks[startStack].pop();
// add current piece to end stack
stacks[endStack].push(currentPiece)
}
function isLegal(startStack, endStack) {
// need to add something it can check
const legalMove = ["a", "b", "c"];
if(legalMove.includes(startStack) == false || legalMove.includes(endStack) == false)
{
return false;
}
//empty stack means move is legal
if(stacks[endStack].length == 0)
{
return true;
}
//if piece is larger move is legal
else if(stacks[startStack].slice(-1) < stacks[endStack].slice(-1))
{
return true;
}
else
{
return false;
}
}
function checkForWin(startStack, endStack) {
// checking to win
if( stacks.b.length === 4 || stacks.c.length === 4)
{
console.log("You've won!!!!")
return true;
}
else
{
return false;
}
}
function towersOfHanoi(startStack, endStack) {
// Your code here
if(isLegal(startStack, endStack) == true)
{
movePiece(startStack, endStack)
}
else
{
console.log("YOU SHALL NOT PASS!!")
}
checkForWin();
}