Author Topic: Site game?  (Read 4077 times)

0 Members and 1 Guest are viewing this topic.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Site game?
« on: June 12, 2011, 07:13:26 AM »
0
Here's an idea I've been tossing about a bit and curious if anyone is interested in.

A basic web game, somewhat in the vein of 1000ad (I think this died), Urbandead, etc.  (edit: I've been informed some of you may know of Kingdom of Loathing as another example)  I really don't want to be making anything too complicated since I'll likely tire of maintaining/updating things at some point but I have considered trying my hand at this sort of thing many times and never actually done it.

The general gameplay format is that every so often you get a turn/action point/whatever (1 per hour, 1 per day, 1 per minute whatever) and when you log in you can spend your turns on doing things.  Some games like urbandead are you're a single person others you're running a empire or city state or something like that.

I think the style that most interests me is an empire/citystate type of game which of course leaves the next question of setting.  Fantasy has been done a lot so I'm somewhat attracted to the idea of a futuristic type game.  Something like the Alpha Centauri games where you're on a new planet with limited resources to build with.

Now if people are interested in this I think I can be convinced to move ahead with it, and any ideas from here on out are just speculative setup that can be tweaked/scrapped if people don't like the idea but I'm going to continue to ramble on the futuristic on a planet idea.

The first thing every faction is going to need is resources.  In fantasy games that's usually gold, metal, wood and food.  In a future game I'm thinking food, metal, fuel of some kind, power(electricity), and some kind of unobtainium. :P  I'm not sure but I think some sort of monetary resource would be a decent idea as well.

Then the faction will of course have a population, and units that can do different things.  The general population is just people of the faction and the units would be things in specific roles that work for the government.  Like various military units, engineers/mechanics, stuff like that.

Then you'd have buildings which would help to build stuff, and various technologies as well.  I think most of the buildings should be along the lines of "this stuff is all known you just have to build up the infrastructure to actually use them" maybe something you can build 30 tank factories if you want, but until you have enough tank tread factories running already there is no point to these running.  Technologies I think should be generic researchy things like +1 attack for tanks, not game changing stuff like "you can now build these because you have the tech."

What do you all think?

I'll probably reply to this a little later with more ideas for it.  And coding up a quick and easy one should be pretty straight forward and then it could be expanded if wanted or not.
« Last Edit: June 12, 2011, 07:15:44 AM by The Doctor »
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline Mazder_Verhal

  • Hero Member
  • *****
  • Posts: 1771
  • Gender: Male
  • I have a bad feeling about this...
  • Respect: +32
    • http://mazder-1x5.deviantart.com/
    • http://steamcommunity.com/profiles/76561198031547390
    • View Profile
Re: Site game?
« Reply #1 on: June 12, 2011, 12:34:38 PM »
0
Interested, not sure on the whole site doing it as it'd be very difficult on organising it.
Not sure I'd join though as I'm not one for joining big things which involve stats things in the game, I prefer just to write only. :P

A good idea though, just the size looks a little ambitious to me. :)
Come look at my art.
Deviantart: http://mazder-1x5.deviantart.com/
Tumblr: http://mazderverhal.tumblr.com/
Leave ideas or critiques or anything with me there or anywhere you can reach me. :)

Offline SirEmilCrane

  • Sword Arm of the forum Staff
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1662
  • Gender: Male
  • We're watching you...
  • Respect: +28
    • View Profile
Re: Site game?
« Reply #2 on: June 12, 2011, 12:57:32 PM »
0
I'll give it a go
...scum.

Offline killer rin

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6314
  • Gender: Male
  • Unanian Innovation!
  • Respect: +37
    • killerrin
    • Killerrin
    • killer rin
    • killerrin
    • View Profile
    • Killerrin Studios
Re: Site game?
« Reply #3 on: June 12, 2011, 05:26:39 PM »
0
I'd try it out

Offline wisekill1

  • Hero Member
  • *****
  • Posts: 1860
  • Gender: Male
  • Random penguins are cool!
  • Respect: +22
    • wisekill1
    • wisekill1
    • wisseify
    • View Profile
Re: Site game?
« Reply #4 on: June 12, 2011, 05:29:29 PM »
0
I am sure that i  will try it out if it is made
...
...
...
Boo!

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #5 on: June 12, 2011, 10:13:22 PM »
0
Interested, not sure on the whole site doing it as it'd be very difficult on organising it.
Not sure I'd join though as I'm not one for joining big things which involve stats things in the game, I prefer just to write only. :P

A good idea though, just the size looks a little ambitious to me. :)

It would just be a something that we had not something everyone would have to play.  I kinda like the idea of tying it to the forum login but I'm not -sure- about that.  I'll see how easy that is.  I may try to get a basic prototype running a little later today.

Expanding on game theory idea I'm thinking it'll go like this:

Buildings
  Buildings allow various actions to take place assuming you have the manpower and resources to do it.  Some buildings will convert resources from one type to another (smelt iron-steel for example), some will allow you to train units (train infantry, requires people and guns).

Resources
  Resources represent things your faction has, should work up from base resources up to more complicated things.  Base resources are things you pull out of the ground environment directly, food, water, etc.  Then there will be intermediate resources, like steel, carbon nanotubes, tank treads, etc.  Then there are final resources which are actually useful, like guns, tanks, enriched uranium, etc.

Technologies
  Technologies will be researched and will give small bonuses each level.  like +1% infantry defense or something of that nature.

Units
  Units will be primarily for war :D  troops of various types, they'll do damage or something.. I haven't quite worked out the mechanics for this yet.

I shall continue to reply to this with stuff until I feel I have enough to make a basic prototype work.  Proof of concept type of thing.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline Ormag_Necros

  • Sr. Member
  • ****
  • Posts: 308
  • Gender: Male
  • Respect: +5
    • RedMarkerRellik
    • Orm Necros
    • ZEUS V101
    • View Profile
Re: Site game?
« Reply #6 on: June 13, 2011, 12:03:28 AM »
0
Sounds interesing.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #7 on: June 13, 2011, 12:41:53 AM »
0
Alright forum login integration seems stupidly difficult at first glance so I'm going to scrap that for now in favor of getting a proof of concept going first.

Now there are two primary ways of having a game like this work.  Either like a real time strat game where you give orders and then they take so long to complete or a turns/action points type where you are given turns every so often and you spend them to do things in game.  A more real time game feels more interesting to me but changes things up slightly.

With a real time variant you would log in and say "do this, do that, do the other thing."  Maybe even with some "do this then do this then do that" type of stuff.  Then you'd wait however long it takes for those to complete.

With the turn based you would gather turns and then spend them to do things, saying do this do that, do the other thing.  But they would happen instantly so long as you had enough turns saved up to do whatever you wanted.

I'm sure there are advantages and disadvantages to both but I'm not really sure what they would be honestly and am having some difficulty picking one.  Any preferences from people?

