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.

DarkBASIC Discussion / The DB Classic Programming Challenge Thread

Author
Message
Digger412
18
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 21st Oct 2008 04:20
Sorry for the double post. I looked around some and found a code snippet by OBese87 (I've seen a good amount of his work around here, think he's a real good coder personally), integrated it into my 2-D C/E code, so now the red guy (chaser) smoothly curves to follow the blue guy (evader). Idk if red will catch blue a lot of the time, it's a random placement so sometimes he'll catch him like BAM and then it's over, and sometimes he never does..



This isn't my entry insofar, maybe it will be if I can't make a working 3-D one lol..
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 22nd Oct 2008 23:21 Edited at: 22nd Oct 2008 23:23
Weird, digger, whenever you post, it doesn't register on the main forum page.

Nice "entry" though.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd Oct 2008 23:53
Digger-

Nice program. A few commands you don't seem to know of:
cls rgb(r,g,b)

Instead of using box command.

suspend for mouse

Instead of using repeat...until.

Nice code altogether though!


I download memory.
Digger412
18
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 25th Oct 2008 06:38
Nope, never heard of the cls rgb(r,g,b), but I can guess what it'll do, nice command. I knew there was a suspend for key, but not suspend for mouse. Thanks, it's pretty simple, my first A.I.

@BN2 yeah, my posts still have to be approved I'm not a new mem, but I'm new to the forum...oh well, shouldn't be too long 'till I'm free =P
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 27th Oct 2008 16:13
I've made my entry. It's about 2000 lines so I've attached it as a dba file.

I creates a random maze (thanks to Latch) and has a 'predator' circle (red) trying to get a 'prey' circle (green).

The prey AI basically finds a path from one point to another and goes there. When it reaches it's destination, it finds a path to another point and goes there, and so on. However, if it sees that the 'predator' has crossed it's path or that the predator is close to it (taking into account the walls in between them), it finds a path that leads it away from the predator. If it finds that it is trapped by the predator in a corner, it makes a rush for freedom, usually resulting in it being caught.

The Predator AI is more complex. It looks at the most common routes taken by a prey if it were to go around the maze several times (basically, at the beginning of the code, I have repeatedly found paths between two points and found out what the most common routes those paths take). It then performs a flood function to find out how far away each cell is from the prey. Using this information, it determines the most probable path the prey is likely to take and finds the most probable end point. It then finds a path to that point and goes there. The predator also looks at the prey's recent paths to determine what path it's not likely to take. Because the predator goes to the point the prey is most likely to take, this means it can trap it or at least get closer to it than it would if it were simply following it. The predator also looks to see if the prey is in an enclosed area. Because the predator AI doesn't look at any part of the prey AI, it would be possible to adapt it so that it could follow a prey controlled by the user.

Both the prey and the predator go at the same speed, however, because the predator has superior AI, it always eventually catches the prey.


"To succeed is not enough, others must fail" - Gore Vidal
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Oct 2008 01:55
Nice!

Enjoy your day.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Oct 2008 06:15
Wow, nano, that's very impressive. Was kind of confused at first as to which color was which.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Oct 2008 00:34
@Nano
I managed to cut down your colour code...

I can't seem to get the adjustment quite right.
Here's the original code if you want it...


A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 30th Oct 2008 20:28 Edited at: 30th Oct 2008 20:28
Thanks Latch and BN2!

@Obese
Thanks, I modified it slightly so the colours were more like the original:




"To succeed is not enough, others must fail" - Gore Vidal
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 31st Oct 2008 18:43
Alright guys, here is the deal, I have been swamped with work and homework lately, so I am a little behind on judging. Should be able to get it done by the end of the weekend. If you guys want to, go ahead and add on to your code or fix bugs, until I officially close it later today.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 2nd Nov 2008 07:03
As you haven't closed it, I figure I'll go ahead and do that, so the challenges don't fall apart.



CHALLENGE IS CLOSED



I download memory.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 2nd Nov 2008 07:18
Thanks, got busy! I will second, the challenge is closed. I will begin judging tonight.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 2nd Nov 2008 20:49
No problem.
Quote: "I will begin judging tonight."


Excellent.


I download memory.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Nov 2008 19:12
Alright, here are the results:

Latch: Great example of chasing and evading. I liked the inclusion of the walking animation and the text.

Digger412: Cool program. Would have liked to see the chaser follow a path that showed where the evader would be (aiming in front of him in order to ensure catching).

