Page 3 of 3

Posted: Mon Mar 01, 2010 1:46 am
by roflamingo
martin wrote:Use a flood fill algorithm:

1) Generate all points in the ocean and add them to a set


I tried doing this with the first coroutine setup and it was extremely slow.

Are you doing this? What algorithm and step values do you use? Is it fast enough?

Posted: Mon Mar 01, 2010 10:15 am
by martin
bert_the_turtle wrote:Welcome to the DEFCON forums, where everything gets turned into an argument :)


Oh god, you're right :O
xander, let's agree to differ one this one ;)

xander wrote:Finally, the acronym is PEMDAS: parentheses (or brackets, as you silly Europeans call them), exponents, multiplication and division, and addition and subtraction. :P

xander


I've never heard of PEMDAS, the various ones I have heard through the years are BODMAS and BIDMAS (I can't remember what the O stands for, if I remember correctly that was before we learnt about exponents and it's basically just a placeholder, the I stands for indices, and I always thought BEDMAS would make more sense).

Montyphy wrote:
xander wrote:Moreover, it is even bad code, as I highly doubt that you would be using x in that situation (it is likely that "x" would already be used for something else).


You obviously haven't seen martin's code :P


In all seriousness, I have no idea if my Lua code is good or not, I'm writing it in a pretty strong OOP style, which is probably not classical Lua style.

roflamingo wrote:
martin wrote:Use a flood fill algorithm:

1) Generate all points in the ocean and add them to a set


I tried doing this with the first coroutine setup and it was extremely slow.

Are you doing this? What algorithm and step values do you use? Is it fast enough?


I'm not, but I am doing something similar with surveying the land around my cities for find the best place to put silos

I was talking in pseudo code, you can probably do it somewhat better than that in reality

1) Pick a random point in the ocean and add to a set foo
2) Generate all surrounding points, for each point which is _not_ in the set foo do step add to set and do step 2
3) At the end, if foo does not contain all ocean points, then you have a discontinuous ocean.

Determining step 3 is not trivial, but I'm sure some simple solution can be found (it's 9am, I'm not gonna figure out how to do it right now)

Finally, for an implementation of a set in Lua, see the Joshua/Utilities folder :)

Posted: Mon Mar 01, 2010 3:18 pm
by xander
martin wrote:
Montyphy wrote:
xander wrote:Moreover, it is even bad code, as I highly doubt that you would be using x in that situation (it is likely that "x" would already be used for something else).


You obviously haven't seen martin's code :P


In all seriousness, I have no idea if my Lua code is good or not, I'm writing it in a pretty strong OOP style, which is probably not classical Lua style.

I have not taken a lot of programming, nor do I program that often, nor do I read other people's code that often. However, was always taught to use the clearest possible variable naming conventions, to ensure that my code is readable to others. The best possible code is that which requires no comments because everything is so self-evidently clear that any idiot could read through it and know what is going on. From that standpoint, using "x" rather than "x1" is confusing. If nothing else, it gives the impression that "x" and "x2" are different kinds of variables. It does not imply that, for instance, one is an int and the other a float, but it does imply that they are holding different pieces of unrelated data. On the other hand, "x1" and "x2" are clearer, and are in line with mathematical convention. Thus a mathhead like myself finds Ace's version more readable.

On the other hand, I suppose that your code is more functional (i.e. it does what it is supposed to do), so a programming junkie would probably prefer yours. When I say that Ace's version is more "correct," I am speaking from my perspective as a math person, not as a programmer. This is a situation where context is probably important. That being said, you are still both wrong. :P

xander

Posted: Mon Mar 01, 2010 8:23 pm
by martin
Oh I would never use names like x and x2 in code! Have a glance through the Joshua source and you'll see I use pretty verbose names. However, for a little example like that, where I was mostly worried about correcting a bracketing mistake that would cause Lua to throw a wobbly, I didn't really care about naming where it was obvious what I meant ;)

Posted: Mon Mar 01, 2010 8:27 pm
by Montyphy
martin wrote:Oh I would never use names like x and x2 in code! Have a glance through the Joshua source and you'll see I use pretty verbose names.


svn/trunk/whiteboard.lua

Code: Select all

Whiteboard.DrawLine = function(x, y, x2, y2)
        WhiteboardDraw(x, y, x2, y2)
end



:P

Posted: Mon Mar 01, 2010 8:31 pm
by martin
I inherited that from the old version of Joshua, which iirc is inherited from the old version of the Luabot. Maybe I should change that :oops:

Before anyone points it out, yes I know I call tables in my constructor methods "t" but no, I'm not going to change that, I just can't be arsed :P

Posted: Tue Mar 02, 2010 12:40 am
by xander
martin wrote:Oh I would never use names like x and x2 in code! Have a glance through the Joshua source and you'll see I use pretty verbose names. However, for a little example like that, where I was mostly worried about correcting a bracketing mistake that would cause Lua to throw a wobbly, I didn't really care about naming where it was obvious what I meant ;)

If you are going to take the time to correct someone take the time to do it right. The only thing more annoying that posts that consist of an edited quote and the word "Fixed" (or some variant thereof) are such posts where the fix is incomplete or inaccurate.

xander