Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Recursion Challenge (June 2008)

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Jun 2008 13:00
If you haven't already seen it, there is a small challenge in this month's newsletter. Read Lee's Tip of The Month, and IanM's additional contribution regarding recursion as a powerful programming tool. Please use this thread to post your entries, anything arriving before the end of June 25th will be considered.

Even if your efforts don't quite match up to prior posts in the thread, post them anyway. We're looking for anything interesting, and also want this thread to become a resource for anyone new to the concept.

El Goorf
18
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 5th Jun 2008 14:59
i dreamt last night i won this and was secretly awarded an infinate supply of DarkBASIC classic and 2 copies of FPSC

anyways, this thread seems a little quiet, i can only assume everyone's busy with their entries, i know i am

http://notmybase.com
All my base are not belong to anyone.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Jun 2008 16:43
Yeah, these more advanced coding challenges tend to start off slow, I think it's just people wanting to get a good start before showing their work.


less is more, but if less is more how you keeping score?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jun 2008 17:09
let's hope so The prize isn't massive, but the public admiration and 1-up should be enough inspiration.

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 5th Jun 2008 17:09 Edited at: 5th Jun 2008 17:10
Well I just re-read that part of the newsletter and by any language on TGC I assume that means we can use C++ and GDK, even if TGC don't offer C++ directly. And are there any other rules? Plus it seems a bit strange offering TGC points(which can later be exchanged for a voucher), when the TGC store currently is only available to FPSC users and FPSC cannot be used for this :p. But yea I'll be entering, as I'd need to code this for my game eventually anyway, two birds with one stone .

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jun 2008 18:48
The voucher will be directly awarded, as an alternative to the points.

Yes, if your code is relevant to a GDKer, it's valid. This is a relaxed mini-challenge, we are looking for any code that fits the recursion theme, that will inspire or assist other users.

Aertic
17
Years of Service
User Offline
Joined: 2nd Jul 2007
Location: United Kingdom
Posted: 5th Jun 2008 18:52
hey BatVink? aint you're signature a little too high?
or is it just about right?


AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 6th Jun 2008 03:31
It's 700x160.

90% of statistics are completely inaccurate.
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 6th Jun 2008 10:03
Quote: "hey BatVink? aint you're signature a little too high?"


hey LT Tatters? aint you're tired of being a forum cop?

Please don't derail this thread.


BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jun 2008 10:13
My sig is too high - I uploaded the wrong one. It will be replaced ASAP.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 6th Jun 2008 20:47
Here is mine It will let you enter a sum, and it will calculate the result using BIDMAS

The available operators are:

binary + (add)
binary - (subtract)
binary * (multiply)
binary / (divide)
binary \ (quotient/modulus)
binary ^ (power)
binary ¬ (root)

unary - (negation)
unary + (does nothing)

Teh Codez:


the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 7th Jun 2008 00:16
I'm sure to win with this one.



By way of demonstration, he emitted a batlike squeak that was indeed bothersome.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 8th Jun 2008 14:33
If I have a member that calls a separate instance of the same member is this a valid entry? As the underlying function uses the same code, but it's not exactly calling itself.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Jun 2008 18:52
@dark coder
Technically, it IS the same function, it's just that the hidden 'this' parameter is different, so I would say yes, that would be allowed

bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 8th Jun 2008 20:58
Wow Winch, that is way slick. Nicely done.


Hurray for teh logd!
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 9th Jun 2008 10:47
Do you know a fractal?

http://en.wikipedia.org/wiki/Fractal
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Jun 2008 22:15
I apologise in advance because I know my dumb PS3 wont let me put all this in one post.

Here's my entry: The Towers of Hanoi


This is going to take too long so I'll finish it when I'm at a computer.
It will be in one post too.

It is far better to complete a 10 line program than to start a 10,000 line program.
RedFlames
17
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 19th Jun 2008 22:33
ok so i made this two little functions for strings etc. and i 100% know they have to work but there seems to be a problem with exitfunction vs. endfunction

anyway the code: (started around half an hour ago )


H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 20th Jun 2008 02:42
I have two entries, since I have no life anyways

First entry: (Almost) Unbeatable Tic-Tac-Toe Player
This program's main AI works by looking at each possible play it can make in any given instance, and then calculating through a recursive function every possible move that could be made after that, and then selects the play that has the most net possible gain. There are a few tweaks to this general idea, to make it a slightly better player, but the recursive function is the backbone of its AI.

