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
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Feb 2007 19:10
Sorry, I wasn't there... School work, and then valentine (yes, I have a girlfiend)

But in any case. I actually prefer to participate and skip the chosing, setting the challenge and judging part...
(But ofcourse, I'm glad I won )

But if you want me to judge or set a new challenge next time... It's not like it's the end of the world right? ... RIGHT?

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Feb 2007 19:15
No it's not like the end of the world.

Things happen! Internet connections get lost, girlfriends demand attention, we get ill and we all have lives... That's why we have a runner-up to take over setting the next challenge, so no worries.

TDK_Man

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Feb 2007 19:22
Quote: "Internet connections get lost"

Some things we can help...

Quote: "girlfriends demand attention"

...and some things we can't

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Data
19
Years of Service
User Offline
Joined: 26th Nov 2004
Location: Winnipeg,Canada
Posted: 15th Feb 2007 23:21
lol I'm pretty new to Darkbasic but I'll try the challenge...

Free sigs, email addresses and contests!
JimmyR.Co.Uk
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 16th Feb 2007 15:35
Well done TDK, I'm looking forward to seeing the 'harder way'

I can see you...
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 16th Feb 2007 15:38
I've made one. You can change the font, text size and colour.
It's very slow though.

rem make a 3D object obt of a 2D one



Note: When you change the colour, press enter to select.

I can see you...
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Feb 2007 21:39
I can't get any idea's...
Frustrating

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Feb 2007 22:41
To be honest with you, I can't see any way to do it other than the method Lukas W has used - without DLL calls (which aren't allowed).

The only real difference with what I've done is that it doesn't use data statements and you can use whatever characters in the string.

What's missing is a Make Object command which lets you set the number of vertices and their X,Y,Z positions!

Count me as frustrated too...

TDK_Man

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Feb 2007 00:48
Me too...

I'm using a variation of Lukas W also that doesn't use data statements. In fact, it's very similar to NanoGamez guy's latest entry.

I was thinking of maybe some semi old school methods like raycasting DOOM! style.

Plausible?

Maybe we should extend the deadline.

Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Feb 2007 01:12 Edited at: 17th Feb 2007 01:32
Well, my brain hurts!



Please note that the use of 2D commands in this means that it's speed isn't spectacular, so allow around 30 seconds (on my machine anyway) for anything to appear after you've pressed a key.

[Edit] Hadn't noticed NanoGamez guy's post prior to posting this and we've both had pretty much the same idea. Wouldn't have posted my snippet had I seen it. Hopefully mine is different enough to see that I've not copied anything!

[Edit 2] Nanogames: Just taken a look at your code. In your for x=1 to xsize loop, move the Sync down so it's between the Next Y line and the Next I line. You'll see a significant speed increase.

TDK_Man

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Feb 2007 01:45
@TDK and Nano

For a really big speed increase, save you bitmap to a file and read it back checking for colors <> 0, Of course you'll have to account for byte padding in the bmp. This is how I did mine. The file is basically a preformatted array so you don't have to go across the screen using POINT to find the colors.

Enjoy your day.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Feb 2007 02:00 Edited at: 17th Feb 2007 04:56
here's the draft:

[EDIT]

I'm gonna work on this a little more before posting it...

Enjoy your day.
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 17th Feb 2007 16:00
Thanks for the tip TDK

I can see you...
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 17th Feb 2007 16:03
Who votes we extend the deadline?

I can see you...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Feb 2007 20:08
Well, I for one am not going to benefit from a deadline extension - unless it's set to somewhere in June!

The only way I can think of to improve on what I've done already (apart from the speed increase gained by adding save/load bmp to avoid using the Point command) would take far too long to do.

Basically, the idea I had was to convert the raster image of a character into a vector image and then construct a totally new .X object from the data, save the .X file and then re-load it.

Creating from scratch and saving a .X file is working OK, but I'm stuck on turning the pixel image of a character into a vector (line) image. What's more it's incredibly slow!

