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 Professional Discussion / - DBPro Coding Challenges -

Author
Message
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 3rd May 2010 06:04
Okay, see how the new version works. Changes are that the function will now return 3 as discussed, or -1 if the coordinate is out of the proper range. There's also a debug number in the top left that gives the function result for the tile your mouse is over, so you can make sure it's working properly.

http://forum.thegamecreators.com/?m=forum_view&t=48011&b=1&msg=2004932#m2004932

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 3rd May 2010 06:13 Edited at: 3rd May 2010 06:14
you are overly awesome. i'm going to install dbp on my wife's laptop while she's asleep...just so i can do this.
thanks!
bob

waiting for ATHF 100

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 3rd May 2010 06:26
Quote: "you are overly awesome. i'm going to install dbp on my wife's laptop while she's asleep...just so i can do this.
thanks!
bob"

Ha, okay .

Quote: "waiting for ATHF 100"

Huh?

Coldfire
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location: Indiana
Posted: 3rd May 2010 14:33
I think he may be referring to the Aqua Teen Hunger Force episode 100... I could be mistaken tho :/
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2010 15:50
Damn, I'd better work on my function then to include the '3' return!

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 4th May 2010 05:24 Edited at: 4th May 2010 05:26
i have been working on this, and found a problem with the 'sunk' function.

i put in a new color to mark a TOTALLY SUNK ship, and i use getp2board() within the drawboard() function.

there are times when a ship that is all hits surrounded by all misses shows up as 'still alive'.

there are also times that a single hit registers as "SUNK".

can someone else put something like this into their code and take a look at their results?



thanks,
bob

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th May 2010 05:34
Thanks ibol, I'll look into it.

Code always has problems .

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th May 2010 05:42
I couldn't replicate the problem at all.

