8-puzzle game

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Wed May 18, 2011 8:27 pm

Hi Britt,
My buttons are 100x100 pixels. Will your app work with that size?
just tested, yes. The right and left pointing buttons will have a flat angle.
Presently fontsize up to 22, could be more if desired.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Wed May 18, 2011 8:40 pm

Hi Britt,

you are lucky this week we offer the free app even freeer (is that a word?) :)
shuffle.png
shuffle.png (27.75 KiB) Viewed 11621 times
Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Wed May 18, 2011 11:39 pm

How do I get them into my app? They would need to be 100x100, with a font size of about 60.

Edit: I copied and pasted one into my app, but I don't see how it is different from a regular button.

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Thu May 19, 2011 12:05 am

Actually, I'm okay with how my buttons look. I just want to get rid of the bug that makes a box appear around them in iOS.

The box only shows up when I press the button, and it doesn't go away.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Thu May 19, 2011 12:10 am

Hi Britt,

try to set the borderwidth of the button to 0 and see if that helps.

Kind regards

bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Thu May 19, 2011 12:30 am

Hi Britt,

it is not the borderwidth, I think it is the showFocusBorder.

try in the message box:

Code: Select all

set the showFocusborder of button "shuffle" to false
and hit the return key.

Then try in the simulator.

Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Thu May 19, 2011 3:29 am

Yep. That was it. You rule.

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Fri May 20, 2011 3:58 pm

A few questions:

Why did you use this form on the shuffle button

Code: Select all

   send "solvePuzzle gWidthPadding, gHeightPadding" to me in 10 milliseconds
rather than

Code: Select all

solvePuzzle gWidthPadding, gHeightPadding
Likewise in the "solvePuzzle" handler. Why this:

Code: Select all

  send "displayBotButtons tParameter" to me in 10 milliseconds

and not this:

Code: Select all

displayBotButtons tParameter
Why in the "displayBotButtons" handler, is this necessary?

Code: Select all

   if "displayBotButtons" is not in the pendingMessages then
Finally, how do I change my timers such that beginning with 60 seconds, it will display the elapsed time as minutes:seconds?

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Fri May 20, 2011 11:47 pm

Any idea how to speed the bot up? When the current state is very far from the final state (which often is the case when you really randomize the tiles by shuffling them 50 times), it can take a really long time to solve. I want to build a 15-puzzle, but I am concerned that it will take forever for the bot to solve. I don't need it to find the shortest path. I just need it to be as fast as possible.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Mon May 23, 2011 12:24 am

Hi Britt,
Why did you use this form on the shuffle button
CODE: SELECT ALL
send "solvePuzzle gWidthPadding, gHeightPadding" to me in 10 milliseconds

rather than
CODE: SELECT ALL
solvePuzzle gWidthPadding, gHeightPadding
when you use send in time like in the first version the handler (in this case the mouseUp handler) finishes first and then send the solvePuzzle comman. This means no pending handler because in the second version 'solvePuzzle' starts right when it is issued and after it is finished it will return to the issueing hander-> the mouseUp handler.

I did not want to leave any handler pending because there was no real need for that: all the mouseUp handler had to do was done. The script is complicated enough and I just wanted to have no pending handler.
Likewise in the "solvePuzzle" handler. Why this:
CODE: SELECT ALL
send "displayBotButtons tParameter" to me in 10 milliseconds

and not this:
CODE: SELECT ALL
displayBotButtons tParameter
The same reason as above. When displayBotButtons is called from the solvePuzzle handler the solvePuzzle handler has finished and has prepared a list of moves to solve the puzzle for the bot. No more calculations necessary. So now I call a handler displayBotButtons with a send in time message to finish the solvePuzzle handler. No pending solvePuzzle handler. Now you have a handler displayBotButtons that you can slow down or speed up at will. That was what you wanted in the first place. In parallel the human can solve his puzzle withouth interfering with the bots moves of the puzzle pieces.

Why in the "displayBotButtons" handler, is this necessary?
CODE: SELECT ALL
if "displayBotButtons" is not in the pendingMessages then
depending on how much is going on at the same time Livecode can not always deliver at the specified time. Suppose some calculation is going on because the human player just made a move. The 'displayBotButtons' will fire when all the running handlers are finished. In this paricular case it may not be necessary but it has become a habit to avoid two messages running the same handler. The easiest scenario is to think of a button that sends a message in say 10 seconds. The user hits the button before the 10 seconds are over. Now you have two messages running that will reach the handler after 10 seconds effectively doubling the times the handler is executed. When testing for the pendingmessages it will avoid that scenario.
Finally, how do I change my timers such that beginning with 60 seconds, it will display the elapsed time as minutes:seconds?
just add the seconds to a variable and display the seconds mod 60 to get the seconds and the seconds div 60 to get the minutes.

See attached sample stack.

As for speeding up the calculations of the bot: I will have to look into that. I am not too optimistic about making it really fast because there is a lot of calcutations going on.

Kind regards

Bernd
Attachments
aCounterForMinutesSeconds.livecode.zip
(1.27 KiB) Downloaded 407 times

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: 8-puzzle game

Post by Brittgriscom » Mon May 23, 2011 3:42 am

That's awesome Bernd.

Thank you!

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: 8-puzzle game

Post by rumplestiltskin » Thu Jun 09, 2011 4:47 am

bn wrote:{snip}For the standard iOS buttons I made a stack that produces images for buttons à la iOS.

http://www.berndniggemann.on-rev.com/bt ... vecode.zip

Kind regards

Bernd
THANK YOU! THANK YOU! Your stack is exactly what I needed to make my app's buttons look iOS-correct and consistent.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Thu Jun 09, 2011 12:58 pm

Hi rumplestilskin,

thank you, that was an early try to avoid the need to go to photoshop.

But have a look at:

http://forums.runrev.com/phpBB2/viewtop ... f=4&t=7973

it is fantastic. It makes buttons for iOS and a lot more, it actually manages a good deal of designing an iOS app.

Kind regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Mon Nov 21, 2011 6:50 pm

Hi, when creating the board for the 8-puzzle game, and before running openStack of which the execution of the code sets up the tiles, each of which denotes a number and the shuffle button, does it have to be assigned to a button, for example "Start Game" of which when activated by a click of a mouse results in the board being created? If this is true, please let me know.

With kind regards,

Syed Hoque

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Mon Nov 21, 2011 9:01 pm

Hi Syed,

the 8-puzzle game is a lesson on the lesson section of RunRev

http://lessons.runrev.com/s/lessons/m/4 ... zzle-Game-

It is pretty well explained and the versions that are discussed/posted here are derivatives of the lesson game.

Did you look at the lesson/original game?

Actually I don't think it is an easy program to understand. The code and the logic is rather advanced. This is not to discourage anybody but this is not an easy/obvious example for a Livecode beginner.

Kind regards

Bernd

Post Reply

Return to “Games”