• 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
BkoChan

Efficiently calculating increase in money over a period of time

7 posts in this topic

I'm currently working on the server side logic of a real-time online browser game build using NodeJS. Currently the logic works like this...

 

1. Receive an event from a player (queue something for production)

2. Calculate when the next event will happen in the game (look at when the next production will complete or when the next research project will finish)

3. Set a timeout so that the server effectively sleeps until the next event happens (unless interrupted by a player sending another event)

 

This seems to work very well so far. When the server wakes up from the timeout it updates the game with the amount of time passed and all production and research etc. is updated by the ellapsed time.

 

The problem I'm having at the moment is that the amount of money generated for a player is based on how many workers they have. Worker numbers slowly increase over time until they reach a population cap. Given the following facts...

 

- The player has 1 worker

- The player has no money

- A new working is created every minute

- A worker produces 100 credits per minute

 

How many credits does the user have after an hour? I have no idea how to predict the number of credits produced as the number of workers increases over time

 

I hope that makes sense!

0

Share this post


Link to post
Share on other sites

Oh hell, I can't remember the proper name for it, but it's done with sigma notation.

 

Edit:

http://en.wikipedia.org/wiki/Summation

 

The formula for a sequence starting at 1 is

 

s = n(n+1) / 2

 

For sequences starting at numbers higher than one it's:

 

s = (n(n+1) / 2) - (m(m+1) / 2)

 

Where m is one less than the starting point for the sequence and n is the ending point.

 

For instance:

 

1+2+3+4+5 = 15

 

1+2 = 3 +3 = 6 +4 = 10 +5 = 15

 

vs

 

5(5+1) / 2

5(6) / 2

30 / 2

15

 

or

 

3+4+5

 

3+4 = 7 +5 = 12

 

vs

 

5(5+1) / 2 = 15

2(2+1) / 2 = 3

15 - 3 = 12

Edited by Khatharr
0

Share this post


Link to post
Share on other sites

I'm not really seeing how to apply this to my problem in a more general manner. Your solution does provide the answer for 1 hour where the increase in workers is 1p/m. How to I alter this to handle 2,3,4 hours or a worker increase of 2 p/m?

0

Share this post


Link to post
Share on other sites

The player has a known number of workers (eg. 10, 20, 123)

Each worker will produce 100 credits per minute

A new worker is generated periodically (eg. every 1 minute, every 1.5 minutes, every 30 minutes) based on other variables

A period of time passed (eg. 1 minute, 4 minutes, 2034 minutes)

 

How to I calculate how many credits have been produced in the time period?

 

example:

The player has 20 workers

The worker spawn rate is 1 worker every 2 minutes

20 minutes have passed since the last update

 

How many credits have been generated in this time frame

0

Share this post


Link to post
Share on other sites
This is untested, but at first glance it would be:

m = starting_population
n = m + cycles_elapsed
worker_cycles = summation(m, n) * workers_spawned_per_cycle
produced = worker_cycles * production_per_worker_cycle
0

Share this post


Link to post
Share on other sites

example:

The player has 20 workers

The worker spawn rate is 1 worker every 2 minutes

20 minutes have passed since the last update



How many credits have been generated in this time frame

You need to be much more precise than that. For instance, does a worker produce 100 credits the minute that it is spawned? Or is it one minute after? In your example, when is the next worker going to be produced? Right away, or in one minute, or in two minutes?

I suggest you write reference code that iterates over minutes (or whatever other time unit you want) and computes things in a naive way. You can then try to optimize that code by using summation formulas. But you have to know what it is you are trying to compute.
0

Share this post


Link to post
Share on other sites

Given the following facts...
 
- The player has 1 worker
- The player has no money
- A new working is created every minute
- A worker produces 100 credits per minute
 
How many credits does the user have after an hour?

 

 

The complex code isn't necessary.  Unless you have some serious problems, you could do something along these lines:

if(timeElapsed > kMaxElapsedTime)
{
	ShowMessage( Messages::TooMuchTimeElapsed );
    timeElapsed = kMaxTimeElapsed;
}
for(int i=0; i<timeElapsed; i++)
{
	SimulateOneTimeUnit();
}

If you need more, create two simulators.  One is an online simulator, the other an offline simulator.

Edited by frob
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