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
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 25th Oct 2006 17:52
Code challange entry for maths game.

Title: Projectile
Game Play: Take turns firing a projectile over a mountain at your opponent. First one with 10 hits wins.
Set the angle and power of your projectile, then fire.

I have added a Sound on/off function so all sound can be disabled.



( 2b || !2b ), that is the question. The answer: true
Spopovich
20
Years of Service
User Offline
Joined: 12th Jul 2006
Location:
Posted: 25th Oct 2006 22:22
Dang both of your enteries looked very nice. Acelepage, your game was addicting, its like that game tanks on line, well done. Now if I can just implement some math into my entry.....

Do not ask what the forums can do ask what you can do for the forums.
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 25th Oct 2006 23:35
@Spopovich: thanks for the comments.
I know what you mean about addicting. When I play the computer, and I miss my shot, I get very impatient waiting for the computer to shoot so I can go again. Sometimes I know right after I fire that my shot is going long or short and I have to wait over 5 seconds before I can tweak it and fire again!

I need to make some faster action games.

( 2b || !2b ), that is the question. The answer: true
Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 26th Oct 2006 11:48
@RBurke: Nice idea - and good presentation. There are several things, if you're interested, you could do to optimise your code which would make your game run much more smoothly, and make your code easier to read/manage. Even if you don't make any alterations to your existing code, these are things which will be very useful to know for next time.

Firstly, rather than putting all your active code into one big do-loop, which can become difficult to manage after it gets beyond a certain size, you should try splitting it into subroutines. It's no extra coding - it's simple. For example:



The great advantage of this, is that in your editor, to find a particular section of code, you just click on 'labels' in the project manager window, and click on the subroutine you want and it will take you to that bit of the code. It also makes your code easier to read for you and other people, and it means you can copy subroutines that work well into other programs more easily. Once you are used to using subroutines, you'll also want to look into the use of functions, which do a similar job but are even more reusable for other projects.

