Jump to content

The Slide Puzzle (game)


abberration
 Share

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.

 

The Slide Puzzle v.1.0.zipThe Slide Puzzle v.1.1.zip

Edited by abberration
New version posted
Link to comment
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:

https://gamingph.com/blackdesertmobile/puzzle/puzzle.html

 

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

Some of my script sourcecode

Link to comment
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.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
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)

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...