TDK_Man

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Feb 2007 22:42
@TDK_Man

I hate saying this because it sounds like I'm just copying you but that was one of the solutions that I was working on! I just thought that was a bit meaty and maybe better suited for creating an entire 3d application... but, here's some ideas that you probably already considered:

Create a routine that draws the outline of the text. From there you will basically have a convex polygon. You can go through the polygon and find where the key points are (where the angle between segments change direction). Get these x,y coordinates. Next use a Delaunay tessalation algorithm to get the triangles (faces) for these points. Once you have the triangles, you have indeces for the vertex order. Add a z=0 to the x,y of the vertices. Duplicate the vertices but this time, give a z depth for the second set (maybe something like z=5). All that's left are the edges that connect the first set of verts to the second. If you imagine your 3d text sideways, then the faces index basically go zigzag like a sewing seem. Create the faces using a clockwise vertex selection - and then you have the indeces for the side edges.

In the midst of all the face finding, you can calculate the face normals for each triangle. No need to calculate the vertex normals for DBC, since they can't be individually colored. In fact, you might be able to skip the normal calculation altogether, The X file should still work, but you might get an object that looks like it's missing panels.

Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Feb 2007 01:56
Quote: "Create a routine that draws the outline of the text. From there you will basically have a convex polygon. You can go through the polygon and find where the key points are (where the angle between segments change direction)."


I've got the outline of the text, but it's the second part that has me stumped. How do you treat a capital 'C' for example or an 'O'?

All we need is a routine which would take an X by X pixel image containing a raster image of a character and return the vector points to recreate the shape with lines. This set of points would be extruded to get the rest of the vertices in order to create the .X file.

Sounds quite easy when I put it like that doesn't it!

TDK_Man

Tone3e
17
Years of Service
User Offline
Joined: 17th Feb 2007
Location: here
Posted: 18th Feb 2007 03:41
please don,t unsticky this. I e been following these challenges closely, but couldn't enter my entries, because my internet connection sucked and then I couldn't register into this site. I did the paint challenge semi successfully. I will try this 3d text challenge although it seems sort of complicated. Thanks for everything TDK because your tutorials in your site have helped me out a lot in getting started with darkbasic. Guess I will go to work on the challenge now.

Future programming master.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Feb 2007 03:43 Edited at: 19th Feb 2007 01:47
The whole extrude thing is what had/has me pulling my hair out.