Also a hybrid type thing could be developed I suppose where you gather up turns, but you give orders like a real time and then you simply choose to use your turns to cause the time to pass in game.

To differentiate a little here's how the three systems would work to train up 5 soldiers and explore the land (all times and costs are just making excrement up :P)

Real time: You give an order to train 5 soldiers.  This takes 5 minutes to complete, then you give the order to explore for 5 minutes.  5 minutes after that you gain the land from exploring.  Alternatively: You order the training of 5 soldiers, and 5 minutes of exploring.  Both happen simultaneously but neither completes until the 10 minutes total have passed.

Turn based: You wait 10 minutes, this gives you 10 turns.  You say train 5 soldiers, this costs 5 turns.  You say explore for 5 turns.  Then you gain the land as soon as the turns are spent.  Alternatively: You wait 5 minutes, gain 5 turns, spend them training soldiers.  You wait 5 more minutes, gain 5 turns, spend them on exploring.

Hybrid: You gain turns just like in turn based.  You give an order to train 5 soldiers.  Then spend 5 turns to cause "time" to pass and the soldiers are trained, you then give an order to explore for 5 turns.  Then spend 5 turns to cause "time" to pass again and gain the land.  Alternatively:  You give both orders at once, spend 10 turns and both complete.

All three end up with things taking the same amount of real time to get the same goals done, it's just a different design.  Real time would likely encourage players to log in more frequently for shorter periods, where the others would probably encourage a "log in now and then and spend all my turns" type of thing.  Both ways have advantages to your being online at the same time as your opponent if they choose to attack you as they couldn't react but the real time gives the option that you could order attacks to occur when -you- won't be online to change things.  Letting you try to predict when your opponent will be able to react to your attack and planning around that without actually messing with your own schedule.

Just for reference I envision battles as being fairly hands off and just numbers based, and either way the attackers would order an attack and that's all they can do except alter the army distribution but defensively if you are online and realize an attack is in progress you could switch your tactics from exploring or building up economically to building defenses/repairing things.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #8 on: June 13, 2011, 04:00:07 AM »
0
Alright, after much thinking.  While I like the Real-Time idea it's likely to jump up with a bunch of stuff I haven't thought of in terms of coding difficulty.

The pure turn based vs hybrid system I'm debating on and leaning towards the latter.  There really isn't a massive difference between them but if desired hybrid can be turned into either of the others fairly easily.

That being said lets talk about how things will work for play.  I'm going to start getting into mathematics and some basic game theory here.  Probably jumping about a lot as my mind flicks from idea to idea putting this together.

Firstly the main resource: Turns.  Turns represent game time.  They will be gained every X real time units (probably 1 minute for testing games, 5-10 minutes for fast paced games, 30-60 minutes slow pace games).  When you start the game you will be given a number of turns to get started.  Maybe like 50 or something.  Turns should represent time in game, maybe like a month or week.  Since I'm plotting this as a futuristic type game on another world lets call a turn "1 week", 4 weeks per month, 12 months per year = 48 turns per "year" which nicely lines up with 1 day real time = 1 year game time at 30 minute turns.

Next base resources: Population, this is your base population of people and doesn't cover military units/etc.  It's the civilians of your faction.  Population will grow with time.  Land is your next base resource being where you build things.  I'm thinking Mountains, Plains, Deserts, and Forests as a start.  Each type of land will be required for building different buildings/facilities.  These are all resources that can be gained and used but are not really lost.  For example training soldiers costs from your unused population but still counts to total population.

Primary resources: Going to have to expand this with time but a big one will be food.  Primary resources will be things that are acquired from your land through buildings (mines, farms, etc), and spend.  When used they are gone.  I'll probably reference others later but for now these seem like a good base: Food, oil/coal(fossil fuel of some kind), at least one kind of metal, electricity, unobtainium and credits (money).

Secondary resources: These will be produced from primary resources using up the primaries but may not provide any particular use themselves.  Think things like tank treads or guns.  Sure guns are helpful but without someone to use them they don't do much good.

Units: Units are used to attack and defend.  They will have attack stats and defense stats mechanics of battle need to be worked out.  Note: Attack and defense doesn't mean attacking the enemy or defending self, it means attacking the enemy units or defending friendly units regardless of whether the fight is at the enemy gates or home gates.

Buildings: Buildings will provide storage for resources, housing for units/population, production of resources over time, or ability to train units/do research.



Empire should have nifty settings like tax rate and work rate.  Which will effect how fast you gain credits, how many buildings run effectively and population growth.

Population growth/loss: There should be a small population loss every turn.  Assuming average lifespan of 100 years (this is the future) that works out to 1% loss every game year = about 0.02% per turn loss.  If there is not enough housing for the population there should be an increase in loss, probably proportional to overage, maybe like 5% of your overage every turn dies.  So if you could support 5000, and you have 10,000 you would lose 2 people for lifespan and 250 more for your overage.  Growth should be based of "morale" which is just a work rate/tax rate thing.  I would say Morale = (100% - tax rate) * (100% - work rate).  I.E. only way to get perfect morale is no work and no taxes.  Looking at real world figures and fiddling it appears that double population every 10 years at "perfect" morale would be a reasonable number.  I'm thinking that it should follow a exponential scale.  The benefit of having 50% tax over 100% tax is better than the benefit of having 0% tax over 50% tax.

Final calculations per turn: pop loss = pop*0.0002, pop gain = pop*(2^(morale/(10*48))), morale = sqrt((100%-tax)*(100%-work))

This works out to almost exactly double population every 28 years at 50% tax and 50% work rates.  Which seems about right.  If you lower tax or work rate to 25% you double in about 21.5 years, both to 0% doubles in 12 years.  Minimum sustainable population is at tax/work rates of about 86% each.  Above that and loss will outdo growth.  NOTE: setting either rate to 100% will result in no growth.


Money income: tax rate.  1 credit per population per turn at 100%, nice linear scale downward from there.

Need to write more but want to stop thinking for now: next time: food and it's interactions with population.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline killer rin

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6314
  • Gender: Male
  • Unanian Innovation!
  • Respect: +37
    • killerrin
    • Killerrin
    • killer rin
    • killerrin
    • View Profile
    • Killerrin Studios
Re: Site game?
« Reply #9 on: June 13, 2011, 04:12:49 AM »
0
interesting, and it looks nicely thought out in a game designy way... Though question, Is it going to be Text based, or Picture based, or a hybrid of the 2?

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #10 on: June 13, 2011, 05:23:29 AM »
0
Food.  Lets start with a basic 1 unit of food needed per population per year.  48 weeks per year 1 food needed per 48 population per week.  I'm thinking that if you run out of food you'll see a population drop of 5% of your overage population per turn.  and I'm revising the homeless over pop to 2% per turn.  We can modify these later if needed.