Here's the code:


Entry 2: Sierpinski's Triangle
I'm not entirely sure if this counts as a recursive function or not, but considering that it calls itself many times over I believe it does. This program creates a very cool fractal by randomly selecting an endpoint on a triangle and creating a new point halfway between its starting point and the endpoint of the triangle. It repeats this process over and over again, theoretically forever, but I've capped it at 100,000 repititions. Take a look! When it's done, press space to close the window.



dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 21st Jun 2008 08:44
OK here's my entry, recursively subdividing patches for a planet . This is far more optimized than my previous attempt in DBP, in-fact when benchmakring it the only real slowdown was caused by trying to update the meshes, which is quite slow. I tried 4 methods to update the mesh and the fastest I found was to just delete the limb(the terrain uses) and just add another limb of the same ID again, there was one last method I didn't try, that was to selectively erase and insert patches from the limbs when locked as vertexdata, but that would have taken a while to do, besides the current method isn't too slow and will suffice.

The planet class isn't fully finished yet, as I didn't write any code to check the depth of neighbour patches so you can check if the next patch is of a lower resolution, if so you skip the normalization for the mid-point verts in the current patch thus avoiding creating seams/gaps between adjacent ones. I also didn't implement any heightmap reading code because making cubemap surface textures requires me to code more than I needed for the entry blah blah(and that too is hard to code ).

The archive comes with an exe so anyone can try it, in case you can't be bothered to thumb through the whole thing the recursion occurs on the lines: 16 in planet.cpp(destructor calling instances of itself), line 46(method calling a child/branch instance of itself), same for line 122, and line 138(another method calling a child/branch instance of itself).

Attachments

Login to view attachments
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 21st Jun 2008 11:30
Cool, I have a project that uses LOTS of recursion that I hope to have finished by the end of this month!

Mountain Dew, happyness in a bottle.
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 28th Jun 2008 05:39 Edited at: 28th Jun 2008 20:23
K, here is my program. I hope it's alright, I'm using 2 of the Matrix1Util dlls by IanM, and Dark AI. The MatrixUtil dlls have been included in the .Zip folder. I'm also including an .EXE file for anyone not wanting to compile the code.

The actual recursion happens with the functions on the following lines:

line 135
line 153
line 250
line 378
line 499
line 700


The program simulates a tribal system by monitoring the male tribal members. The simulation starts with a male, which reproduces a child, who again will reproduce, ect, ect. Eventually the leader of the tribe (the first male) will die of old age, and his sons will split into their own tribes. If the leader only had one son, then that son becomes the new leader of the tribe. Tribes war with each other and will eventually die off. This keeps the population to a reasonable amount. You can use either WASD or arrow keys to move the camera.

Also, when new tribal members are born, they start out very small, and as they grow with age they gain more strength. So as babies they are very vulnerable.

I use recursion exstensivly to manage all the tribal members. In this way I don't need to loop through an array of everyone when I want to update a single person, I can simply recurse through the family tree of a single tribe. In this way, I update a tribe at a time, instead of everyone at once. This gives some considerable speed boosts in areas such as checking to see if one tribal member can fight with another, as it never has to check with someone in it's own tribe.

Anyways, it's all a little confusing, so enough said, attached is the zip file.

EDIT: I apologize, it seems I accidentally uploaded an older version of the program. Attached is the newest version, thanks

Mountain Dew, happyness in a bottle.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Jun 2008 06:22
Fern Fractal



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Jun 2008 22:02
Thanks for the efforts - check the newsletter for the winner

Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 30th Jun 2008 23:42
Sweet! I especially liked H4ck1d Tic Tac Toe code!

Mountain Dew, happyness in a bottle.
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 30th Jun 2008 23:42 Edited at: 30th Jun 2008 23:43
<DOUBLE POST HICCUP>

Mountain Dew, happyness in a bottle.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 4th Jul 2008 17:39
Wow, I'm really impressed. Clever programming and brilliant approaches.
All are excellent, congratulations.
Mew151
16
Years of Service
User Offline
Joined: 1st Jun 2008
Location: Glitch city
Posted: 25th Jul 2008 07:54
Tribes is awesome No wonder why it won

ow! that hurt!

Login to post a reply

Server time is: 2024-11-14 23:31:30
Your offset time is: 2024-11-14 23:31:30