[EDIT - lot's of blah blah blah]

Super simple method: Take all the x and y coords. of the pixels in the letter, and divide them by an imaginary z one at a time. Then draw lines from the original x and y to the new x and y and voila! you have your 3d text. Lot's of polys though.

Enjoy your day.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Feb 2007 01:17
Well, too much trouble doing it the really hard way with the dealine being today! So here is a different way:

Press Y to enter new text. Just type the text after the prompt up to 255 characters. use the mouse to move around. Left click zooms in, right click zooms out.

I originally had paired matrices so the letter protruded on both sides, but without texturing, it doesn't add much, so I removed it for this demo. The code is thrown together last minute so it's a bit sloppy.



Enjoy your day.
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 19th Feb 2007 08:32
Is it over already?

I can see you...
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 19th Feb 2007 08:57
OK I'd better get marking:

Lukas W
Simple, very fast working, but no colours or characters other than letters.

TDK 'easy way' 1
Simple, very fast but you couldn't enter the text when you run the program (although, you could enter it in the code)

TDK 'easy way' 2
Same as 'easy way 1' but it was mouse controlled and had a nice layered effect.

TDK 'hard way'
Takes a while to work, but a very nice shadow effect.

Latch
A creative and imagnative idea, very fast, but no colour.

OK and my decision:

Runner up :


Winner :


Now to the winner to set the next challenge.

I can see you...
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Feb 2007 18:30 Edited at: 1st Mar 2007 08:25
Thanks Nano! I was hoping to get something else in, but I ran out of time!

Anyway, here's the next challenge everybody. Read it through and let me know what you think... I don't believe it's too tough:

[EDIT] changed some stuff 2/20/07 - last changes (I Promise - I hope)

Help Karol the Robot Through the Maze

Once upon a time, Karel the robot lived in a city of geometric shapes. Karel's friend, Karol lives there too. It was Karel's lot in life to be taught how to interact with it's environment through very basic commands. Now that task has fallen to Karol.

It's your job to get Karol through the maze. I have included a program that creates a maze, Karol (a green cone), and three of Karol's deactivated friends (grey cones).

You must create functions, subroutines, and code in general to add to the program to "teach" Karol how to get through the maze, pick up each of it's friends (one at a time), and bring them back to the three squares in the lower right area of the screen.

Here's the full criteria of the challenge:

1. The goal is to create some kind of method, to get the green cone through the maze and pick up it's buddies and bring them back one at a time. It is a race so you have to create a routine that does this as fast as possible. Karol will keep running at a constant speed. You may not change this by stopping, speeding up or slowing down Karol.

2. You may not alter any of the code that is already part of the "shell" of the main program. That includes changing the speed of Karol, turning off collision, making all the walls disappear, etc.

3. You may, however, add as much code as you want. You cannot add code to any existing subroutines except for _main and _init. You can create as many new subroutines or functions as you want. You may rename existing subroutines as long as they are called (activated, jumped to) by the shell program the same way.

4. You CANNOT directly plot Karol's path through the maze. You can use waypoints, you can use logic, you can add additional objects if you like. One thing to note: Karol doesn't like the walls and when it bumps into them, it turns around and goes the other way. You also cannot just walk around the outside of the maze as a shortcut. No credit for that!

5. To keep things consistant, all entries will be run at 40 fps. While there is some pretty heavy collision calcs going on, it should still run at that. At the very least, I'll be able to test the entries at 40fps. I will include a built in timer that will automatically stop when all 3 friends (grey cones) are positioned on the 3 matrix squares on the bottom right. To start the program, you must press the CONTROL key. From that point on your routines should be referenced.

6. You can position the camera however you want. You can even move it around or pan it, or whatever.

While this challenge is a little tricky, it's not too hard. Please label clearly all the additional code and routines that you've added so it can be sorted out later and I know the original code hasn't been changed.

I'll give this a one week time limit plus a couple of days since I changed the program: Sunday, March 4 at midnight GMT

The winner will be the robot that completes the test in the least amount of time. Since the timer will be in milliseconds, it's very unlikely that there will be a tie. So cut every corner that you can!

NOTE : the routine _move_friends is just a test of the _timer procedure. The gosub _move_friends is commented out in _main. If you uncomment it, after 6 seconds it will move the 3 grey cones to the final resting positions on the matrix in the lower right, stop the program, and display the time. In your final program, you will at the very least want this commented out or you can remove it from the shell program all together.



Enjoy your day.
NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 19th Feb 2007 19:17
Www, this is gonna be a hard one... but I have an idea on how to do it...

I can see you...
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Feb 2007 19:28
Too hard, do you think? Or maybe a little longer deadline?

Enjoy your day.
Unstable data
17
Years of Service
User Offline
Joined: 12th Jan 2007
Location: Texas Panhandle
Posted: 19th Feb 2007 20:21
I can only get it to run at 31 fps so how is it that you want the program for karol to run at 40 fps if you are only at 31 fps to start.
I have one of the fastest computers out so I am puzzled at what you are asking for in your challenge.Please forward a repsponse.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Feb 2007 20:27 Edited at: 19th Feb 2007 20:40
Congrats on winning Latch!

[Edit] Unstable data:

It shows 31 fps for me too. Don't worry about it.

Setting the Sync rate at 40 doesn't guarantee that your program will run at exactly 40 fps - Latch is just saying that we can't change it to something else to speed it up!

[Edit2] Latch:

Permission to change the procedure labels please? My IDE displays all functions and labels alphabetically and if every one starts with an underscore it messes up.

TDK_Man

Unstable data
17
Years of Service
User Offline
Joined: 12th Jan 2007
Location: Texas Panhandle
Posted: 19th Feb 2007 21:01
i need to know if we are allowed to use his data statements or are we allowed to use limbs to detect where the blocks are or are we just going to keep hitting the walls until we map out the whole place. I haven't found a statement in darkbasic yet that tells me where the walls are in 3d space where in 2d i could use point to find out if there was a wall and map it out, but if you bump into a wall it messes you up. So i am at a loss as to how to be able to do it unless i make the map by hitting the wall or use the data he has put in, if i can use his data statements it would be easy to do.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Feb 2007 21:33
Sorry to nitpick, but a question about rule 3:

Quote: "You cannot add code to any existing subroutines except for _main"


Shouldn't we be able to add code to the Init function as our code is going to need variables declaring and such. I don't like the idea of squeezing them in between the Main label and the Do!

TDK_Man

Unstable data
17
Years of Service
User Offline
Joined: 12th Jan 2007
Location: Texas Panhandle
Posted: 19th Feb 2007 21:50
I think this challenge needs to be changed, because there is to much that won't be able to be done by someone new to programming, to make everyone happy I will include myself in there, won't be able to do, and the rulz are not making any sence to me.
so lets try something different and if ya want to do that try it in the Darkbasic Pro section where they know more about programming and have a better language to work with.
Anyone agree with me on that???????????
Lukas W
20
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 19th Feb 2007 22:11
cool! neat challenge

NanoGamez guy
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 19th Feb 2007 22:35
Keep the challenge, The language is not that important, but you just have to think about how you can do it a bit...

I can see you...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Feb 2007 23:19
Quote: "Anyone agree with me on that???????????"


Some parts yes - others no.

Yes it is a difficult challenge for newcomers, but you need the occasional head-scratcher to make you think. Don't forget that the easy challenges are often too easy for the more experienced coders, so it's a case of swings and roundabouts.

As for this being better a DBP challenge as that's a better language, I disagree. DBP has a few extras that DBC doesn't have, but none that would be of any use in solving this particular challenge. In DBP, you would still have exactly the same programming logic problems to figure out.

Incidentally, if anyone is struggling with this challenge, think about placing a hidden cube in front of the robot as it moves around and checking for collision between the cube and the walls...

TDK_Man

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Feb 2007 03:05 Edited at: 20th Feb 2007 03:31
[EDIT]

Not sure why this double posted

Enjoy your day.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Feb 2007 03:27 Edited at: 20th Feb 2007 05:45
Ok we'll keep the challenge. But I'm open to change some of the parameters if necessary. It is about being challenging but I would like people to think it's fun also.

@ everyone
31 fps? really? I'm running an AMD at 1.5 ghz at it runs at 40 fps. Try changing the sync rate to 0 and let me know how fast it is running. Maybe i'll have to change the collision routine.
If the FPS for most people ends up being lower, then the lowest FPS will be the benchmark. I'll have to feel this out as we go along. In the end, I'll be running all of the prgrams from the same machine, so the overhead will be consistant. The whole point is for speed consistancy in timing how long it takes Karol to do it's job.

@Unstable Data:
You can't change the data statements (that's the maze) and you can't change any of the characters by adding limbs. But you can add additional characters (objects) if you want.