Food production: Farms.  Farms should produce lots of food but only half the year.  Hunters/foragers produce less food but do so constantly


Lets talk buildings:

Buildings should have a cost.  Credits and land.  Some will provide resources.  Some will provide storage for resources.  Some will provide the ability to do things.

Farm:
Costs: Plains land
Produces food every turn for half the year, requires labor during any turn it's producing.

Hunter/Foragers:
Costs: Forest land
Produces food all turns, requires labor constantly.  Less food per labor/turn than farms.

Coal Mine:
Costs: Mountain land
Produces coal all turns, requires labor constantly.

Oil Well:
Costs: Desert land
Produces oil all turns, requires labor constantly.

Oil refinery
Costs: Plains land
Produces fuel, costs Oil and Labor to run.

Coal powerplant:
Costs: plains land
Produces electricity, costs Coal and labor to run.

Oil powerplant:
Costs: Plains land
Produces Electricity, costs Fuel and labor to run.

Solar powerplant:
Costs: Desert land
Produces Electricity, costs labor.  Produces more electricity during summer weeks, less during winter.

Housing:
Costs: Plains land
Provides housing, requires electricity to run. 

Warehouse:
Costs: Plains land
Provides storage for non electricity resources.

Capacitor bank:
Costs: Plains land
Provides storage for electricity.

Settlement:
Costs: Plains land
Provides some storage, some housing, some electricity generation.  Some exploration ability.

City Center:
Costs: Plains land, a settlement
Upgrades a Settlement.  Provides more of everything a settlement provides.  Possibly required for some other buildings.

Building calculations.  First figure out which buildings are trying to run (some may only be trying to do something at certain times, for example: military training, or research).  for each building type check that input requirements are met.  For example: oil refinery costs oil, if you have no oil than the refinery doesn't try to run.  If you have 5 refineries, but only 3 refineries worth of oil, only 3 try to run.  If multiple things are trying to use a resource and less of it exists than they all need it is split proportionally.  For example: if you have farms trying to use 200 population, and refineries trying to use 100 population but only have 150 population the farms will get 100 and the refineries 50.  Population is done after any other resource draws.

Once resource distributions are calculated the costs are subtracted from resource pools, then the results are added to resource pools.  (Note: I think I want to reverse this but it seriously ups the computational calculations.  As it is you -have- to have capacitors to store electricity where really you just hook the output of A to the input of B and go.)  After all production/consumption storage is attempted.  Any that can't be stored is lost.

Next post: Trying to work out the exact production/consumption algorithms to make everything shiny cap'n.  Anyone with unit/building suggestions let me know!
« Last Edit: June 13, 2011, 05:32:12 AM by The Doctor »
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #11 on: June 13, 2011, 05:24:46 AM »
0
interesting, and it looks nicely thought out in a game designy way... Though question, Is it going to be Text based, or Picture based, or a hybrid of the 2?

It would be a web game, there will be some pictures and a lot of text.  Mostly text, with buttons, and stuffs :P
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #12 on: June 13, 2011, 08:56:47 AM »
0
Alright folks it's algorithm time.  For those of you interested in mod/game programing this will be a good intro to things you have to learn to do.  Algorithm design along with a good grasp of the mathematics behind game design are absolutely critical.  If anyone is interested in these things let me know in here and I'll look to making a site feature, maybe even a series of them.  Now to our algorithm here.

First thing you need to do is define the problem.  What are you trying to solve?  What obstacles are there?  Sometimes you have to also define what restrictions you have.  Usually this is in terms of performance/time limitations.  In this case CPU power won't be limited and timing is not critical.  This isn't a real time game where you are planning on doing this calc 10 times per second.  It can be wasteful.

So our problem: We need to define how to distribute (potentially limited) resources of various types to buildings.  The largest issue is some resources being used may be being produced by the very buildings that are limited.  You could even end up with a supply loop.

Now we begin our pseudo code, psuedo code is essentially human readable stuff that can easily be converted to actual code.

Code: [Select]
Total costs of all resources for all buildings
Total production of all buildings
If total production+stores is greater than total costs we're done
Else begin limited resource calculation

This is a quick check, if it matches here we don't have to think anymore because it's done.  However if this fails we get more interesting.  And we have to begin fun times.

Code: [Select]
Check each resource cost vs supplies.  If cost is greater than supply add to limited resource list.
Go through limited resource list
  For each resource look at supply drains calculate supply proportion.  (I.E.  Attempting to draw 100 oil, have 90 supply = 90% proportion)
  For each building type that draws this resource go through resource costs/productions
    For each resource lower total resource costs to meet supply proportion
    If a resource cost lowered such is on the limited list check if this lowered cost is within supply levels.  If so remove from limited list
    For each resource produced lower supplies by proportion (WARNING: Only lower -produced- supplies by proportion, not total supplies!)
    If a resource supply is lowered below total resource costs and it is not already on the limited resource list, add to limited list

This -should- be all you need to do.  Lets do a run through this with some simulation.

Lets assume we have no warehoused resources.  We have 100 pop.  We have oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel produce 200 electricity.

Code: [Select]
Base supplies: 100 pop.
Produced supplies: 100 oil, 50 fuel, 200 electricity.
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.
Total costs: 75 pop, 50 oil, 50 fuel, 100 electricity.

Costs under production, we're done.

Alright first run done.  Now lets assume we add in houses trying to draw 150 electricity.

Code: [Select]
Base supplies: 100 pop.
Produced supplies: 100 oil, 50 fuel, 200 electricity.
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.
Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.

Now we enter our loop.

Code: [Select]
(limited resource list = electricity)
electricity draw 250, supply 200 = 80% electricity supply.
  Oil rigs use electricity
    Lower electricity cost to 80%(40 instead of 50), total cost now 240, still above supply, ignore list
    Lower pop cost to 80%(20 vs 25), total cost now 70, wasn't above supply, ignore list
    Lower oil production to 80%(80 vs 100), total supply now 80, supply still over cost, ignore list.
  Oil refinery uses electricity
    Lower electricity cost to 80%(40 instead of 50), total cost now 230, still above supply, ignore list
    Lower pop cost to 80%(20 vs 25), total cost now 65, wasn't above supply, ignore list
    Lower oil cost to 80%(40 vs 50), total cost now 40, wasn't above supply, ignore list
    Lower fuel production to 80%(40 vs 50), total supply now 40, costs now greater, add to limited resource list (now: electricity, fuel)
  Housing uses electricity
    Lower electricity cost to 80%(120 vs 150), total cost now 200, supply meets cost, remove electricity from limited resource list (now: fuel)
Fuel draw 50, supply 40 = 80% fuel supply
  Oil powerplant uses fuel
    Lower fuel cost to 80%(40 vs 50), total cost now 40, supply meets cost, remove fuel from limited resource list list (now: blank)
    Lower pop cost to 80%(20 vs 25), total cost now 60, wasn't above supply, ignore list
    Lower electricity production to 80%(160 vs 200), total supply now 160, cost now greater add to limited resource list (now: electricity)