To make your program smoother (on my p.c. it was very slow and jerky), you should cut down on the amount of 2d drawing done every loop. Commands like line, print, and box are very slow - and repeating them every loop is unecessary. All you need to do is create a bitmap (an offscreen area the user can't see), do the drawing once onto the bitmap, grab the image, and paste it to a sprite. You can then position the sprite on the screen wherever you like without needing anymore drawing, until the actual drawing changes. For example, to draw your gui, you don't need anything in your do-loop at all:

instead of:


you would do:


Finally, entering numbers using 'inkey$()' can be very awkward if you are typing fast, because it will only allow a key to be pressed once another one has been released. Much better is to use the 'entry$(1)' command, with the 'clear entry buffer' command for inputting text. Try this example to see how text can be entered accurately at speed:



@Aclepage: Very nice rendition. I like the gui, and the exploding boxes. Looks like you've given yourself some stiff competition!

Wisewolf
19
Years of Service
User Offline
Joined: 12th Oct 2006
Location:
Posted: 26th Oct 2006 14:27
Nice games, unfortunatly I am unable to do this competition so I will hope to join in the next one. Personally I am hoping for a screensaver competition because it's simple and with the people here, there should be some superb entries. See you all in a week!
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Oct 2006 14:39
The exploding boxes are fantastic! I'm not sure about something though... I set and angle and used 8.3 power... too little. So 8.5... Too much... 8.4... Too much... 8.3... Too much. How did 8.3 go from being too little to too much?!

[center]
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 26th Oct 2006 18:05
@Nicholas Thompson:
The wind speed changes after every shot. So you have to watch the wind speed indicator at the top of the screen. Stronger wind makes the shot go further (unless it is blowing your way, then the shot distance is reduced).

( 2b || !2b ), that is the question. The answer: true
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Oct 2006 18:24
ohhh right! I didn't see that.

[center]
Rburke
19
Years of Service
User Offline
Joined: 28th Sep 2006
Location:
Posted: 27th Oct 2006 12:42
Ric, Thank you. I will take advantage of your advice. Though, one question stands. I do indeed love the entry command now that I've learned it; However, I would be interested to know how to convert stufftyped$=entry$() to stufftyped as integers. When I used c++ I remember using a strcmp command to help convert strings to integers. Is there a similar command I can use to convert the characters typed into being recognized as integers. Also what can I use to have backspace function so that a person can delete the last number/letter typed if he or she has accidently entered the wrong digit? Thanks again for you thoughts and advice
Spopovich
20
Years of Service
User Offline
Joined: 12th Jul 2006
Location:
Posted: 28th Oct 2006 02:05
Rburke, I think you need the val command, it converts a string into an integer. As for a backspace function one way is to use the left$ and len commands. The left$ command gets a string starting from the begging of the string entered to the number provided. The len command returns the length of the string. So if the string is a$ to take out the last character you could use a$=left$(a$,len(a$)-1). Though there is probobly a better way.

Do not ask what the forums can do ask what you can do for the forums.
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 28th Oct 2006 06:36
Rburke,
For backspace, you want to check for character 8 (as opposed to scancode 14). Like this:
if stuffyped$=chr$(8) then a$=left$(a$,len(a$)-1)

Spopovich, I like that way for removing the last character. Can't think of a better way.

( 2b || !2b ), that is the question. The answer: true
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Oct 2006 14:16
I'm BACK!!!

Some very good entries while I was away

It's going to be difficult judging this one

DarkBasic Pro Guy
22
Years of Service
User Offline
Joined: 4th Jun 2004
Location: Broomfield, Colorado
Posted: 2nd Nov 2006 00:23
Hey all I'm back, been very busy with school anyways I'll have to wait for the next challenge I guess (deadline being The Day After Tomorrow)

Wisewolf
19
Years of Service
User Offline
Joined: 12th Oct 2006
Location:
Posted: 2nd Nov 2006 13:28
Hello,
Just droped in to tell you that I am starting my own challenge based like this one except it is restricted to just screensavers. Just look up screen saver challenge and you'll find my post. Hope to compete here in the next challenge.
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 3rd Nov 2006 23:10
I believe the challenge is ment to be finishing today?

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Nov 2006 23:24
The DEADLINE is the 3rd November, (which includes 3rd of november)
So people still have the rest of today to post. I'll be judging in the morning *yawn*

Goodnight...

Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 4th Nov 2006 02:30
Wisewolf - look forward to your entry and "good luck" with your thread.

Diggsey - i like your golf game! looks good. I hope you know your responsibility for judging (ie, the collating of challenges into a zip file! )

Everyone else - good luck in this challenge.

[center]
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Nov 2006 05:26
I'm still only using a Mac at the moment. (been outa town, still am. NY was interesting on halloween)

I did have an idea to recreate Math Blaster, if anyone remembers that on the Apple IIe

I can start the next challenge next week though!

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Nov 2006 09:58
Lower Logic:
I loved the colour scheme, and it was good fun, only problem, was that it had a slight bug in level 2 where you couldn't shoot any more blocks (even after collecting ammo) The AI was pretty good as well.

Acelepage:
Truly brilliant, and unique idea! Good AI (although a liittle easy ) Very good use of DBPro's commands to create something fit for sale! The sounds were in time with, and fitted their actions.

Nicholas Thompson:
Good use of vertex manipulation for that gun, however, a I had a slight problem where the screen wasn't clearing properly. Also, I think the code could have been a bit more efficient.

Rburke:
The maths element was the best so far, and it was still quite fun. The only problem is that when trying to type quickly, it sometimes misses a keystroke. Code was a bit chunky, and could have been cut down.

Acelepage(projectile):
Again a very addictive game, good idea, although it did not have much of a maths element in it .

and the winner is...



Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 4th Nov 2006 11:53
Congrats Aclepage - two really good entries, either of which could have won to be honest. I played 'Maximum' several times against my girlfriend. (She beat me once, but she has a degree in maths so she should do!)

I didn't get time for this one unfortunately - hope to join in on the next one though.

Spopovich
20
Years of Service
User Offline
Joined: 12th Jul 2006
Location:
Posted: 4th Nov 2006 15:35
Well done Acelepage both of your games were extreamly fun. You did a very nice job. Hopefuly I actualy be able to work on an entry on the next challenge.

Do not ask what the forums can do ask what you can do for the forums.
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 4th Nov 2006 16:52
Thank you everyone, I had a lot of fun with this challenge.
As you may have noticed, I like to code programs that use the computer as an opponent. So I would like to present a challenge that involves some AI, but hopefully not too hard.


Challenge: create an X&O game (naughts and crosses), that you play against the computer.
I will judge entries based on the computer's ability to never lose. (I know this is possible from previous research). Looking for a game that will win or tie.
Extra points if you can pick who goes first. Groovy graphics always an asset.

Time limit: 2 weeks (to conclude on Nov. 17)

( 2b || !2b ), that is the question. The answer: true
Peter H
22
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 4th Nov 2006 19:15
end date is my birthday so i think i might enter

"One man, one lawnmower, plenty of angry groundhogs."
Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Nov 2006 12:01
Good challenge Aclepage. For those who are new to AI programming, noughts and crosses should be enough of a challenge for them to get their teeth into, but as you said, easy enough with a bit of research.

For the AI experts here, there should be plenty of scope to expand - eg. varying difficulty levels, cool graphics, perhaps even 3d noughts and crosses (ie. on a 3x3x3 grid)?

Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Nov 2006 14:22
It could also be expanded to larger-than-3x3-grid version.

Acelepage - Make an announcement on the DBP board about the challenge. Could get a few more people in - although might wanna make it clear that its an announcement about an official challenge - not one of the recently common challenge people are posting for the hell of it.

[center]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2006 15:15
@acelepage

Just returned to the Challenge pages after a long absence. That winning entry of yours ("Maximum") was fantastic. Very simple idea, fun to play and well put together. Thought-provoking too. For example, it's not clear that the obvious "greedy" strategy of always choosing the highest number is a good strategy. Is it always possible for the first player to win? Etc, etc.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Nov 2006 15:20
I just found a way to make an object of each O and X Woohoo!

acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 6th Nov 2006 03:22
@Green Gandalf
Thanks. I set up the computer to look for the number that will set up the opponent for the least amount of gain, rather than just picking the highest number in the row.

X&O challenge: Hint
There are only 3 opening moves in the game: center, edge, corner. Wherever the opening move occurs, you can rotate the board so that it matches one of these opening moves.

( 2b || !2b ), that is the question. The answer: true
Dbproguy
19
Years of Service
User Offline
Joined: 1st Nov 2006
Location: At my computer desk no-life programming
Posted: 6th Nov 2006 06:04
I'll have a try at this.

I'm such a n00b (Dark Basic Pro Guy is my older bro btw!!!)
[/url]
Tinkergirl
23
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 6th Nov 2006 21:12
@Nicholas: Sorry I've been away, I just thought I'd mention that one of the entries in your page doesn't want to appear - the Kaiyodo Flocking Clock entry.

http://forum.thegamecreators.com/?m=forum_view&t=48011&b=1&p=48
Or, post number 689028, I think. Eyes hurt now - so many pages.

Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Nov 2006 22:09
There is a slight bug with the code highlighter... It gets itself into an infinite loop when a certain situation occurs and the criteria to end the loop is not met and instead the pointer goes back to the beginning of the code. I'll look into it - I'm actually working on a newer version of the site which should make finding code MUCH easier.

[center]
Dbproguy
19
Years of Service
User Offline
Joined: 1st Nov 2006
Location: At my computer desk no-life programming
Posted: 9th Nov 2006 02:35
I think I'm doing well, but the AI is seriously hurting my head (*gets some ibuprofen or however you spell it) I'm using a box for the background (box 0,0,640,480,magenta,blue,white,yellow looks good for now, might change)

I'm such a n00b (Dark Basic Pro Guy is my older bro btw!!!)
[/url]
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 9th Nov 2006 15:26
X&O Challenge Hint:
You only need to look for 3 conditions when making a move.
1) Look for a win. Look for a line with 2 of your pieces and a blank square.
2) Look for a block. Look for a line with 2 of your opponents pieces and a blank square.
3) Look for a blank square. If condition 1 and 2 are not found, then pick a square to place your piece.