Oh and if you are having trouble with an idea, just ask. These challenges are really about learning and helping each other out. And if you see some code that you like or works, it's completely legal in these challenges to use it and improve on it.

The rules are basically, you can't change the program as it stands, but you can add code to it. Your code should be a way to get the green cone (it will keep moving forward non stop) through the maze without directly telling it where to go. By that I mean you can't write a routine that says for example " go forward three squares, then turn right, go forward 2 swuares then turn left" until you've mapped Karol's path directly. The goal is to use the environment, or teach it the logic of going through the maze. For example, you can find Karol's y angle, and if it's an angle you don't want you could have some code that will rotate it to a different angle. You can add waypoints - areas that the cone is attracted to.

@TDK_Man and Everyone
Yes you can add code to the init subroutine if you want to add variables and other branches and such.
Yes you can change the names of the subroutines, as long as the shell program calls them the same way.

---Note to Eveyone: You cannot bypass routines. For example, in _main, there is a gosub _move_robot. This has to run every loop so that Karol is moving at a constant speed.

And if you haven't picked up on it yet, look up the programming language Karel.




Enjoy your day.
Unstable data
17
Years of Service
User Offline
Joined: 12th Jan 2007
Location: Texas Panhandle
Posted: 20th Feb 2007 03:29
@latch
I didn't say anything about changing the data, I was wanting to know if i could reread them for my part of the program so i could have the map or if i need to go through the map and find my own way through it and make my own copy of it, aka do i get to use the data statements as if the robot would see the walls or if i need to have the robot bump into the walls and figure out where the wall are as if it has no sight, you still have me lost on what you want, because if i use the data statements it would be like it could see the walls but if not allowed to use the data statements then it would have to figure out where the walls are by walking into them, (because you said no limbs) so you lost me on this
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Feb 2007 04:33
Quote: "I was wanting to know if i could reread them for my part of the program so i could have the map"


As the whole subject of this challenge is AI, I'd say that the answer to that would be no. There's no intelligence involved in reading a map.

Rule 4 outlines this. You have to program some form of artificial intelligence into the robot to sense what is around it. This basically restricts your options to using collision commands.

The code Latch supplied shows how this is used, so if you're not too hot on collision, you should be able to figure out enough from his code. There's also my basic collision tutorial in the sticky at the top of the Newcomers board...

Making your own map as the robot goes around would be an acceptable solution - a pretty good one too.

Quote: "(because you said no limbs)"


Did you read the last paragraph of my last post? Using other objects in the solution has not been ruled out.

This challenge is good because how it is done is a good grounding for basic AI in any 3D game where you have characters wandering around under their own control - as opposed to moving via a 'map' (waypoints). They need to be able to negotiate and learn from their surroundings.

TDK_Man

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Feb 2007 05:55
@Unstable:

Very clever idea, but like TDK said, you can't have the robot know the map ahead of time. It's all clear in my mind but I'm probably not describing the challenge quite right. You could have the robot "learn" the map as it went along so that the next time through it was easy for it - so in that sense you could store the map. I was think more along the lines of the robot having to figure out which way to go.

When I mentioned being able to use waypoints, I was thinking along the line of the robot figuring out the map and marking the right way to go as it learns it.

The goal is to have Karol interact with the environment. That can be as simple as Karol bumping into a wall, or as complicated as raytracing.

You can create as many aditional objects as you want to help you.

Enjoy your day.
Unstable data
17
Years of Service
User Offline
Joined: 12th Jan 2007
Location: Texas Panhandle
Posted: 20th Feb 2007 07:07
@latch
Thank you now i Know how i am going to do it. I was just confused on the stuuf about what i could use and how it was to be done. now that i know i can use additional objects and that it needs to interact with the enviroment to figure out what way it needs to go that make sence to me now. I will be working on my entry, now that sounds like fun seeing what everyone comes up with.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 21st Feb 2007 03:05 Edited at: 21st Feb 2007 03:07
Ok everybody. You'll probably want to kill me for changing things, but I wasn't happy with how slow the program was - due to the number of objects and collision. I rewrote the _plot_maze routine so that it uses extended boxes if there is a wall that covers more that one grid square. This reduced the objects by more than 20, thus the collision check is faster, and thus the program runs at a higher frame rate (with sync rate set to 0 ). So squeezing out 40 fps shouldn't be a problem.

Here's a big change that may affect how you've been coding so far (sorry! ) - I decided to add a built in timer function so that that part was consistant across programs. It wasn't very smart of me to include in the rules that the contestants should build a timer routine. There should be only one that everyone uses so that makes things a little more fair. I've changed the challenge rules a bit and extended the deadline to Wednesday feb 28.

