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 / Need Some Help With A Text-Based Prototype

Author
Message
MonchoMeecho
15
Years of Service
User Offline
Joined: 10th Aug 2010
Location:
Posted: 4th Jul 2011 01:37
[Sorry I posted this original topic in the wrong forum]

Hey guys, just looking for some assistance.

I have very limited knowledge with DarkBasic Pro as I haven't used it for a very long time.

Basically I'm looking to set up text-only system that simulates battles between two or more characters and outputs the most likely outcome based on statistics I input (like attack, defence rate of fire etc).

So during fights I could factor in things like speed and a probability added to that to calculate how likely one character is to dodge an attack. I'd like it to run multiple tests and basically show results on deaths, survivals and draws for each character.

Thanks in advance for any help you guys can provide, some code examples will be greatly appreciated.
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 4th Jul 2011 09:52
Personally I'd keep each character in a typed array like this



Then i'd use a random number against their chances to hit and block and remove their attack points from their hit points taking into account their defense points etc. Or that would be my starting point anyway.

Keeping them in an array like that that will help you keep an easy eye on them all. I'd have a pointer to the maximum number in the array, then when one was killed sort the array to remove the dead one - ie copy all the ones ahead of if back 1 and reduce the pointer. Unless there are literally thousands in which case I might think about some sort of index to them so I only have to sort or order the index instead of copying all the data all the time.

If you are going to make it text based I'd recommend looking into the d3d_func commands. I use them all the time and they are much much faster than DB native text or print commands, and allow you to do much more. Find them at:

http://forum.thegamecreators.com/?m=forum_view&t=69221&b=5

and

http://www.dbdepot.co.uk/d3dfunc.html

Ben
MonchoMeecho
15
Years of Service
User Offline
Joined: 10th Aug 2010
Location:
Posted: 4th Jul 2011 15:27
Well the factors are attack, defence (absorbs certain % of damage), health, speed (metres per/second) and rate of fire.

There's no real 'blocking' per say, just a chance to dodge it based on speed and how much RoF fire the opponent has.

So here I hope I've set up an attack-speed class along with an attack-health class correctly.



How would I go about making these two classes combat each other, factoring in rate of fire's impact on the opponents ability to dodge via their speed?
MonchoMeecho
15
Years of Service
User Offline
Joined: 10th Aug 2010
Location:
Posted: 4th Jul 2011 15:31
Whoops sorry, fixed that mess-up with the not changing the second array of info to AttkHlth.
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 5th Jul 2011 12:22
OK, first things first,

I would structure it (while simple) something like this



A few tips on the structure first.
Keep a note of your data structure requirements, integers, strings, floats etc.

There is a convention when writing them out that goes like this:
a float = variable#
a string = variable$
and integer/dword = variable

This will help you see what type of variable you are using when you code gets bigger.

I also use a descriptor for the type of variable, global, local etc in the variable.

global variable = g_variable
local variable = l_
a variable passed into a function (received variable) = r_

This just helps me structure it so I can always tell what is going on. I also read that if the variable name is above 9 characters DB makes it a 32 bit variable, not 16, or something, I don't know if thats right, but when I program a project I make the variable names the minimum length to fully describe what the variable is to myself so not things like CxN$ when I can call it g_Character_Demon_Hell1_Name$ etc, though I find naming easier with arrays, probably because you end up with far more variables for controlling the program than you ever have arrays for storing things.

If you want advice on the code for battles you will have to let me know what you are trying to do.
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 5th Jul 2011 12:33
Oops, i did your trick with main_character and AttkSpeed in the setup_characters() function, but you get the jist - you'd think we'd be able to edit our comments...

Login to post a reply

Server time is: 2026-07-10 21:42:05
Your offset time is: 2026-07-10 21:42:05