![]() ![]() ![]() We can use Zobrist hashing, according to Wikipedia, "Zobrist hashing is a hash function construction used in computer programs that play abstract board games, such as chess and Go, to implement transposition tables, a special kind of hash table that is indexed by a board position and used to avoid analyzing the same position more than once." Based on the current game state, if a block's position is changed, it only takes O(1) time to compute the next state, this is a huge win, and it is the key to boost the performance of the algorithm. The problem is it takes O(n²) time to compute the state, and it's really expensive, is there a better way? We can concatenate each block's position and type to form a string, or we can use the feature of JavaScript Number datatype to optimize the storage space, see this article. There are many different ways to represent the current state of the game. During the try, any duplicate state should be avoided.īreadth-first search in Klotski Zobrist hashing Basically, we start from the initial game state, try to move every block and generate the new game states, scan each new game state and see if the 2x2 block is at the desired position, if not, we will continue to try. It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbors. The directions code is as follows: down: 0īFS is an algorithm for traversing or searching tree or graph data structures. Position: is the initial position of the block, it uses zero-based numering.īoardSize: is the size of the game board.ĮscapePoint: is the destination point for block 0 to escape.Įach block's movement can also be restricted, for example, this will only allow the block to move up and down. The shape property defines the shape of the block, for example, means a horizontal block has 1 row and 2 columns, means a vertical block that has 3 rows and 1 column. Life was simple then, so simple in fact that happiness could be found within a small puzzle box and where success could be had by merely moving a king from his summer palace to his winter home.The first block is the blocks list is always the one that tries to escape. However, my husband and I walk down memory lane, and many of its by-lanes, exchanging notes about all the games we played as kids. The kids soon move on from their fleeting interest in the puzzle box. There was no need to charge any phone or laptop. ![]() We played the same games multiple times, and when we got bored, we would move to another similar game or puzzle, and then come back to this one. They talk about how the mobile game has so many levels and challenges.īut, my husband and I are stuck in the past, where levels did not matter, where machines did not give you rewards and awards. They liken it to a game called Klotski that they play on their phones. The kids move the puzzle pieces this way and that. ![]() My husband’s eyes light up, when he sees this small box that contains some of his childhood memories memories that come gushing out and bring a delighted smile to his face. The objective of the game is to bring the King down from his summer palace to his winter house. My kids look excited, and look curiously at the small box from nearly four decades ago. She passes it to my daughter, and says, “This was a puzzle that belonged to your Dad.” She wears her reading glasses, and looks at what seems to be a small rectangular box in her hand. My husband’s mom walks into the room, where my kids are sprawled out. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |