Sliding Tile Puzze

Post any examples or modules that you want to share here
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Sliding Tile Puzze

Post by martinvicanek »

This is my little vacation Ruby excercise. :) Download only if you need to kill time and have absolutely nothing else to do.
Attachments
slidingTilePuzzle.fsm
(959.1 KiB) Downloaded 1161 times
Last edited by martinvicanek on Tue Feb 09, 2016 2:33 pm, edited 1 time in total.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Sliding Tile Puzze

Post by billv »

Crashed FS on load..3.06 (Pebble)...twice.....What version is it built with?
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Sliding Tile Puzze

Post by adamszabo »

Very nice! I remember I had a game like this when I was a kid :)
works fine in 3.0.8
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Sliding Tile Puzze

Post by martinvicanek »

Sorry, billv. I am using 3.0.8. I have a suspicion what might have caused the crash in an earlier version. Try the updated fsm in the original post.
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Sliding Tile Puzze

Post by RJHollins »

Nice 3-d frame !

won't even begin to start playing the game for obvious reasons :lol:
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Sliding Tile Puzze

Post by tulamide »

This version runs with 3.0.6

Well done!
There are a few things to optimize, but not that much. The pens, brushes and colors are assigned to variables, which makes it easier to select the correct ones. But it also allows you to define them in the initializion method instead of the draw method, where they are defined on each draw call. By defining them just once, the garbage collector has much less work to do, which means less cpu usage.

The condition of an if clause always resolves to true or false, so it is valid to write

Code: Select all

if @mybool
    #do something if @mybool is set to true
end


Once again you use indentation (which is more important than people might think). If you now could also get rid of the old-school-behavior of using as less spaces as possible, your code would be perfect!

Code: Select all

a=(b*c)/d-e^^f #old way
a = (b * c) / d - e^^f #better readable
"There lies the dog buried" (German saying translated literally)
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Sliding Tile Puzze

Post by billv »

Thanks Martin...yeh, all good now on 3.06.
Nice work.
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Sliding Tile Puzze

Post by martinvicanek »

tulamide wrote:The pens, brushes and colors [...] define them in the initializion method instead of the draw method, where they are defined on each draw call.
Fair enough, and you made this point earlier. We really need this facepalm emoticon. :lol:
tulamide wrote:If you now could also get rid of the old-school-behavior of using as less spaces as possible, your code would be perfect!

Code: Select all

a=(b*c)/d-e^^f #old way
a = (b * c) / d - e^^f #better readable

I use spaces around "+" and "-", but not around "*" or "/" as they have stronger binding. For me it is easier to see that

Code: Select all

a^2 + 2*a*b + b^2
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!). :mrgreen:
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Sliding Tile Puzze

Post by tulamide »

martinvicanek wrote:I use spaces around "+" and "-", but not around "*" or "/" as they have stronger binding. For me it is easier to see that

Code: Select all

a^2 + 2*a*b + b^2
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!). :mrgreen:


It's not so much about personal preference. Pretty much all programming languages, at least the ones I know, have style guides. This is to agree on a common way to write code, so that it is easily interchangeable while all programmers recognize the code fast and easy. Ruby has such a style guide as well, and it says:

Use spaces around operators, after commas, colons and semicolons, around { and before }.

Code: Select all

sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }


Here are two versions of the style guide (they are the same, but I don't know which one will be updated more regularly (probably the second link):
https://github.com/styleguide/ruby
https://github.com/airbnb/ruby

But we are in the same boat. There are some things that I still need to get used to (like using parantheses with methods and indenting when only as deep as case) and even some that I don't agree to (the style guide tells me that "and", "or" and "not" are banned and I should use &&, || and ! instead. I disagree extremely on this, because Ruby's goal is to be readable as easy as possible. Using strange signs instead of clear words doesn't help towards that goal)

The more we get used to the style guide, the easier it is for us to work on shared projects. That's why I pointed to it so strong :)
"There lies the dog buried" (German saying translated literally)
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Sliding Tile Puzze

Post by RJHollins »

We all learn from these posts.

Thank-you Gentlemen 8-)
Post Reply