electricity draw 200, supply 160 = 80% supply.

And we call it quits here.  I can recognize a death spiral when I see one.  This will continue until all production is at 0% because we have a resource loop with no outside influence.  Looks like our algorithm failed (as I suspected it would from the beginning).  We'll have to devise a way out of this death loop  I can see a couple ways out but can anyone else?

Next time: After I sleep and get back up, devising ways out of this predicament.

P.S. thinking about it slightly the death spiral won't actually reach 0%, it will loop forever constantly getting smaller and smaller until finally the computer decides to lock up.  This is called an infinite loop and is the bane of all devs everywhere.  Learning to recognize warning signs early on for these is a very important skill.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline wisekill1

  • Hero Member
  • *****
  • Posts: 1860
  • Gender: Male
  • Random penguins are cool!
  • Respect: +22
    • wisekill1
    • wisekill1
    • wisseify
    • View Profile
Re: Site game?
« Reply #13 on: June 13, 2011, 09:19:09 AM »
0
so, you now gain turns by waiting, I was personally thinking of something else (just let me know what you think of it)

for example: there are 6 people who play the game. one is online and builds something using 5 turns, Instead of losing these turns the other players gain them. so: 5(turns/5(players (not counting the one who used it)=1 turn for every player.
this mean that saving up turns is not good because it would slow down the game.
new players would gain 50 turns


edit.
that loop, what if you are able to automaticly buy extra stuff the other players have so the other players gain some credits and you get your whatever you need.

this is not fail safe. so it might be a option to set in a "home planet" (this is a Future game... so why not)
you will buy from this homeplanet whatever you need for high amounts of credits. until you have solved this loop military units will be disbanded because you don't have money to pay them and you will only be able to build the buildings that are needed to solve this loop (a power plant in this case)
you will probaly have debts in the end of this but you will just get your taxes and slowly rebuild your military.
 
« Last Edit: June 13, 2011, 09:31:35 AM by wisekill1 »
...
...
...
Boo!

Offline killer rin

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6314
  • Gender: Male
  • Unanian Innovation!
  • Respect: +37
    • killerrin
    • Killerrin
    • killer rin
    • killerrin
    • View Profile
    • Killerrin Studios
Re: Site game?
« Reply #14 on: June 13, 2011, 01:54:37 PM »
0
Alright folks it's algorithm time.  For those of you interested in mod/game programing this will be a good intro to things you have to learn to do.  Algorithm design along with a good grasp of the mathematics behind game design are absolutely critical.  If anyone is interested in these things let me know in here and I'll look to making a site feature, maybe even a series of them.  Now to our algorithm here.

First thing you need to do is define the problem.  What are you trying to solve?  What obstacles are there?  Sometimes you have to also define what restrictions you have.  Usually this is in terms of performance/time limitations.  In this case CPU power won't be limited and timing is not critical.  This isn't a real time game where you are planning on doing this calc 10 times per second.  It can be wasteful.

So our problem: We need to define how to distribute (potentially limited) resources of various types to buildings.  The largest issue is some resources being used may be being produced by the very buildings that are limited.  You could even end up with a supply loop.

Spoiler for Hiden:

Now we begin our pseudo code, psuedo code is essentially human readable stuff that can easily be converted to actual code.

Code: [Select]
Total costs of all resources for all buildings
Total production of all buildings
If total production+stores is greater than total costs we're done
Else begin limited resource calculation

This is a quick check, if it matches here we don't have to think anymore because it's done.  However if this fails we get more interesting.  And we have to begin fun times.

Code: [Select]
Check each resource cost vs supplies.  If cost is greater than supply add to limited resource list.
Go through limited resource list
  For each resource look at supply drains calculate supply proportion.  (I.E.  Attempting to draw 100 oil, have 90 supply = 90% proportion)
  For each building type that draws this resource go through resource costs/productions
    For each resource lower total resource costs to meet supply proportion
    If a resource cost lowered such is on the limited list check if this lowered cost is within supply levels.  If so remove from limited list
    For each resource produced lower supplies by proportion (WARNING: Only lower -produced- supplies by proportion, not total supplies!)
    If a resource supply is lowered below total resource costs and it is not already on the limited resource list, add to limited list

This -should- be all you need to do.  Lets do a run through this with some simulation.

Lets assume we have no warehoused resources.  We have 100 pop.  We have oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel produce 200 electricity.

Code: [Select]
Base supplies: 100 pop.
Produced supplies: 100 oil, 50 fuel, 200 electricity.
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.
Total costs: 75 pop, 50 oil, 50 fuel, 100 electricity.

Costs under production, we're done.

Alright first run done.  Now lets assume we add in houses trying to draw 150 electricity.

Code: [Select]
Base supplies: 100 pop.
Produced supplies: 100 oil, 50 fuel, 200 electricity.
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.
Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.

Now we enter our loop.

Code: [Select]
(limited resource list = electricity)
electricity draw 250, supply 200 = 80% electricity supply.
  Oil rigs use electricity
    Lower electricity cost to 80%(40 instead of 50), total cost now 240, still above supply, ignore list
    Lower pop cost to 80%(20 vs 25), total cost now 70, wasn't above supply, ignore list
    Lower oil production to 80%(80 vs 100), total supply now 80, supply still over cost, ignore list.
  Oil refinery uses electricity
    Lower electricity cost to 80%(40 instead of 50), total cost now 230, still above supply, ignore list
    Lower pop cost to 80%(20 vs 25), total cost now 65, wasn't above supply, ignore list
    Lower oil cost to 80%(40 vs 50), total cost now 40, wasn't above supply, ignore list
    Lower fuel production to 80%(40 vs 50), total supply now 40, costs now greater, add to limited resource list (now: electricity, fuel)
  Housing uses electricity
    Lower electricity cost to 80%(120 vs 150), total cost now 200, supply meets cost, remove electricity from limited resource list (now: fuel)
Fuel draw 50, supply 40 = 80% fuel supply
  Oil powerplant uses fuel
    Lower fuel cost to 80%(40 vs 50), total cost now 40, supply meets cost, remove fuel from limited resource list list (now: blank)
    Lower pop cost to 80%(20 vs 25), total cost now 60, wasn't above supply, ignore list
    Lower electricity production to 80%(160 vs 200), total supply now 160, cost now greater add to limited resource list (now: electricity)
electricity draw 200, supply 160 = 80% supply.

And we call it quits here.  I can recognize a death spiral when I see one.  This will continue until all production is at 0% because we have a resource loop with no outside influence.  Looks like our algorithm failed (as I suspected it would from the beginning).  We'll have to devise a way out of this death loop  I can see a couple ways out but can anyone else?

Next time: After I sleep and get back up, devising ways out of this predicament.

P.S. thinking about it slightly the death spiral won't actually reach 0%, it will loop forever constantly getting smaller and smaller until finally the computer decides to lock up.  This is called an infinite loop and is the bane of all devs everywhere.  Learning to recognize warning signs early on for these is a very important skill.
Hmm Interesting I'm going into the field of game design myself (though Im still 2 years away from graduating HS (Staying for an extra year for some extra maths)) this should be fun looking over the psudo code.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #15 on: June 13, 2011, 05:38:49 PM »
+1
so, you now gain turns by waiting, I was personally thinking of something else (just let me know what you think of it)

for example: there are 6 people who play the game. one is online and builds something using 5 turns, Instead of losing these turns the other players gain them. so: 5(turns/5(players (not counting the one who used it)=1 turn for every player.
this mean that saving up turns is not good because it would slow down the game.
new players would gain 50 turns


edit.
that loop, what if you are able to automaticly buy extra stuff the other players have so the other players gain some credits and you get your whatever you need.

this is not fail safe. so it might be a option to set in a "home planet" (this is a Future game... so why not)
you will buy from this homeplanet whatever you need for high amounts of credits. until you have solved this loop military units will be disbanded because you don't have money to pay them and you will only be able to build the buildings that are needed to solve this loop (a power plant in this case)
you will probaly have debts in the end of this but you will just get your taxes and slowly rebuild your military.
 


That turns idea is interesting but doesn't work well with the idea of people being able to join/stop at anytime.  The standard turns/action points system can handle 5, 50 or even 5000 players without a big difference.

For the loop there are a couple of competing things, first you want to make it act as smart as it can in solving the problems, second you don't want it making choices for the player if at all possible, third you don't want players to let it get there so you need to punish them if they do.

So, looking for ways out of the loop there is an easy way to cut some draw without starting a loop.  Our production provided 100 oil, but draw was only 50.  So that can be cut by 50% significantly lowering the draw of electricity without causing other supply limits to occur.  We weren't dealing with what the housing provides but if the housing was also producing more than needed that can be cut down without causing incident.  If we could cut a total of 50 electricity cost without lowering productions below needed values then we're good.  So we should revise our algorithm to attempt to cut unneeded items first.

However what if we can't cut housing?  Then we're caught in the situation that there is no safe solution.  Something has to be cut that is needed, and this is where we don't want the computer making choices for the player.  Also because the player hasn't properly built up their system we want to give them a slap on the wrist for failing to watch things properly.  So what happens in real life when you don't manage your supply systems correctly?  It backfires and the whole system collapses ( http://en.wikipedia.org/wiki/Northeast_Blackout_of_2003 ).  So what we need to do is make it so the system -recognises- when it is in a cascading failure and cuts to the final result instead of taking the time to get there.

Next time: Trying to figure out how to algorithmically recognise that and reach the end solution quickly as well as pseudo coding the safe cuts.

Hmm Interesting I'm going into the field of game design myself (though Im still 2 years away from graduating HS (Staying for an extra year for some extra maths)) this should be fun looking over the psudo code.


Algorithms are fun :D
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #16 on: June 14, 2011, 12:30:28 AM »
0
so, you now gain turns by waiting, I was personally thinking of something else (just let me know what you think of it)

for example: there are 6 people who play the game. one is online and builds something using 5 turns, Instead of losing these turns the other players gain them. so: 5(turns/5(players (not counting the one who used it)=1 turn for every player.
this mean that saving up turns is not good because it would slow down the game.
new players would gain 50 turns


edit.
that loop, what if you are able to automaticly buy extra stuff the other players have so the other players gain some credits and you get your whatever you need.

this is not fail safe. so it might be a option to set in a "home planet" (this is a Future game... so why not)
you will buy from this homeplanet whatever you need for high amounts of credits. until you have solved this loop military units will be disbanded because you don't have money to pay them and you will only be able to build the buildings that are needed to solve this loop (a power plant in this case)
you will probaly have debts in the end of this but you will just get your taxes and slowly rebuild your military.
 

Quick comment on the home planet thing before I go off and make another epic post ;)

The home planet is interesting but dangerous.  If you can just summon resource from the home planet, why can't you summon units?  Nukes?  Planet killer weapons?  Once you invoke such a thing it's hard to put the genie back in the bottle.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #17 on: June 14, 2011, 01:26:49 AM »
0
Alright lets start with safe cuts.  To make this work we're going to add the detail that the housing supports 200 pop.  We only need 100 so this will make houses safe to reduce.

This makes our supplies/costs look like this:  100 pop.  Oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel, produce 200 electricity.  Houses trying to draw 150 electricity, produce 200 pop support.  (Note: houses produce population support, not population itself.)

Code: [Select]
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity, 200 pop support.
Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.

We see that electricity cost is over supply by 50 so it needs to go onto the limited resource list.  but we need an algorithm to identify resources we can get rid off without any issues.  At this point it's easier to try to work with the numbers then make the algorithm to fit than to make an algorithm  So we're going to do this in reverse, first the "do this do that" and later the pseudo code.

Code: [Select]
Total draw 250, supply 200 = 50 unit overage
  Oil rigs, Oil refineries, Housing using electricity
  Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50%
  Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut.
  Housing are using 150 to produce 200 pop support, only 100 needed, can be cut up to 50%.

At this point we have our safe cut list (Oil Rigs, 50%, Housing 50%) in this case both can be cut 50% but that won't always be true, we'll have to examine that case later with any algorithm we make to ensure it works properly.  Also we have to examine the case where we need to cut 50%, one can cut 75% and one can only cut 25%.  This is where the algorithm will get -really- interesting.  Algorithm design like this is essentially taking a task (distribute resources) and breaking it down into sub tasks, then doing the same thing over and over again until you're sub tasks are simple enough to convert to code easily.

Code: [Select]
  Our safe cut list is drawing 200, we need to cut 50 which is 25%.
  Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75)
  Housing can be cut by 25% do so (electricity cost reduced by 37.5 to 200, pop support reduced by 50 to 150)
  Electricity cost is within supply.  Cave Johnson, we're done here.

So we've solved this case, we need to examine others before we know that our algorithm will work, or even exactly what it is for that matter.  Lets start with the uneven unneeded %'s.  Lets say housing only produces 150 pop support.  Now the above looks like this (NOTE: both code sections above combined here):

Code: [Select]
Total draw 250, supply 200 = 50 unit overage
  Oil rigs, Oil refineries, Housing using electricity
  Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50%
  Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut.
  Housing are using 150 to produce 150 pop support, only 100 needed, can be cut up to 33.3...% (NOTE: because of how number are handled in computing you probably don't want to store this % and retrieve it later as it may be slightly wrong.  Look up or ask me about floating point computing for details.)
  Our safe cut list is drawing 200, we need to cut 50 which is 25%.
  Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75)
  Housing can be cut by 25% do so (electricity cost reduced by 37.5 to 200, pop support reduced by 37.5 to 112.5)
  Electricity cost is within supply.  Cave Johnson, we're done here.

Alright that works fine, now lets change it up a little more.  Our goal is to cause the plan to fail so lets modify housing again.  If we reduce housing pop support to 125.  That should be just low enough to screw up the algorithm.

Alright lets start with safe cuts.  To make this work we're going to add the detail that the housing supports 200 pop.  We only need 100 so this will make houses safe to reduce.

This makes our supplies/costs look like this:  100 pop.  Oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel, produce 200 electricity.  Houses trying to draw 150 electricity, produce 200 pop support.  (Not houses produce population support, not population itself.)

Code: [Select]
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity, 200 pop support.
Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.

We see that electricity cost is over supply by 50 so it needs to go onto the limited resource list.  but we need an algorithm to identify resources we can get rid off without any issues.  At this point it's easier to try to work with the numbers then make the algorithm to fit than to make an algorithm  So we're going to do this in reverse, first the "do this do that" and later the pseudo code.

Code: [Select]
Total draw 250, supply 200 = 50 unit overage
  Oil rigs, Oil refineries, Housing using electricity
  Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50%
  Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut.
  Housing are using 150 to produce 200 pop support, only 100 needed, can be cut up to 50%.

At this point we have our safe cut list (Oil Rigs, 50%, Housing 50%) in this case both can be cut 50% but that won't always be true, we'll have to examine that case later with any algorithm we make to ensure it works properly.  Also we have to examine the case where we need to cut 50%, one can cut 75% and one can only cut 25%.  This is where the algorithm will get -really- interesting.  Algorithm design like this is essentially taking a task (distribute resources) and breaking it down into sub tasks, then doing the same thing over and over again until you're sub tasks are simple enough to convert to code easily.

Code: [Select]
  Our safe cut list is drawing 200, we need to cut 50 which is 25%.
  Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75)
  Housing can be cut by 25% do so (electricity cost reduced by 37.5 to 200, pop support reduced by 50 to 150)
  Electricity cost is within supply.  Cave Johnson, we're done here.

So we've solved this case, we need to examine others before we know that our algorithm will work, or even exactly what it is for that matter.  Lets start with the uneven unneeded %'s.  Lets say housing only produces 150 pop support.  Now the above looks like this (NOTE: both code sections above combined here):

Code: [Select]
Total draw 250, supply 200 = 50 unit overage
  Oil rigs, Oil refineries, Housing using electricity
  Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50%
  Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut.
  Housing are using 150 to produce 125 pop support, only 100 needed, can be cut up to 20%
  Our safe cut list is drawing 200, we need to cut 50 which is 25%.
  Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75)
  Housing cannot be cut by 25%, only 20% do so (electricity cost reduced by 30 to 207.5, pop support reduced by 25 to 100)

Alright we've broken it.  It's not solved the problem and we know the problem is solvable (we need to cut 7.5, there is 12.5 left to cut from the rigs.  Two possible solutions here: A.  Cycle the algorithm as long as there is uncut unneeded resources and excess draw, or B. Change the algorithm so it never reaches that point.  A. is easier.  B. is more fun.  Another thing to keep in mind is execution time.  In our case it is irrelevant but in the real world you have to compare your options and see which is faster.  In a case like this sometimes A will be faster,  Sometimes B will be faster.  I can tell you from looking and experience that B will be faster in any case that would cause A to loop and A will be faster in any case that it completes in 1 pass.  To determine the "best" of the two you would have to analyze which case occurred more often and the performance profiles of each.  Lots of work.  Sometimes you can actually end up with a option C. Calculate if A or B is faster, run faster one.  That only works if the savings of choosing the best case is more than the cost of figuring out which is best.

In this case, we're going to go with option B.  Because I enjoy solving problems and B is more difficult than A.

A potential solution is to take our list of things we're cutting to meet supply and sort it by how much we can cut before we go through, and then (potentially) recalculate the cut percentage at each step which would then look like this:


Code: [Select]
Total draw 250, supply 200 = 50 unit overage
  Oil rigs, Oil refineries, Housing using electricity
  Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50%
  Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut.
  Housing are using 150 to produce 125 pop support, only 100 needed, can be cut up to 20%
  Our safe cut list is drawing 200, we need to cut 50 which is 25%.
  Sort cut order by percentage( housing, then oil)
  Housing cannot be cut by 25%, only 20% do so (electricity cost reduced by 30 to 220, pop support reduced by 25 to 100)
    As this didn't meet cut percentage, recalculate cut percentage for remaining items.
    current safe cut list is drawing 50, we need to cut 20 which is 40%.
  Oil rigs can be cut by 40% do so (electricity cost reduced by 20 to 200, oil production reduced by 40 to 60)
  Electricity draw is within supply, we're done here.

To confirm that our system produced the correct result lets examine our final numbers:  100 pop.  Oil rigs trying to draw 30 electricity, 15 pop, produce 60 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel, produce 200 electricity.  Houses trying to draw 120 electricity, produce 100 pop support.  (Not houses produce population support, not population itself.)

Code: [Select]
Total supplies: 100 pop, 60 oil, 50 fuel, 200 electricity, 100 pop support.
Total costs: 65 pop, 50 oil, 50 fuel, 200 electricity.

We've done it!

Now people are dragging me to dinner so... Next post: Pseudo coding that, examining situation where cuts are not do able, identifying the situation and moving to forgone conclusion (total shutdown).
« Last Edit: June 14, 2011, 04:32:04 AM by The Doctor »
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #18 on: June 14, 2011, 05:29:44 AM »
0
Alright Pseudo code system so far:

Code: [Select]
Calculate total costs
Calculate total production
Calculate total supply (production + stored)
Create list of resources where supply is less than cost
For each limited resource
  Calculate overdraw (cost - supply)
  Create list of cuttable building types (buildings that produce more than is needed to meet cost)
  Sort list by percentage cuttable, smallest to largest
  Calculate cost from the cuttable buildings (total cost)
  Calculate needed cut percentage (overdraw / total cost from cuttable buildings)
  For each building type (go through in sort order)
    If cuttable percent greater than or equal to needed cut percent
      Decrease all costs from building type by cut percentage
      Decrease all production from building type by cut percentage
    If cuttable percent less than needed cut percent
      Decrease all costs from building type by cuttable percentage
      Decrease all production from building type by cut percentage
      Recalculate overdraw, cost from cuttable buildings, and needed cut percentage
  Recalculate overdraw.
  If overdraw = 0 move to next limited resource.

At this point we have made all safe cuts, any further cuts will reduce supplies to the point that more resources will be added to the need to cut list.  The question now becomes: Is this situation salvageable or should we consider this a blackout situation?

My initial reaction is that there has to be a salvageable situation here, but looking at the prior experiment my feeling is no.  The only escape from this is if building A supplies B supplies C and C is also supplied by A cutting B might relieve strain.  But that's a painful thing to calculate.

And thinking further (into game mechanics and realism) there are only two resources which are used instantly upon production.  Electricity and storage space.  Everything else, realistically, should by produced, stored, then used.  The system made above would allow oil to be extracted, then refined, then turned into electricity all in the same turn.  Not something that ever actually happens.  This also makes storage mostly useless for anything except food and resources not consumed by buildings normally.  Perhaps a better system would be to do everything above except -only- electricity is production added to stored, everything else is stored values only.  This eliminates the possible feedback loop at least in an instant turn sense.  It is still very possible to put yourself in a position where each turn your fuel reserves are falling and it will black out eventually.

With this design the code looks a little different:
Code: [Select]
Calculate total costs
Calculate total production
Calculate total supply (stored resources + supply of electricity)
Create list of resources where supply is less than cost
For each limited resource
  Calculate supply percentage (supply / cost)
  For each building type consuming resource
    Reduce all costs by percentage
    Reduce all production by percentage
    If produces electricity recalculate supply, if new supply is lower than cost add electricity to limited resources list unless electricity is already on the list.
Subtract all costs from supplies
Add all production to supplies
Check storage (this needs to be expanded)

Lets play with our previous scenario a bit:  100 pop.  Oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel, produce 200 electricity.  Houses trying to draw 150 electricity, produce 200 pop support.

Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity
Total supply: 100 pop, 200 electricity.
Total production: 100 oil, 50 fuel, 200 pop support

Code: [Select]
resources where supply is lest than cost: Oil, Fuel, Electricity.
For Oil
  Supply percent: 0%
  Oil refinery trying to use oil
    Reduce pop cost to 0% (now 50 total cost)
    Reduce oil cost to 0% (now 0 total cost)
    Reduce electricity cost to 0% (now 200 total cost), remove from limited resource list as supply now meets demand.
    Reduce fuel production to 0% (now 0 total production)
  No other uses, remove oil from limited list
For Fuel
  Supply percent: 0%
  Oil powerplant trying to us fuel
    Reduce pop cost to 0% (now 25 total cost)
    Reduce fuel cost to 0% (now 0 total cost)
    Reduce electricity production to 0% (now 0 total production)
    Producing electricity so
      Reduce electricity supply to 0% (now 0 total supply)
      Electricity supply below cost, not on limited list, add to limited list
  No other uses, remove fuel from limited list
For Electricity
  Supply percent: 0%
  Oil rigs trying to use electricity
    reduce pop cost to 0% (now 0 total cost)
    reduce electricity cost to 0% (now 150 total cost)
    reduce oil production to 0% (now 0 total production)
  Housing trying to use electricity
    reduce electricity cost to 0% (now 0 total cost)
  No other uses, remove electricity from limited list

Total costs: 0 pop, 0 oil, 0 fuel, 0 electricity
Total supplies: 100 pop, 0 oil, 0 fuel, 0 electricity
Total production 0 oil, 0 fuel, 0 electricity

Well... That went well...

Lets add a -little- bit of initial storage and see what happens: 100 pop.  Oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil.  Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel.  Oil powerplants trying to draw 25 pop, 50 fuel, produce 200 electricity.  Houses trying to draw 150 electricity, produce 200 pop support.  5 oil, 5 fuel in storage.

Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity
Total supply: 100 pop, 5 oil, 5 fuel, 200 electricity.
Total production: 100 oil, 50 fuel, 200 pop support

Code: [Select]
resources where supply is lest than cost: Oil, Fuel, Electricity.
For Oil
  Supply percent: 10%
  Oil refinery trying to use oil
    Reduce pop cost to 10% (now 52.5 total cost)
    Reduce oil cost to 10% (now 5 total cost)
    Reduce electricity cost to 10% (now 205 total cost)
    Reduce fuel production to 10% (now 10 total production)
  No other uses, remove oil from limited list
For Fuel
  Supply percent: 10%
  Oil powerplant trying to use fuel
    Reduce pop cost to 10% (now 30 total cost)
    Reduce fuel cost to 10% (now 5 total cost)
    Reduce electricity production to 10% (now 20 total production)
    Producing electricity so
      Reduce electricity supply to 10% (now 20 total supply)
      Electricity supply below cost, already on limited list, move along
  No other uses, remove fuel from limited list
For Electricity
  Supply percent: 20/205(about 9.7%)

Oh now that is just ugly...  This is where the first great virtue of a programmer comes into play: Lazyness.  I am not about to run those numbers manually when I'm sure an algorithm alteration would simplify things massively.  While it will cost me far more time to deal with that than it would the computer, finding a better algorithm will help the computer too.  Also: I produced a 20/205 with these numbers, something just seems -wrong- about that.

The only solution that seems feasible to fix it is to stop adjusting costs on the fly and shift to something else instead.  How about:


Code: [Select]
Calculate total costs
Calculate total production
Calculate total supply (stored resources + production of electricity)
Create list of all running buildings tied to "run percentage" set run percentage to 100% for all.
Create list of resources where supply is less than cost
Put electricity at the end if it's on the list (why?  Because my intuition says to)
For each limited resource
  Calculate supply percentage (supply / cost)
  For each building type consuming resource
    If current "run percentage" greater than supply percentage
      Reduce "run percentage" to supply percentage
    If building produces electricity
      Reduce electricity supply to percentage
      Add electricity to limited resources list if new supply is below costs and not already on the list.
Recalculate costs, production based off run percentages, round down to avoid fractional values (may allow free production, may increase costs sometimes)
Subtract all costs from supplies
Add all production to supplies
Check storage (this needs to be expanded)

Now what's it do?


Code: [Select]
resources where supply is lest than cost: Oil, Fuel, Electricity.
For Oil
  Supply percent: 10%
  Oil refinery trying to use oil
    Set oil refinery "run percent" to 10%.
  No other uses, remove oil from limited list
For Fuel
  Supply percent: 10%
  Oil powerplant trying to use fuel
    Set oil powerplant run level to 10%
    Producing electricity so
      Reduce electricity supply to 10% (now 20 total supply)
      Electricity supply below cost, already on limited list, move along
  No other uses, remove fuel from limited list
For Electricity
  Supply percent: 8% (muuuuch cleaner numbers this time)
  Oil rig trying to use electricity
    Set oil rig run percent to 8%
  Oil refinery trying to use electricity
    Set oil refinery run percent to 8%
  Housing trying to use electricity
    Set housing run percent to 8%
  No other uses, remove electricity from limited list
Recalculate costs, production

Total costs: 6.5(round to 6) pop, 4 oil, 5 fuel, 20 electricity
Total supply: 100 pop, 5 oil, 5 fuel, 20 electricity.
Total production: 8 oil, 4 fuel, 16 pop support

This ends us with supply for the next round of 100 pop, 9 oil, 4 fuel.  Increase on one but decrease on another.  Lets see what happens next round:

Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity
Total supply: 100 pop, 8 oil, 4 fuel, 200 electricity.
Total production: 100 oil, 50 fuel, 200 pop support

Code: [Select]
resources where supply is lest than cost: Oil, Fuel, Electricity.
For Oil
  Supply percent: 16%
  Oil refinery trying to use oil
    Set oil refinery "run percent" to 16%.
  No other uses, remove oil from limited list
For Fuel
  Supply percent: 8%
  Oil powerplant trying to use fuel
    Set oil powerplant run level to 8%
    Producing electricity so
      Reduce electricity supply to 8% (now 16 total supply)
      Electricity supply below cost, already on limited list, move along
  No other uses, remove fuel from limited list
For Electricity
  Supply percent: 6.4%
  Oil rig trying to use electricity
    Set oil rig run percent to 6.4%
  Oil refinery trying to use electricity
    Set oil refinery run percent to 6.4%
  Housing trying to use electricity
    Set housing run percent to 6.4%
  No other uses, remove electricity from limited list
Recalculate costs, production

Total costs: 5.7 (round to 5) pop, 3.2 (round to 3) oil, 4 fuel, 16 electricity
Total supply: 100 pop, 8 oil, 4 fuel, 16 electricity.
Total production: 6.4 (round to 6) oil, 3.2 (round to 3) fuel,  12.94 (round to 12) pop support.

This ends us with supply for the next round of 100 pop, 11 oil, 3 fuel.  Again increase on one, decrease on another.  And heading for terminal fast.  But... It's savable at this point.  The player just has to realize they are overdrawing and don't need to and correct it.

Next time: Lets start actually implementing something so we can talk less and play more.

P.S: My intuition told me to put electricity at the end.  Why?  Something in the back of my head told me to and that was it, after going through the numbers more I think it's because I subconsciously realized that the fuel alterations would reduce the electricity production which would reduce the current supply.  If electricity was already on the list and done first it would be re-added and done a second time.  While this wouldn't actually cause a problem with the result it would increase processing time unnecessarily.
« Last Edit: June 14, 2011, 05:54:32 AM by The Doctor »
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #19 on: June 14, 2011, 06:50:20 AM »
0
Alright, time to start thinking a little more about actual coding:

This will be a database driven application and we have to store a fair bit of data:

Username, Password, Empire name, population values(maybe more than 1), total and available land, stored resource values, counts of all building types, player set "active percents" for all building types, military units of all types, technologies of all types.  Lots of values.

Possibly going to see other things to store also.

Other things to store:  Game settings: turn rate (every 5 min, 30 min, whatever), initial turn count, initial player units/land/etc.  Also game stats, what buildings require/cost.

Usually when working these types of things for a database you get to do all kind of relational stuff but in this case... You could just dump all the values into a single table and call it good which is a bit odd for most games.  It does make the database queries muuuch easier though.

I'm going to split things into two tables to start: player table, empire table

Player table:
Code: [Select]
Player_ID
Username
Password
Empire_ID

Empire table:
Code: [Select]
Empire_ID
Empire_Name
Population
Res_Food
Res_Oil
Res_Fuel
Bld_Farm
Bld_OilWell
Bld_OilRefinery
Bld_OilPowerplant
Bld_Housing
Bld_Warehouse
Bld_Settlement

The player table is purely for login type info, all game info stored in the other.

all resources are prefixed with Res_, buildings with Bld_, not all of this will work or be used right away but it's a start.

At this point, I don't have much I can plot without code.  So... Off to the code windows.  Maybe have something decent tonight, probably not :P
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline Mazder_Verhal

  • Hero Member
  • *****
  • Posts: 1771
  • Gender: Male
  • I have a bad feeling about this...
  • Respect: +32
    • http://mazder-1x5.deviantart.com/
    • http://steamcommunity.com/profiles/76561198031547390
    • View Profile
Re: Site game?
« Reply #20 on: June 14, 2011, 08:56:28 AM »
0
Oooooohhh, see I thought it was an RP game you were talking about initially! :D

Yeah this I can see happening. :P
*Mazder gives his seal of approval.*
Come look at my art.
Deviantart: http://mazder-1x5.deviantart.com/
Tumblr: http://mazderverhal.tumblr.com/
Leave ideas or critiques or anything with me there or anywhere you can reach me. :)

Offline killer rin

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6314
  • Gender: Male
  • Unanian Innovation!
  • Respect: +37
    • killerrin
    • Killerrin
    • killer rin
    • killerrin
    • View Profile
    • Killerrin Studios
Re: Site game?
« Reply #21 on: June 14, 2011, 11:27:21 AM »
0
Variables are fun ^-^

Oooooohhh, see I thought it was an RP game you were talking about initially! :D

Yeah this I can see happening. :P
*Mazder gives his seal of approval.*
I've got the RP Game version all set down :P

Offline Mazder_Verhal

  • Hero Member
  • *****
  • Posts: 1771
  • Gender: Male
  • I have a bad feeling about this...
  • Respect: +32
    • http://mazder-1x5.deviantart.com/
    • http://steamcommunity.com/profiles/76561198031547390
    • View Profile
Re: Site game?
« Reply #22 on: June 14, 2011, 11:41:18 AM »
0
Variables are fun ^-^
I've got the RP Game version all set down :P
The RP version I won't be joining in as it looks all tabletop-y and I have troubles with table top, but the computer game version I might.
Come look at my art.
Deviantart: http://mazder-1x5.deviantart.com/
Tumblr: http://mazderverhal.tumblr.com/
Leave ideas or critiques or anything with me there or anywhere you can reach me. :)

Offline The Doctor

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Respect: +57
    • rdaruszka
    • View Profile
Re: Site game?
« Reply #23 on: June 14, 2011, 03:13:01 PM »
0
Uhg, didn't get much last night.  Didn't expect to.  Hoped to get some good work done today.  Got 3 hours sleep.  gently-carressing smoke alarms.

Will update when I can assuming my brain ever recovers.
Forum Rules - Web IRC

Quote
<CaptainJean-Luc> Doc: You have ruthlessly high standards.

His name was Marauder Shields.  Never forget his sacrifice.

Offline .

  • Newbie
  • *
  • Posts: 35
  • Gender: Male
  • I am the end.
  • Respect: +2
    • point-dot-point
    • superfrombelgium
    • View Profile
Re: Site game?
« Reply #24 on: August 20, 2012, 01:09:59 PM »
0
So, this idea lived for 3 days..
Is anyone still interested in this? (I am).
You're doing the programming tran? (I can help a little).
Ever tried to be happy? Its kinda fun.