• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mr_malee

Calculate number sequence

10 posts in this topic

Hi, was wondering if there's a more mathematical approach to calculating a sequence of numbers where each number multiplies itself by 2. so starting with the number 5, and running 6 levels you would end up with

 

5, 10, 20, 40, 80, 160

 

I've got this and it works, but wondering if there's a more efficient way of doing it?

int n = 5;
int level = 6;

for (int i = 1; i < level; i++) {

	n *= 2;
}

return n;

thanks

0

Share this post


Link to post
Share on other sites

You're performing a multiple of two, n times, which is the same as one multiplication of (2 ^ (n-1))

 

I.E

 

5 * 2 ^ (6 - 1)  is 5 * 2 ^ 5

0

Share this post


Link to post
Share on other sites

ah thank you.

Just gonna slap this here:

 

5 * Mathf.Pow(2, level - 1);

Edited by mr_malee
0

Share this post


Link to post
Share on other sites

In code, you can do this using the bitshift operator as well instead of using pow or something, courtesy of binary:

n = 5 << (level - 1);

Watch out for overflow though. Of course, if later on you want to have partial levels, e.g. level = 2.5 somewhere between level 2 and level 3, then just using pow is the better solution, since you're using floats anyway.

Edited by Bacterius
1

Share this post


Link to post
Share on other sites

Say I wanted to get the inverse of that function. Given these numbers:

 

5, 10, 20, 40, 80, 160

 

how could I produce:

 

1, 2, 3, 4, 5, 6

 

again, I only know how to do this using loops:

int n = 1;
int value = 80;

while (value > 5) {

	value -= value / 2;
	n++;
}

return n;
Edited by mr_malee
0

Share this post


Link to post
Share on other sites

Say I wanted to get the inverse of that function. Given these numbers:

 

5, 10, 20, 40, 80, 160

 

how could I produce:

 

1, 2, 3, 4, 5, 6

 

It would be:

 

level = log2(n / 5) + 1

 

Where log2 is the base-two logarithm. (again, if using bitshifts and integers, log2 can be implemented as the "highest bit set to one" instruction, which has no built-in keyword but may have an intrinsic available on your compiler - but at this point, using your math library's log2 is probably easier).

 

So e.g. for n = 80, we take n / 5 = 16, and log2(16) = 4 which gives us level = 5, as expected.

0

Share this post


Link to post
Share on other sites

hello again, I've got another interesting sequence problem, more of a difficult pattern this time (imo)

 

given this sequence of numbers: 1, 5, 10, 30, 60, 300, 600, 1800, 3600, 18000, 36000

 

can you find a way (without arrays) to return one of these numbers based on an index (1, 2, 3, 4, 5, 6, 7...)?

 

ignoring 1. The sequence is separated into pairs of double size numbers:

 

(5, 10)

(30, 60)

(300, 600)

(1800, 3600)

(18000, 36000)

 

pairs are separated by a multiplication of the preceding number:

 

1 * 5 = 5

10 * 3 = 30

60 * 5 = 300

600 * 3 = 1800

3600 * 5 = 18000

 

I'm almost positive there needs to be some tricky modulus going on, but can't seem to crack it.

 

The very difficult problem is given only an index "7", and the first number real number "5". How do you get 1800. 

Edited by mr_malee
0

Share this post


Link to post
Share on other sites

Your sequence increases by multiples of the repeating sequence [5, 2, 3, 2], so for each multiple of 4 indices, the sequence increases by a factor 60. The remainder of a multiple by 4 can easily be applied afterwards.

 

Two hints:

  1. (index-1)/4 gives you the number of times to multiply by 60.
  2. (index-1)%4 gives you the number of factors to multiply as a fraction of 60; for no remainder you multiply by 1 since all factors are covered by a whole number of 60's, for one remainder you multiply by 1*5=5, for two remainders you multiply by 1*5*2=10, and so on for the last factor which I leave up to you to understand.
0

Share this post


Link to post
Share on other sites

ah Thanks. Here's what I ended up with

if (index == 0) {
			
	return 1;
}

int v = (index - 1) / 4;
int n = (index - 1) % 4;
int m = (int)Mathf.Pow(60, v);

if (n == 0) {

	return 5 * m;
}
else if (n == 1) {

	return 10 * m;
}
else if (n == 2) {

	return 30 * m;
}
else if (n == 3) {

	return 60 * m;
}
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0