I'll include the new shell program here and also in the original challenge thread. Some things I added:


In _init I added some timer reference variables and the code to start the program running. When you press CONTROL, control of the program is turned over to _main (the program and timer start)



I added a 2 routines:
_timer and _move_friends

_timer is the timer routine that is called in the main loop. When all three friend cones are placed on the final matrix in the right order, the timer and program will automatically stop and display the time.

_move_friends is just a test routine I wrote to make sure the program will stop when the friends have been put in their final resting places. After 6 seconds, the friends will be moved and the time displayed. I have the gosub commented out in the main loop, but I'll still include it in the shell if you want to test that the timer is working. In your final program, you'll want to comment this out or eliminate it from the shell all together. Check the variable names in both _timer and _move_friends to make sure they aren't conflicting with code you have already written.

Sorry about that!

Here's the new shell. Hopefully, I won't be making any more changes.



Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Feb 2007 08:48
Oh bugger! Are all those damn underscores back at the beginning of every label????

(The other changes don't bother me that much)...

TDK_Man

Data
19
Years of Service
User Offline
Joined: 26th Nov 2004
Location: Winnipeg,Canada
Posted: 21st Feb 2007 23:56 Edited at: 21st Feb 2007 23:57
Hi

I'm pretty new to Darkbasic but I was tring out this challenge a lot and came to two problems, both of which I have an idea on how to sole but am unsure of the exact code for it, perhaps someone can help me with them.

Firstly, how would you get the cone to rotate to face a specific object.

I know I would likely use


yrotate object robot,(not sure what to put here)


I know you would have to use some kind of angle but I'm not exactly sure what it would be or is the only way to do this is just test the program, look at what direction the cone is facing, and put in the degrees? The problem with this is that if you would have to keep checking which way the cone is facing now.

My other question is that say you wanted to keep an object (not necessarily the cone)say 4 units aways from the wall and constantly moving and turning with the wall and turning as the wall turns; how would you go about doing this? I know that you could just position it at that distance and tell it to move forward but how would you do it if the wall turns


for example:

o
wwwwwwww
--------------w
--------------w


the 'o' represents the object that has to move and 'w' the walls. So to make the 'o' move along the wall I could just give it the comman 'move object 1,2' but if the wall turns like that one in the diagram, how could I make sure that the 'o' also turns with the wall. I think that I would have to do some kind of a collision check in which as long as if the 'o' was to move down whatever amount of units there would be a collision then the 'o' can keep moving forward but if there was no collision below it, the 'o' would have to move slightly up check if there is a collision around it, if not, move slightly down, check if there is a collision around it, if there is then begin moving that direction. the only part that am un sure of is how to go about checking collision. From looking and examining the code given, I figured collision could be stored something like this


test= object collision(1,0)

`and then you can check it by

if test=0 or friend(1) or friend(2) or friend(3)



else
`rem everything I would want to happen when there was a wall collision would come here I think


endif

Still I am unsure of how to check if there would be a collision if the object moved 4 spaces any way and if there wasn't how to make it turn and move forward until it found one again.

Thanks

Data

www.urbn-tremor.net
luke810
17
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 22nd Feb 2007 03:26
In response to your first question, you can use trigonometry or the point object command. Using the point object command you would do this



Where obj is the object you are turning and unit is the object it is turning towards.

Using trigonometry you can take the arctan of the z distance between the first and second objects squared divided by the x distance between the objects squared. This would give you the angle to point the first object towards the second. I'm not positive this is the best way to do it but I always use a trigonometric formula to find angle values.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Feb 2007 09:44 Edited at: 23rd Feb 2007 02:14
@Data

Like luke810 said, using the POINT OBJECT command will point your object (in this case Karol the robot) where ever you tell it . I would change luke's example a little bit, because you don't want Karol to point towards y=0, because then it would be pointing down. You want to keep the y height at the same level as Karol.

So if there was an object on the board called BLOCK, and you want Karol to face it (rotate towards it), you have to know BLOCK's x and z position, which can be obtained through OBJECT POSTION X(BLOCK) and OBJECT POSITION Z(BLOCK). And like I said before, you also need Karol's y position - so you could look it up in the code I provided and use a constant, or you can look it up dynamically while the program is running with OBJECT POSITION Y(robot).

So the example would look like this:



And that would point Karol at BLOCK - handle's the rotation for you.

Your second question,

That could be handled in many different ways depending on how you are moving the object,it's size and so forth. But in general if you want to keep the object 4 units away from the wall at all times, you have to test the units position against the position of any wall within a specified radius (~1 grid unit in 4 directions assuming the object is rotating at 90 degree increments). If the test reveals that there is no contact within that radius, then that probably means it's an empty space.

An easier way may simply be to let the object run into a wall and then change it's direction until it doesn't run into a wall anymore. This is the example that you were providing - that looks like a sound method.

so put you code in a routine that gets checked once each time through the main loop:



the actual command to rotate the object are (excluding pitch and roll):



But let's say you end up somewhere in open space - outside of the maze and you have no objects around to test collision. Will Karol run on forever? How do you stop it? You'd have to look in the shell program and try and figure out the maximum distances you want to allow the object to move. If it's position at any given moment is outside of the limits, you'll have to take action!

Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Feb 2007 21:50 Edited at: 23rd Feb 2007 10:32
I would suggest keeping it simple.

In the maze, the cone only needs to point in one of four directions and as it starts off pointing to the right, then forget rotating - use Turn Left 90 and Turn Right 90.

You can always get the current direction the cone is facing by using Object Angle Y(robot) - it can only ever be 0, 90, 180 or 270 degrees.

TDK_Man

Data
19
Years of Service
User Offline
Joined: 26th Nov 2004
Location: Winnipeg,Canada
Posted: 23rd Feb 2007 00:53
thanks to everyone, that really helps and I may even be able to submit a challenge entry for my first time

www.urbn-tremor.net
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Feb 2007 21:23 Edited at: 1st Mar 2007 08:28
Well,

There's only a few hours left for this challenge and not a single entry so far.

[EDIT] So I'm extending the challenge deadline to Sunday March 4 2007 midnight GMT.

Oh well, maybe they will be last minute. Here's my entry just for fun. At 40 FPS it takes about 106 seconds to finish. The routine I used could be improved upon. I basically just collide with a wall and rotate Karol until it can find a way to go. There's better ways to do this kinda thing. Anyway, here it is:

(if it seems too slow, change the sync rate to 0)



Enjoy your day.
Data
19
Years of Service
User Offline
Joined: 26th Nov 2004
Location: Winnipeg,Canada
Posted: 1st Mar 2007 01:02
well I honestly gave this one a shot but unfortunately just couldn't figure it out and seeing as the contest ends at 12GMT looks like its already over.

www.urbn-tremor.net
luke810
17
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 1st Mar 2007 01:48 Edited at: 1st Mar 2007 04:11
I had actually set up an A* pathfinding algorithm that updates the "walkability" array for tiles adjacent to the robot so he has learned the entire map after the first freind is found, but I didnt have time to finish it up before the deadline.

Here is the script I had up to when the competition ended for anyone who wants to see it. The pathfinding algorithm works but I was having problems carrying out the path and recalculating the waypoints with data from the robots "Sensory Input" at the same time.



If anyone doesn't know what A* is there is a website describing it here: http://www.policyalmanac.org/games/aStarTutorial.htm
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st Mar 2007 03:58
Aw common guys... I was really hoping to see some examples.

Would it help if the deadline were extended to Sunday March 4 ?

If there's no interest in this challenge , then since TDK was the runner up of the last challenge, maybe he should set the next challenge.

Enjoy your day.

Login to post a reply

Server time is: 2024-04-18 05:27:20
Your offset time is: 2024-04-18 05:27:20