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.

Code Snippets / A function for counting backward from an n value.

Author
Message
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jun 2005 03:29 Edited at: 21st Jun 2005 04:31
Hi All

If I knew how spell the correct name for this code I would, anyway here it is.



{edit}
found the word and its recursive code.
[/edit]

I'm not getting you down am I, Ho Look! another fancy Door?
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Jun 2005 03:50
You do know that you can count backwards this way too?

for i = 10 to 1 step -1

next i

I'm sorry but I don't really see the use of it...

Immunity and Annihalation makes Immunihalation...
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jun 2005 04:27
Its for use in AI stuff allows you put your code in it, then do it again with a diffrent set of numbers, until you get the results you are after.

working on a connect 5 game.

Have a search on Alpha and Beta

I'm not getting you down am I, Ho Look! another fancy Door?
Frozen Flame
20
Years of Service
User Offline
Joined: 22nd Jul 2004
Location:
Posted: 21st Jun 2005 12:43
Could be useful for like a game where you have 20 seconds to defuse a bomb. and when bomb defused you can stop the countdown and show how many seconds there is remains.

Cool.


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 22nd Jun 2005 05:28
Okay... and how do you use it?
The function is a loop on his own...

Immunity and Annihalation makes Immunihalation...
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 22nd Jun 2005 05:48 Edited at: 23rd Jun 2005 02:35
just call from out side with a number like this



I'm not getting you down am I, Ho Look! another fancy Door?
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 23rd Jun 2005 02:52
Again, I don't see what it does...

It just gives a black screen and displays the same random number on 0,400 from time to time...

Immunity and Annihalation makes Immunihalation...
Xolatron old
20
Years of Service
User Offline
Joined: 25th Jan 2004
Location: The Star Forge Language: DBpro
Posted: 30th Jul 2005 16:41
Sven B, it finds the factorial of n.
Factorial is:
1*2*3*4*5...*n
That 'random number' is n! = n factorial.

A simple example of what factorials are useful for:
You have 6 boxes of different colors. How many different ways can they be arranged in a line? 6 factorial.

-Xol

The Nerd
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Denmark
Posted: 30th Jul 2005 17:19 Edited at: 30th Jul 2005 17:25
I would do it like this :



I actually used that way in my first full game we're you should defuse a bomb.
But that's the way i use if i need to count a value backwards on it's own.
If it's a timer for a game i simple do like this :



Visit PanzerGames here
Xolatron old
20
Years of Service
User Offline
Joined: 25th Jan 2004
Location: The Star Forge Language: DBpro
Posted: 30th Jul 2005 20:25
HowDo's thread name is misleading. It is not 'counting backwards', but finding the factorial of a number - useful in math: probability especially.

HowDo is demonstrating how to compute the factorial of a number recursively - by calling the function in that function.

-Xol

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 30th Jul 2005 20:38
Cheers Xolatron for explaining it, couldn't find the word recursively at the time of posting.

I'm not getting you down am I, Ho Look! another fancy Door?
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Aug 2005 23:45
I see it now...
I thought he wanted to count backwards, like he said in the title...

Immunity and Annihalation makes Immunihalation...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Aug 2005 14:38
It's a recursive function. Very powerful, and also very dangerous if you screw it up

It's a good way to set skill levels in games like chess. For a beginner, each piece may "look ahead" 2 moves, by recursively calling the algorithm twice. For Advanced, it may "look ahead" 10 moves, by resursively calling the algorithm 10 times.

Login to post a reply

Server time is: 2024-11-23 11:33:34
Your offset time is: 2024-11-23 11:33:34