( 2b || !2b ), that is the question. The answer: true
Spopovich
20
Years of Service
User Offline
Joined: 12th Jul 2006
Location:
Posted: 9th Nov 2006 23:07 Edited at: 10th Nov 2006 04:26
This is a cool website that I learned a few things from. Actualy I'm kinda copping them. http://ostermiller.org/tictactoeexpert.html
It has four levels of difficulty and the expert never looses. It tells you the basics of how it works too.

Edit: My entry is working so I thought I would go ahead and post it. There are a few different difficulty options in... options. The buttons dont change when you hit them but just know that they were hit. I think Expert is unbeatable however I haven't tested it much. Expert is the default level. Hope you like it.


Do not ask what the forums can do ask what you can do for the forums.
Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 10th Nov 2006 11:44 Edited at: 10th Nov 2006 11:46
I think I beat it on expert - the options menu doesn't appear to indicate the level you have selected, so I can't be sure it registered my click on expert - but anyway, this is how I beat it:

If the spaces in the grid are labelled thus:

1¦2¦3
-------
4¦5¦6
-------
7¦8¦9

then the moves 8,6,9,7 seem to win every time.

acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 10th Nov 2006 22:19
@Spopovich,
I just took a quick look. Nice entry (naughts and boxes). I noticed that when I click Play, the game board comes up and my move has already registered. I need to be real quick on the mouse button, or else my click on the Play button also registers as a click on the game board.
I recommend placing the following code after the menu, but before the game board, to ensure the user has completed the mouse click (has released the mouse button).

