Skip to content

chrsmys/TowersOfHanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

================== Demo

alt tag

================== How to Play


1.Tap the peg with the desired disk to move.
2.Then tap the peg of the desired disk position.
3.Tap the background at any point to autosolve.
Note: Autosolve may take a couple of seconds for the correct moves to be processed

================== About

This game was created with Spritekit and is a basic implementation of towers of hanoi. This project was a spike exercise where I researched the breadth first search algorithm.


step 0:This algorithm starts by adding the current state of the game to an empty queue. (We will call this queue stateQueue).
step 1:Take off the state(currentState) from the top of stateQueue and create every possible state that could come after it (nextStateList).
/*
All Possible Moves
from:peg1 to:peg2
from:peg1 to:peg3
from:peg2 to:peg1
from:peg2 to:peg3
from:peg3 to:peg1
from:peg3 to:peg2
*/
Step 3: Eliminate any states inside of nextStateList that are not possible. EX. Pegs with no disks cannot move a disk from it.
Step 4: Check if any states inside of nextStateList are the solution (All disks on peg3). If one of the states is the solution then the problem is solved. If none of the states in nextStateList are the solution then add all of the sates to stateQueue and then jump back up to step 1:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published