Nano: Very inventive idea. I liked the way that it always caught it in the maze, and all of the debug tools there were (though it wasn't part of the challenge, it was interesting to see the different paths).

And the runner up is :


And the winner is:


Good job everyone! Now I look forward to actually being able to participate in the challenges again!

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 3rd Nov 2008 21:18
congrats again nano!

Enjoy your day.
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 4th Nov 2008 02:08
Grats Nano!


I download memory.
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Nov 2008 18:03 Edited at: 4th Nov 2008 18:06
@Nano
Well done!
I have refined that rainbow colour changed thing, I knew it could be done simpler without those horrible sines.


That's a simple example based on 255, but with a little tweaking you can make a "spectrum" based on any number...

This would be useful if say you wanted to show a players HP as a colour.

Here's a function so it's easy to use...


I hope that works I don't have DB or my notes with me


A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 4th Nov 2008 18:36
Thanks BN2, and thanks Latch, Irojo and Obese .

The next challenge:

Gadget/Minigame Collection


Description:
Create a collection of gadgets (like with the vista sidebar or Google desktop) and/or mini games that can be accessed from a menu. For example: time and date, calender, My Pictures sideshow, mini pong game, etc... . Be as creative as you can with what you come up with.

Deadline:
One and a half weeks: Midnight GMT, Friday, 14th November, 2008

@Obese
That's great, really smooth rainbow colours. The only problem is that it is limited to 255 colours between red and blue, where as the sine/cosine one could have any amount. Not that that is a major problem though .


"To succeed is not enough, others must fail" - Gore Vidal
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 4th Nov 2008 19:05
Grats Nano, been a bit busy couldn't participate in last challenge, I'll make it in this one tho.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Nov 2008 19:48
hmmm this could be interesting, I will try my hand at it. Nice challenge.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 4th Nov 2008 20:41 Edited at: 5th Nov 2008 02:18
I like this challenge... Might just try my hand at it... Good idea!
[Edit]
I did try, and I made a pretty cool program. It's not finished yet, loads left to do, but check it out! I figured I'd post it to spark of the competition, and just in case I don't finish in time:
(Attached also)



If you have any jokes or riddles you like, let me know, and I'll put it in. Many thanks.

-Irojo


I download memory.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Nov 2008 02:19
Very impressive for so fast Irojo, though the transitions could be a bit faster.

Hmmm....perhaps I will use my menu maker code to create the basic menu...

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 5th Nov 2008 02:26
Thanks. Ya... I'll speed it up.


I download memory.
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 5th Nov 2008 11:41
I have a question. Do the games have to run inside the "sidebar"? or can you use the whole screen? Thanks
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 5th Nov 2008 19:35
@Irojo
Looking good, I like the transitions! Although I noticed you're using gotos and please indent you code!

@steve paul thomas
You don't even have to have a sidebar, you could have a menu (like Irojo did) with full screen or part screen gadgets. The way you lay it out is up to you.


"To succeed is not enough, others must fail" - Gore Vidal
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 5th Nov 2008 21:28 Edited at: 5th Nov 2008 21:49
Wow. I didn't want to return, and DBC was acting funny, so I just used goto. It's not this evil command really...

Quote: "please indent you code!"


That appears to be a habit I've fallen out of .


I download memory.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Nov 2008 21:34
Quote: "It's not this evil command really"


Very true. A lot of people seem to think that goto is entirely evil. While it DOES make code harder to read, it is better than using a gosub at times, such as when you don't want to return. I don't really know what the alternative would be, so I use it.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 5th Nov 2008 23:47
Quote: "A lot of people seem to think that goto is entirely evil. While it DOES make code harder to read, it is better than using a gosub at times, such as when you don't want to return. I don't really know what the alternative would be, so I use it."

You may be right but I've never come across a situation that couldn't be better written without GOTO. Having to use GOTO usually means you've written yourself into a corner, and there shouldn't be any dead-ends in a program.

@Nano
Quote: "The only problem is that it is limited to 255 colours between red and blue, where as the sine/cosine one could have any amount."

I realised that, so I wrote a function that let's you have as many colours as you want. I'll re-post it here as it didn't quite come out right...
OK it turns out that function was a load of garbage so I wrote a new one that definitely works ...


About the challenge...
I don't really understand the whole gadget thing, do you mean a menu that pops up or something? Oh I'll just write a mini-game

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 6th Nov 2008 00:50
Thanks for clearing that up NanoGamez guy. I've already gone with the sidebar thing. Going to keep my entry secret until its finished.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Nov 2008 01:33
Quote: "Having to use GOTO usually means you've written yourself into a corner, and there shouldn't be any dead-ends in a program.
"


Good point. How would you suggest going about restarting a program without using goto?

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
jason p sage
18
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 6th Nov 2008 04:44
Wrap everything in a small loop. Try to make all subroutines and functions single entry and single exit.

pseudo...


Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 6th Nov 2008 06:38
Putting everything into one loop, makes it extremely confusing. I think of loops as floodgates, you use gosub, or goto, and the floodgate opens. Different areas, different floodgates.


I download memory.
jason p sage
18
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 6th Nov 2008 13:05
Well.. The question was how do you start a program over without GOTO. I gave a rather plain example.

I also agree with the use of Gosub, and gosub can easily fit into the "single-entry, single-exit" paradigm of most modern programming.

I don't want to get into the GOTO wars... I am not so against them as many are, I also don't use them much at all. It's a tool. Each job/task is unique, and you always want to use the right tool for the job!

BTW - Irojo - I like your brain siloette in your sig - its great!
--Jason

Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 6th Nov 2008 15:54
Thanks. Phaelax made it.


I download memory.
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 6th Nov 2008 18:04
Quote: "Putting everything into one loop, makes it extremely confusing. I think of loops as floodgates, you use gosub, or goto, and the floodgate opens. Different areas, different floodgates."


That's an interesting way of putting it, I never thought of it like that! I usually use one loop for the main game and then use gosubs for each part which makes it much less complicated. But of course I use different loops for the menus and stuff.

Quote: "It's not this evil command really..."


I don't think it's evil, I just found it hard to understand you're code because of it.


"To succeed is not enough, others must fail" - Gore Vidal
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 6th Nov 2008 18:44
Quote: "I just found it hard to understand you're code because of it"


Understood. But how does using a gosub make it easier to understand, if I don't use a goto? Isn't using a gosub without return the same as using goto?


I download memory.
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 6th Nov 2008 19:34
When I started out with DBC, the DB Programming Principals implied that GOTO was deprecated and that it was only retained for compatibility.

So I avoid it (perhaps I am wrong to?). I am guessing a lot of the DB community has a similar feeling towards it. That GOSUB supersedes it and therefore renders it obsolete.

Or have I got that wrong? I'm still a noob after all lol
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Nov 2008 19:38
@Irojo
I thought I'd type up a suggested method to improve your binary translator so you could translate all of the characters (numbers,letters,symbols) without so much conditional testing. DBC has two built in functions that make it a bit easier: BIN$() and ASC().



Enjoy your day.
jason p sage
18
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 6th Nov 2008 19:54
If I may - I'd like to spit out some goto/gosub/function soapbox answers - and allow you guys to get back to challenges (We've hashed this out in other threads.. but here's the summary of the hashing )

1: GOTO is a "High Level Language" version of the Assembly Command "jmp" (Jump). JMP is used in your computer millions of times a day. Obsolete? Never. However the constructs of subroutines, functions, and "single-entry, single-exit" programming have been commonly accepted as cleaner alternatives to using GOTO statements to arrive at the same end.

2: GOSUB is exactly like GOTO except for one important detail: GOSUB stores on the STACK the address/location of the line of code immediately following it so that program execution can be branched to that location when a RETURN statement is encountered. GOSUB is great when you don't want/need to pass variables to your subroutine (and global variables are your answer to getting data to and/or modified by your subroutine if you have the need).

3: Functions are similiar to GOSUB except, functions allow passing parameters (on the stack along with the return address) explicitly to your function, functions can have their own private/local variables inside of them that "go away" when the function exits (unless there is what's called a static variable construct in the language you're using - in which case you can make some variables NOT GO AWAY... and stay persistant, still private to the function though). Also functions by definition return some value... the result of the function.

the theory is that when you use a function or even gosubs, you can follow code easier with your eyes reading source code. If GOTO's are used regularly, its harder for people to identify where the code is flowing. These points can be argued until doomsday - but generally speaking, the single-entry, single-exit rule for code makes for more modular source code that can be reused MUCH easier than code interlaced with GOTO commands. If you're language of choice uses "labels" for the GOTO destination parameter, then even this point can be argued.

So moving forward - I code for a living - do I use GOTO professionally? 99% no... but every so often I find a situation where either for speed's sake, or "boxed in" situation, or perhaps if its just the BEST way to accomplish something... yeah... I'll use a GOTO.

--Jason

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Nov 2008 20:08
Just an addition to point 2, since GOSUB stores it's return address on the stack, don't use it in place of GOTO (GOSUB without RETURN - once upon a time BASIC languages reported this as an error) or you can fill up the stack unintentionally.

And on 3, DBC function variables are static.

Enjoy your day.
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 6th Nov 2008 20:10
Excellent post, jason p sage . That explained it all very well and has changed my view of GOTO.
Irojo
18
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 6th Nov 2008 20:20
Quote: "I thought I'd type up a suggested method to improve your binary translator so you could translate all of the characters (numbers,letters,symbols) without so much conditional testing."



Noooooo!!!!! All me copying and pasting is for nothing. Curse you!

Wow. That's impressive. I'm sticking with mine, because I couldn't stand to delete it.


I download memory.
jason p sage
18
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 6th Nov 2008 20:27
Good Point Latch Thank You Steve... and good Luck!
--Jason

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Nov 2008 20:41
Thanks for the info jason! and why not enter the DBC challenges? It may actually be a challenge to you since I don't think you code in DBC. You'll find you don't have all of the same tools available as in Pro or GDK and it may force you to scratch that coconut a bit.

@Irojo
I know what you mean in terms of putting a lot of work into something!

Enjoy your day.
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 6th Nov 2008 21:05 Edited at: 6th Nov 2008 21:56
Talking of scratching coconuts ...

I could do with some advice on simplifying something I wrote off the top of my head. Its an analogue clock that will sit on the sidebar (on the right-side of the screen). I'm awful at math and have a vague idea of how to use sine and cosine.

I've got the clock working great, but it uses far too much code and it was extremely boring typing out all those angles! I know there is a simpler way to do this...I..er...just don't know what it is.

Here's the code I have written for the clock:

jason p sage
18
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 6th Nov 2008 21:49
@Latch - you're welcome - and thank you for the invite and you're right about the language differences.. would throw me for a loop I'm sure As for actually participating in the challenges.. shoot - I have been so busy lately... its unreal.. I've been writing a web server, an IP phone system, and I'm about to embark on a big (likely DX9) project on Monday... might not write any code until the week after... travel - etc... but .. just to swamped... I really appreciated the invite however!

Steve... WOW... Dedication? You're amazing! Alternatives? I'm not a math genius either... but if there are 360 degrees in a circle, and 60 minutes in an hour... one might calculate how far to move "per minute" using a simple 360Degrees / 60 minutes in a Hour = 6 degrees per minute

Seriously - Dedication like yours is the kind that is required to see projects through until they are completed. I'm all for the person who - regardless how - figures out SOME way to get the job
done - which you appear to have done. Great JOB!

--Jason

BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Nov 2008 21:51
Quote: "functions can have their own private/local variables inside of them that "go away" when the function exit"


just to point this out: In DBC due to bug or design, all variables within a function are static, so make sure you reset them to 0 before checking their value.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 6th Nov 2008 22:11
Thanks Jason Whilst this code works, its hardly ideal. I'm pretty sure you would multiply by 6 for each minute and I think you would have to use WRAPVALUE to stop it going over 360. With 0 minutes being at 270 degrees I am a bit confused how to break this down into a few lines/single-line of code.

If you or anyone could help, I'll be sure to mention you in the finished code.
steve paul thomas
17
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 7th Nov 2008 00:17
Also, joke for Irojo's project:

There are two drunk men in a pub.

One says to the other: "Does your watch tell the time?"
The other replies: "No mate, you have to look at it".
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 7th Nov 2008 00:31 Edited at: 7th Nov 2008 00:32
Basically to get the angle of a clock hand, lets say, a second hand, you have to divide the seconds by 60 (to get a number between 0 and 1). Then multiply it by 360 (to get a number between 0 and 360). You then have to add 270 (or take away 90) to make it work with the sin and cos commands. So to get the angle for the second hand, you would use:

secondangle#=wrapvalue(seconds#/60.0*360+270)

Then to draw the hand, just make a line from clockx,clocky to clockx+cos(secondangle#),clocky+sin(secondangle#).


"To succeed is not enough, others must fail" - Gore Vidal

Login to post a reply

Server time is: 2026-06-07 07:26:17
Your offset time is: 2026-06-07 07:26:17