I added your alternate coloring into the code into the contest post. Could you try it? And maybe provide a screenshot of a board that shows the problem?

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 4th May 2010 06:08 Edited at: 4th May 2010 06:10
i am running a modified version of your code that uses strings instead of the colored boxes because i couldn't get it to work.
(i'm running un-updated dbp straight from the disk because i have to install and uninstall every night.)

i've uploaded a jpg that shows 3 H (hits) surrounded by all v (misses) in the upper right corner. it they were kills, they would be 8 ( or *).

this code also runs multiple iterations and gives you an average and best.
(i don't mean it to replace yours, it's just what i'm using for development)



Attachments

Login to view attachments
IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 4th May 2010 06:22
here's another one, with a lone 8 in the lower right, which shouldn't be possible (a one hit kill)

maybe it's due to the un-updated state of my dbp...

Attachments

Login to view attachments
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th May 2010 06:52
Quote: "maybe it's due to the un-updated state of my dbp..."

I slapped my draw function into your code and watched it run for a good five minutes...didn't see anything of the sort. It could be your DB version...I'd be more inclined to believe it's your DrawBoard function.

Mystifying, I'll look at it more in the morning. In any event, it shouldn't impact the writing of anyone's entries, I'll just have to watch them carefully for errors when I'm judging them.

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 4th May 2010 07:08
bmac, thanks for all your help and attention.
since it seems that no one else is having these problems, i will trust that it works, and submit my entry.



baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th May 2010 11:40 Edited at: 5th May 2010 16:44
Here is my updated entry:


It seems to average at about 55 turns to finish so I'm happy!



EDIT: I just did an average test for @IBOL's code and it got about 53.5... It did seem to vary a lot more than mine though between 39 and 73 shots to win where mine was getting between 44 and 64. Maybe mine's slightly more consistant but it could mean I loose depending on the random order thrown up on the competition.

Ain't chaos grand!!

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 5th May 2010 06:36 Edited at: 5th May 2010 08:58
i got my new computer!
i got the pictures to work,
and maybe the rest of it too.

what upgrade of DBP are you guys running. i need a recommendation for a *Stable* upgrade.

i'm now operating dbp 7.0 final

also might to change my code a little...

Attachments

Login to view attachments
IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 5th May 2010 09:14
my god, i just go on and on.
fixed the =3 issue, and found something else.

@baxslash ,
i ran your code thru my fast iterator, and it freezes up sometimes.
i guess you need some value failsafes...
i would think a freeze in AI is a bug...
of course with all the other issues i've been having with getting a working version of DBP, it could just be my system again.

thanks,
bob

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th May 2010 16:24
Quote: "fixed the =3 issue, and found something else."


Yay! Was it just your code?

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th May 2010 16:31
baxslash, I think you forgot a letter on the very last line of your code...

IBOL, yours works just fine .

Quote: "EDIT: I just did an average test for @IBOL's code and it got about 53.5... It did seem to vary a lot more than mine though between 39 and 73 shots to win where mine was getting between 44 and 64. Maybe mine's slightly more consistant but it could mean I loose depending on the random order thrown up on the competition."

Maybe I'll make it out of five tests...

I remember in the RPS challenge, someone had my entry nailed...I think it was Aurum Knight. After about turn 20, the AIs would just go around in circles and mine would lose every single turn after the 20th .

I don't know why I remembered that...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th May 2010 16:45 Edited at: 5th May 2010 19:12
Quote: "baxslash, I think you forgot a letter on the very last line of your code..."

Oops, fixed it.

EDIT: Actually I decided to make some changes to fix the problem where my code was 'hanging' occasionally:


Don't think I'll add any more now... sorry!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th May 2010 19:29 Edited at: 5th May 2010 19:31
Regarding my previous post about the random nature of the game:

I decided to do a little test with my latest code (and the other code posted). I have written out the results of each code being run 3000 times (at about 10 games per second) to a log file along with an average...

The results were:
@baxslash averaged 58.338 turns (edit not seconds )
@IBOL averaged 58.87 turns (edit not seconds )

...as you can see the results even out to next to nothing over this many tests which means this is going to be completely down to luck (and which code @BMacZero likes more I guess)!

Interesting stuff! If anyone wants me to test their code (just for fun of course) then let me know!

acelepage
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 5th May 2010 19:41
@baxslash,
I think the measurement should be number of moves, not elapsed time. Since Battleship is based on sinking opponent's ships first, a win is based on the least number of turns.

( 2b || !2b ), that is the question. The answer: true
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th May 2010 22:33
@acelepage - I'm pretty sure that's what he's measuring.

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 5th May 2010 23:17
Quote: "Quote: "fixed the =3 issue, and found something else."

Yay! Was it just your code?
"


nope, i didn't change my code at all,
but when upgrading to dbp7.0 and DX9 2006,
it worked just right.

i have no idea what dbp was doing,
but it seems fixed.

amazing that our 2 approaches yield such close results.
thanks, that was cool,
bob

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th May 2010 11:03 Edited at: 6th May 2010 11:45
Quote: "I think the measurement should be number of moves, not elapsed time. Since Battleship is based on sinking opponent's ships first, a win is based on the least number of turns."

That was a user error, should have been turns

Quote: "amazing that our 2 approaches yield such close results."

I was quite surprised. I think that really our approaches are pretty similar though

IE.
1-Search random squares until a hit is found
2-Find whether the ship is horizontal or vertical
3-Keep blasting in each direction until you either miss or sink the ship
4-Goto 1

The only slight difference is in which squares we search. I thought that by searching every other square first I had a better chance of getting all of the ships first but that doesn't seem to make much difference over several thousand attempts...

Maybe some military search algorithms would work better to find the ships in the first place. Anybody know any?

EDIT: I just found a great idea for an algorithm and followed it up with code.

It searches using a gradually decreasing grid which will catch the larger ships first and then close down on smaller ships as it goes but the first 2000 tests came out at about 66 turns... chaos rules (and logic drools)

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 6th May 2010 16:18
Quote: "It searches using a gradually decreasing grid which will catch the larger ships first and then close down on smaller ships as it goes but the first 2000 tests came out at about 66 turns... chaos rules (and logic drools)"

Only for very small grids, I imagine .

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th May 2010 16:53
Quote: "Only for very small grids, I imagine"

Actually it shouldn't make much difference...

It works like this:
1- select randomly from;
---first search----
x 0 0 x 0 0 x 0 0 0
0 x 0 0 x 0 0 x 0 0
0 0 x 0 0 x 0 0 x 0
0 0 0 x 0 0 x 0 0 x
x 0 0 0 x 0 0 x 0 0
0 x 0 0 0 x 0 0 x 0
0 0 x 0 0 0 x 0 0 x
x 0 0 x 0 0 0 x 0 0
0 x 0 0 x 0 0 0 x 0
0 0 x 0 0 x 0 0 0 x

---second search---
- 0 0 - x 0 - 0 x 0
0 - 0 0 - x 0 - 0 x
x 0 - 0 0 - x 0 - 0
0 x 0 - 0 0 - x 0 -
- 0 x 0 - 0 0 - x 0
0 - 0 x 0 - 0 0 - x
x 0 - 0 x 0 - 0 0 -
- x 0 - 0 x 0 - 0 0
0 - x 0 - 0 x 0 - 0
0 0 - x 0 - 0 x 0 -

Actually I got these back to front but you get the idea...

...then it searches using my current grid for the remaining squares (over the top of previous grids but not including already used squares);

---third search----
x o x o x o x o x o
o x o x o x o x o x
x o x o x o x o x o
o x o x o x o x o x
x o x o x o x o x o
o x o x o x o x o x
x o x o x o x o x o
o x o x o x o x o x
x o x o x o x o x o
o x o x o x o x o x

...and finally it randomly looks at the remaining squares using your original code.

I don't think a larger grid would be any better or worse for this technique. Of course my coding could be dodgy (care to look?)

THIS IS NOT MY ENTRY!!


acelepage
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 7th May 2010 23:27 Edited at: 7th May 2010 23:29
I wrote this code over lunch. I didn't have time to test thoroughly. A few runs through seemed OK.



( 2b || !2b ), that is the question. The answer: true
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th May 2010 22:19
@acelepage, I tried to run your code using my 3000 runs test but it gets 'stuck' before running three times every time, sometimes less.

It might be that something needs resetting each time the game is won but I tried clearing your board array and it didn't help, any ideas? I'm interested to see how it compares as when it does finish it seems to do quite well sometimes (30 turns was the best so far).

acelepage
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 8th May 2010 23:23 Edited at: 9th May 2010 05:21
I have run through a number of iterations and have found situations that cause endless loop. So, I have re-gigged it. I have run this version through 20 or so iterations without issue. hopefully this will stand the 3000 test.


Edit: to reset my code, just set the variable myoffset=0. This will cause my function to reset all variables to starting point.

( 2b || !2b ), that is the question. The answer: true
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 9th May 2010 18:14
Okay, the results are in:


Therefore, the winner is


I though acelepage would have an advantage because of his initial search method - after all, one method is as good as another once you get a hit, but there you have it.

Nice entries all .

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 10th May 2010 02:27
woo hoo! thanks for getting me back into programming.
i know i got lucky , because there is randomness,
and we got some help from Bmaczero, since he adjusted his code for us.

i will set another challenge hopefully within a day.

i just cranked out a 20-liner,http://forum.thegamecreators.com/?m=forum_view&t=169862&b=11
but i'm ready for more.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 10th May 2010 02:31
Yeah, if I had to do it again I'd do something like baxslash did to minimize the randomness. But that's how I said I was going to do it, so there you go .

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 10th May 2010 02:41
Congrats IBOL!! Nice 20 lines .

cheers.

I'm not a grumpy grandpa
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th May 2010 11:17
Congrats IBOL! Your code was certainly much more concise than mine too!!

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 10th May 2010 17:05 Edited at: 11th May 2010 02:42
hey thanks everyone!

so listen, i think in the past there was a seperate page or website that listed all of the coding challenges so far.
is that true? after 100k posts it gets a bit hard to make sure something hasn't already been done.
anyway, here's what i am thinking for the next challenge:

===========================================
write a procedural world terrain generator.
===========================================

a program that creates a random 'world' of oceans,lakes,rivers,mountains,deserts,grassland,forest,icecap,etc.

this challenge would not be so much about displaying the world,
but in making it realistic. not just randomly place a forest in the ocean or desert,but a smooth, logical transition and development across the world.

here's a little code i wrote to display your world once you've created it:


my example world is an x/y array of 200x200.
the values stored in the array are the kind of terrain you would find there (water,trees,etc.)
find a way to fill that array.

extra points for :


feel free to make your own display function,
but i'd still like to have the results availble in 2D to look at
(like if you want to wrap it around a sphere)


time limit 10 days (that's noon on may 20th from my US EST)

good luck!

EDIT: i mis-spelled ink (i used inc rgb(245,222,179),0)
i fixed that, so anyone cut/pasting my code should get the new one
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 10th May 2010 17:21
Oh, neat. I'll be in this one I think .

Quote: "so listen, i think in the past there was a seperate page or website that listed all of the coding challenges so far.
is that true? after 100k posts it gets a bit hard to make sure something hasn't already been done."

dbp-site.com, however it is long gone.

I could add a page on the wiki listing the challenges and possibly linking to the start posts. Would take a while to sift through the 71 pages, though.

IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 10th May 2010 17:25
@BMacZero
that's too much work!
you keep going on fields (i checked it out. looks great!)
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 10th May 2010 17:28
That's true, I should be working on that ...

acelepage
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 10th May 2010 23:25
Here's the 1st entry. I changed the colours so that I could see the gradient. The map should wrap around on both edges.




( 2b || !2b ), that is the question. The answer: true
IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 11th May 2010 02:46
first, embarrassing,
i mis-spelled ink (i used inc rgb(245,222,179),0)
i fixed that, so anyone cut/pasting my code should get the new one.

@acelpage:
in my opinion your resolution is much too low in your entry.
if that's a whole world, then you get a bunch of huge square areas.
and even when i change the resolution, it's more like a noise generator. there's no flowing geographical continuity.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 11th May 2010 02:58
@IBOL
I can see it. Try a resolution of like 5, and change the colors to your originals rather than all those shades of blue.

acelepage
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 11th May 2010 05:36
I expected some feedback on my entry. I throw it out there to test my interpretation of the challenge. I was thinking of a simple game board. I am thinking you are looking for something more like a simulation.
Onward and upward...

( 2b || !2b ), that is the question. The answer: true
IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 11th May 2010 17:15
what i'm thinking for the challenge:

imagine a map of the united state (or any country) without the cities, state lines, etc.
you have beaches and lowlands at the outer edges (and in fact oceans beyond that)
the rockies and appalachians flow down futher inland.
fertile plains in the center
southwestern desert, northeastern forests.
major rivers, great lakes, hills, swamps (everglades)
lots of features.

find a way to procedurally generate a world terrain map (not to be confused with any DB "terrain" )
it should be able to be used for a 2D rpg world, or to texture a planet sphere, or somehow otherwise represent the sweeping land and sea features of a world or continent.

i have attached a simple sample using my horrible mouse painting skills. i want something random and better.

Attachments

Login to view attachments
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 11th May 2010 19:35
Think I'll enter this.

My signature is NOT a moderator plaything! Stop changing it!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th May 2010 13:28 Edited at: 12th May 2010 13:39
Here's my initial attempt. It first generates a colour scale to be used to generate a texturemap based on a perlin noise generated heightmap. It then creates an advanced terrain and some water.

This is only an initial attempt, I've yet to include large terrains, and features. (Such as trees, rocks, ect.)

Space will show you the height and texturemaps, and enter will generate a new terrain.



*Edit* Oh yeah, uses an IanM plugin. Hope this is allowed!

My signature is NOT a moderator plaything! Stop changing it!
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th May 2010 14:58 Edited at: 12th May 2010 15:03
Hi all.



any idea?

re-edit...mmmmm I´m a fool....I need a plug-in
cheers.

I'm not a grumpy grandpa

Attachments

Login to view attachments
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th May 2010 16:30
Quote: "*Edit* Oh yeah, uses an IanM plugin. Hope this is allowed! "



My signature is NOT a moderator plaything! Stop changing it!
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th May 2010 23:09 Edited at: 12th May 2010 23:10
@Mobiius
Nice code ....I´v got something like that in 3D, but I think IBOL means something more like:




cheers.

I'm not a grumpy grandpa

Attachments

Login to view attachments
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th May 2010 00:50
Quote: "Nice code ....I´v got something like that in 3D"

???
It IS 3D?

And like I said, I haven't implemented large terrains to simulate islands and things.

My signature is NOT a moderator plaything! Stop changing it!
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th May 2010 01:22
Quote: "It IS 3D?"


We talk about 3D when we mean that is not 2D I never meant that is was a 3D object.

cheers.

I'm not a grumpy grandpa
IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 13th May 2010 07:08
@Mobiius :

i checked the rules (first page of this thread and follow links.)
IanM's plugin is not allowed.
no outside media, and just pure DBPro.
sorry

Login to post a reply

Server time is: 2024-11-27 22:03:16
Your offset time is: 2024-11-27 22:03:16