# The Slide Puzzle (game)

## Recommended Posts

I have been wanting to program a game and now I have done it. It's a fairly small script with no fluff like About boxes or instructions.

Now I need to make a chess game (kidding).

Hope everyone likes it. Cheers! ðŸ¥ƒ

Update: Thanks to Dan_555's suggestion, I have changed the randomize option to move tiles around instead of using _arrayshuffle. Also, I added in a Settings option so you tell it how many moves to shuffle it. Download v.1.1 for these features.

Â

Edited by abberration
New version posted
##### Share on other sites

I like. You can also add control from the keyboard.

##### Share on other sites

Hi, the game is nice but theÂ array-shuffleÂ can create unsolvable puzzles.

You have to swap the pieces one by one, in the code, just like you would do it manually.

(by moving the empty square up/down/left/right randomly, swapping the numbers)Â

You can test a puzzle solver here:

Â

Drag the pieces from the top square to the bottom square and in this order:

1 2 3

4 5 8

7 6

Â

And the puzzle (afaik) can not be solved.

Â

Edited by Dan_555
##### Share on other sites

Hi, Dan_555. Thank you for your input. I didn't think about it creating unsolvable puzzles. It might be neat to watch it shuffle the pieces around. I will work on that for the next version.

##### Share on other sites

As a general rule of thumb, a 2D shuffle puzzle of dimension N (that is of size NxN) is solvable iff, when reading values from, say, top left to bottom right, row by row) the number of permutations of cells (cell with value X appears before cell with value Y AND X > Y) is even. This works whatever the empty cell is. @Dan_555 example gives a odd number of permutations, hence it isn't solvable.

For those who care, here's a wiki page explaining the fact: https://fr.wikipedia.org/wiki/Signature_d'une_permutation

Sorry, as is often the case in wikipedia maths pages, there is no direct english translation. Try Google translate if that works, but many French terms used in combinatorics have only vague equivalent in english (and often ambiguous) due to a radically different approach to the domain.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

jchd,

Good to know. I tried to come up with a formula to figure out which tiles are adjacent, but I couldn't. I saw patterns and I knew I could hard code the moves, but that seemed lazy.

I have already implemented the moving tiles around in v.1.1. It is posted on the first post.

Now I'm off to make a BlackJack game!

Cheers.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...