while mouseclick()>0
endwhile

( 2b || !2b ), that is the question. The answer: true
Daemon
20
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 11th Nov 2006 03:43 Edited at: 11th Nov 2006 03:47
Tic-Tac-Cube

Rules:
-Get 3 in a row on any side of the cube to win.
-If a side gets completely filled it will be emptied.

Controls:
-Hold right mouse button while moving mouse to rotate cube.
-Left-click on face to see a text version of the board of that face where you can pick which position you want to put an x.
-If you decide you do not want to put something on that face just click near the bottom or right side of the screen.



The ai is not that good yet. If you see it do something excessively stupid (not win when it can in one turn; not block you when there is no reason for it not to block you) it would help if you could tell me where it should have gone and why so that I can look through my ai. I say this because I have had to do this a lot in my testing.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Nov 2006 10:14
If the person who goes first goes in one square, they will always win unless the computer goes in that square in the middle, which it doesn't!

eg:

me
x--
---
---

computer goes in another square

me
x--
-x-
---

computer
x--
-x-
--o

me
xx-
-x-
--o

computer
xxo
-x-
--o

me
xxo
-x-
-xo



Peter H
22
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 11th Nov 2006 15:59 Edited at: 11th Nov 2006 16:45
I'm almost done with my perfect AI (at least, i'm 99.9999% sure it's perfect ) i should post it later today... it can play both Xs or Os (first or second)

[edit] ok, here it is


it got kind of bloated for a tic-tac-toe program... (780 lines ) but i attribute that to the ai, which as i said, i'm pretty darn sure you can't beat... (if you have perfect strategy you can force it to draw every time though...)

if you do beat it (ha!) please tell me how you did it!

"One man, one lawnmower, plenty of angry groundhogs."
Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 11th Nov 2006 21:47
Good job - I'm pretty sure that is unbeatable.

acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 12th Nov 2006 01:43 Edited at: 12th Nov 2006 01:45
@Daemon,
There are 2 patterns to watch for which allows the opponent to win. One of these patterns I used against your program. Here it is:

X |   | O   I play upper left (X), computer plays center
---------   I play lower right, computer play upper right
  | O |     I play lower left (to block) and set up a 2 line win.
---------    Computer can only block one of the win lines.
X |   | X

I was able to win playing the corners. I haven't completely assimilated the IF statements in your code yet. I am wondering if you have coded for every possibility. Nice structured code though. Easy to read.

( 2b || !2b ), that is the question. The answer: true
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 12th Nov 2006 01:55
@Peter H,
Nice program. Keeps away from the danger positions, and takes advantage of the double win line strategies. You obviously are a good naughts and crosses player.
Surely some of the IF statements could be contained in a loop
However, this is not the 20 line challenge, so as long as it works.
One thing I noticed is after I play a game, I press a key, and it messages "Please enter either X or O". Even if I press X or O after a game, this message pops up.

Good entry.

( 2b || !2b ), that is the question. The answer: true
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 12th Nov 2006 23:09
Well, I have commented on placing the AI code into loops, instead of IF statements, so here is naughts and crosses in condensed form.

(for demonstration purposes only, this code is not eligible to win this competition)



( 2b || !2b ), that is the question. The answer: true
Peter H
22
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 12th Nov 2006 23:37 Edited at: 12th Nov 2006 23:44
nice, like i said, mine got bloated. I'll fix that return to menu bug.

[edit] ah, found ze problem



it was simply changing this line if scancode() > 0 and escapekey() = 0
to if right$(entry$(), 1) <> "" and escapekey() = 0

"One man, one lawnmower, plenty of angry groundhogs."
Hobgoblin Lord
20
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 14th Nov 2006 01:12
Solid AI Peter I played about 50 games with all variations I know and every game was a draw both as x's and 0's.

http://www.cafepress.com/blackarrowgames
Check out my great stuff here
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 14th Nov 2006 02:13
I wish I had time for this challenge (or any challenge!)

[center]
Rburke
19
Years of Service
User Offline
Joined: 28th Sep 2006
Location:
Posted: 14th Nov 2006 09:51
Ai needs work.
acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 14th Nov 2006 15:18
@RBurke,
Nice and simple interface. I couldn't see the AI at work here. The computer 'O' seems to just play across the top row no matter where the 'X' is played. I also experienced the computer missing turns. Perhaps it is playing in a square that was already played?

( 2b || !2b ), that is the question. The answer: true
Ric
22
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 15th Nov 2006 17:36 Edited at: 15th Nov 2006 17:43
Here's my effort:



It features the ability to play 3, 4 or 5 in a row, has a groovy plasma background, and the bit I'm mostly pleased with, is the antialiased text, which uses a combination of blurring, and then creating an alpha layer using an image memblock to blend the edges into the background.

Oh yes, the AI .... I'm pretty sure (at least I hope) it's unbeatable on 3 in a row. I haven't beaten it on 4 or 5 in a row either, but I don't know for sure if it's unbeatable.

The AI uses 3 rules regarding opening strategies (so, not AI at all, really), but then it uses a rating system to rate all possible moves, taking into account attack and defense.

Given more time, I would like to have tried 4 in a row on a 6x6 grid, as it makes for a more challenging and varied game, but the AI for that was going to get much more tricky. Perhaps another time!

acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 15th Nov 2006 17:58
@Ric,
Very groovy background.
I just gave it a try, and could't beat the computer on hard for 3,4, or 5 rows. I don't know if I'll have enough time to test all the combinations, but it looks pretty solid.

( 2b || !2b ), that is the question. The answer: true

Login to post a reply

Server time is: 2026-07-16 19:54:14
Your offset time is: 2026-07-16 19:54:14