PDA

View Full Version : [WIP] Real Time CC Simulation



PawnXIIX
10-21-2012, 07:40 PM
Hey guys.

Like I said in the past, I program things when I get bored. So what I did was program a real time simulation of CC. It's still in the infancy stages.

Here's what needs to be done:

-Add data for all the buildings
-Incorporate player money
-Incorporate levels

Right now it is taking the buildings that have been added into the data. The buildings that I added into the data are "Laundromat", "Pizza Parlor", and "Gas Station". It calculates the best ROI of every possible upgrade and construction. If there is no upgrade going on, it does that upgrade. If there is no construction going on, it will do the construction with the best ROI. The entire program runs off an infinite loop which updates every building a lot of times per second.

Building collections run off milliseconds. The seconds for collection is multiplied by 1000 and added to the current time of the system. When the building is updated and the system time is equal to or greater than the collection time, the building is flagged for collection. When the update hits it again, the money is collected and a new collection time is calculated.

The system is perfect in the fact that there are no glaring logical or semantic errors right now. The only problem is the tiresome input of data.

Here is a string of data I use for defining a laundromat, and why it is so tiresome:


Laundromat 0 6 17 33 55 83 121 171 231 303 413 30 75 338 7200 21600 43200 64800 86400 172800 216000 100 167 278 465 777 1298 2169 3622 6049 10102 300

The array locations are as follows:
data[0] - name (String)
data[1] - unlock level (integer)
data[2-11] - payout (integer)
data[12-21] - upgrade time in seconds (integer)
data[22-31] - upgrade cost (integer)
data[32] - collection period in seconds (integer)

Every building is set into an array in java, 2 of each. A player is defined to have every building from the start, and buildings cannot be necessarily "removed" or "destroyed". The only way for them to make collection or be completed in any way is for the player to build them. This will increase their level to 1 instantly, allowing them to be seen by the update method which tracks if they're done or not.

The program current spits out only about a little bit of useful data at the moment. Most of the program is jargon that lets me know if the timers are working correctly and that there are no logical errors in the code (Code that is semantically correct, but doesn't perform the necessary actions that were intended).

The algorithm (as previously defined) is to pick the lowest construction/upgrade ROI and build/upgrade that particular building. While this is not a perfect simulation in that aspect, it will pick the lowest ROI and only pick the one that is the lowest. I am thinking of implementing a feature of only picking the lowest one that can be afforded at the time, or just saving up until the lowest ROI regardless becomes available.

http://imageshack.us/a/img26/6560/ccsimulation.png

Like I said, there still needs to be the implementation of more buildings, and other features. I worked long and hard on this just for the sake of it, but if anybody who wants to see the code wishes, just drop me a PM and I'll be glad to share it if you don't mind a million debug areas commented out. Don't worry, my code is very neat and has very good conventions.

Dipstik
10-21-2012, 07:56 PM
If only this sort of ingenuity could be harnessed for something useful...

PawnXIIX
10-21-2012, 08:01 PM
If only this sort of ingenuity could be harnessed for something useful...

Dear GREE...


...Hire me. :)

Trevor b. Trollin
10-21-2012, 08:04 PM
If only this sort of ingenuity could be harnessed for something useful...

Couldn't disagree more. This could cure cancer you see...

PawnXIIX
10-21-2012, 08:06 PM
I'm about 2 years into a computer science degree. I hope there's a company around here offering internships, I would really love to get paid for this sort of stuff. :p

Tomatoneverdie
10-21-2012, 08:12 PM
Create your own game, Pawn City? And make sht load of money....

PawnXIIX
10-21-2012, 08:17 PM
Create your own game, Pawn City? And make sht load of money....

Ah, yeah I wish it worked that way :p

Dipstik
10-21-2012, 08:22 PM
Maybe you could help me with my idea for a game. It involves people sending me money and me drawing penises for them in ms paint. The penises would be bigger if they send more money. Then they can show people how big their e-penises are... Or maybe fight with them somehow. I'll make a fortune.

Gree, you better not steal this!

Trevor b. Trollin
10-21-2012, 08:28 PM
Maybe you could help me with my idea for a game. It involves people sending me money and me drawing penises for them in ms paint. The penises would be bigger if they send more money. Then they can show people how big their e-penises are... Or maybe fight with them somehow. I'll make a fortune.

Gree, you better not steal this!

I think people might just be stupid enough to fall for it. Kinda like buying pixelated gold right?

mxz
10-21-2012, 08:42 PM
Hasn't Ram already created this sim in C? Or C++? Either way, why rewrite it in crappy Java?

C# could be interesting just from a graphing and improved GUI perspective.

...And ROI is a terrible attribute. [/troll]

PawnXIIX
10-21-2012, 09:10 PM
Hasn't Ram already created this sim in C? Or C++? Either way, why rewrite it in crappy Java?

I was really bored! :) I'm not exactly happy with the IDE my school provided me for C++ class, so I used my much more enjoyable Java IDE :) I asked him if I could see his source code, but alas I have yet to get a reply. Maybe I'll just PM him.


C# could be interesting just from a graphing and improved GUI perspective.

I'll definitely look into that :p


...And ROI is a terrible attribute. [/troll]

You're just asking for a fight xD

AFed
10-21-2012, 10:08 PM
To save some trouble with making them, why don't you program in the multipliers for type a and type b buildings, and depending on the building name, you could make an instantiate building arrays method that does the simple multiplication to help you out...

PawnXIIX
10-21-2012, 10:14 PM
To save some trouble with making them, why don't you program in the multipliers for type a and type b buildings, and depending on the building name, you could make an instantiate building arrays method that does the simple multiplication to help you out...

The incomes are no problem, the issues is the construction times. I'm pretty sure most of the buildings follow different functions regarding how their construction/upgrade times increase. I've seen the multipliers, and they're all defined separately.

I've never really looked into the uniformity of the upgrade times, or the upgrade costs...maybe I'll do a study on it and figure out a formula or something.

Ramshutu
10-22-2012, 11:24 AM
Hasn't Ram already created this sim in C? Or C++? Either way, why rewrite it in crappy Java?

C# could be interesting just from a graphing and improved GUI perspective.

...And ROI is a terrible attribute. [/troll]

Ah yes. Java, the short bus of programming languages.

My one is written in Qt/c++. Image revoking some bits of it now, it isn't nearly oo enough. Whacking on a ui and stuff too.

Ramshutu
10-22-2012, 11:28 AM
PS: You can PM me your email address and I'll send on the source; but at the moment i'm in the middle of fiddling (I'm not happy with the proceduralness of what I had).

PawnXIIX
10-22-2012, 11:32 AM
Ah yes. Java, the short bus of programming languages.

My one is written in Qt/c++. Image revoking some bits of it now, it isn't nearly oo enough. Whacking on a ui and stuff too.

At least I enjoy my work :p I was going to make a user interface but the problem is that unless I implemented a GUI then there'd be code in the background that wouldn't be executing because I'd need to wait for user input. Then when the user input is going on there needs to be a wait, and the buildings in the background wouldn't update :(

I'd love to see what you do when you're done :) I enjoy seeing different approaches that everybody comes up with when they try to tackle a problem ^^

Ramshutu
10-22-2012, 11:58 AM
At least I enjoy my work :p I was going to make a user interface but the problem is that unless I implemented a GUI then there'd be code in the background that wouldn't be executing because I'd need to wait for user input. Then when the user input is going on there needs to be a wait, and the buildings in the background wouldn't update :(

I'd love to see what you do when you're done :) I enjoy seeing different approaches that everybody comes up with when they try to tackle a problem ^^

My approach is pretty simple for the moment (and I'm bored which is why I'm changing it).

I have a "Hood" emulation class that holds a list of buildings that are available (two of each), and sets up the starting building. There are multiple versions of this emulation class, which holds an algorithm. The algorithm is a simple interface class, which can be reimplemented by specific algorithms such as GFI or ROI.

This class has two functions 1.)"reorder building list", which occurrs prior to any new upgrade being completed, which pre-orders the list of buildings so that the most desirable are at the top, and the least at the bottom. 2.) getBuilding which returns the next building to use for either an upgrade or build.

The hood simulation class has a "Tick" function which moves the whole simulation forward X hours (I have chosen increments in 5 minutes), which collects any buildings that are outstanding, chooses any upgrades if they are complete, etc.

Each hood simulation class is ticked at the same time, and every N ticks, the current stats of all simulation classes are output to a file.

The way the collections etc are done is all pretty procedural. I'm breaking this down into a class based approach, which basically makes every "timed event" that can occurr into a class that will do things automatically without lots of additional code doing things.

PawnXIIX
10-22-2012, 12:22 PM
My approach is pretty simple for the moment (and I'm bored which is why I'm changing it).

I have a "Hood" emulation class that holds a list of buildings that are available (two of each), and sets up the starting building. There are multiple versions of this emulation class, which holds an algorithm. The algorithm is a simple interface class, which can be reimplemented by specific algorithms such as GFI or ROI.

Yeah I feel like i'm going to have different methods. Right now my main function calls 3 functions: populateBuildings() which reads the data from the sheet and instantiates the buildings, beginTimer() which runs the simulation until a certain condition is met, and exitProgram() which very simply ends the program when said condition is met. I'm planning on having methods like beginTimerROI() or beginTimerGFI() which would define the algorithm used.



public static void main(String [] args)
{
populateBuildings();
beginTimer();
exitProgram();
}



This class has two functions 1.)"reorder building list", which occurrs prior to any new upgrade being completed, which pre-orders the list of buildings so that the most desirable are at the top, and the least at the bottom. 2.) getBuilding which returns the next building to use for either an upgrade or build.

My lists are re-orderable, and that sounds like a good idea to have in this program. Sadly mine is written with one main class and just one external object per building that holds the data for that individual building. I made sure to keep my array use down to a minimum and take advantage of java arraylists which are infinitely more manipulative.


The hood simulation class has a "Tick" function which moves the whole simulation forward X hours (I have chosen increments in 5 minutes), which collects any buildings that are outstanding, chooses any upgrades if they are complete, etc.

Each hood simulation class is ticked at the same time, and every N ticks, the current stats of all simulation classes are output to a file.

That's much different than mine. I was thinking of running it off an imaginary timer, but for now I run it off real time. The hood gets an update every x milliseconds, probably about 10 updates a second. This is why I wrote "realtime" because everything takes exactly as long as it does in Crime City. It's already becoming annoying with the 2 hour Laundromat upgrade at level 4 :p


The way the collections etc are done is all pretty procedural. I'm breaking this down into a class based approach, which basically makes every "timed event" that can occurr into a class that will do things automatically without lots of additional code doing things.

Every building class as a method called update. Every tick calls this method which in turn flags it for different things.
the update method first checks if it's level 0, if the building is level 0 it skips every check and instantly return to the main class. The method then checks if it is building or upgrading, if this is true, it checks if it has timed out. If it has timed out, building and upgrading are set to false. If it was upgrading, the level is incremented. Upon building, the level is instantly set to 1 or else it would not be seen by the update class.

Next comes the payout. If it is past the time for the collection, it flags collectionNeeded as true. The next update method in the main method (x milliseconds later) it sees this variable, and calls the method in the building class and the cycle repeats.



public void update()
{
if(level == 0)
return;
long currentTime = System.currentTimeMillis();
if((upgrade || building) && (upgradeFinished <= currentTime))
{
if(upgrade)
{
level++;
System.out.println("Upgrade for the " + name + " to level " + level + " complete!");
}
else
System.out.println("Construction for the " + name + " complete!");
upgrade = false;
building = false;
}
/*if(upgrade || building)
{
System.out.print("Upgrade time remaining: ");
double timeLeft = (upgradeFinished - currentTime) /1000;
System.out.println(timeLeft);
}*/
if(nextPayout <= currentTime)
collectionNeeded = true;
}


You can see I still have some debug code in there in case the method decides to re-break itself or I put the data in wrong :p

Ramshutu
10-22-2012, 12:47 PM
Send me a PM; I have some code I can send you if you're interested ;)

PawnXIIX
10-22-2012, 12:57 PM
Send me a PM; I have some code I can send you if you're interested ;)

Okay :) I'm thinking of making a automated data entry program just so I can fill in the data faster.

Asks for name, level unlock, ect. Automatically converts upgrade time into seconds...going to be fantastic :D

Ramshutu
10-22-2012, 01:01 PM
Okay :) I'm thinking of making a automated data entry program just so I can fill in the data faster.

Asks for name, level unlock, ect. Automatically converts upgrade time into seconds...going to be fantastic :D

I would recommend saving the hood spreadsheet as .CSV; and then reading it and parsing it (CSV easy to parse). That way you do not have to enter anything.

My stuff is based on Qt; but it should be translatable.

WestLondon
10-22-2012, 01:09 PM
Dear GREE...


...Hire me. :)

Your sucking up is cringeworthy and this isn't the first time I've seen It from you.

Listen the best advice I can give you is this

It's not all about what you learn at high school when it comes to software, I left school when I was 15, got a hand into desktop support at a blue chip and worked my way up

I got so far and end of the day 50k is fcuk all when you spend 300 on don perigon,

Anyway, learned trading and now work for bony, you can laugh at the name but the people in the know will know.... Tuck in

PawnXIIX
10-22-2012, 01:25 PM
Your sucking up is cringeworthy and this isn't the first time I've seen It from you.

Two things:

1. That was a joke...
2. I have a lot to learn and I was bored and made this in my spare time, forgive me for sharing it.

WestLondon
10-22-2012, 01:32 PM
Two things:

1. That was a joke...
2. I have a lot to learn and I was bored and made this in my spare time, forgive me for sharing it.

One thing

Stop acting desperate

Either grow a pair and do it yourself or wait for a hand out

Ramshutu
10-22-2012, 01:35 PM
One thing

Stop acting desperate

Either grow a pair and do it yourself or wait for a hand out

I think I saw Dravak and Dipstick in another thread. You need to be quick, they aren't going to troll themselves.

Sasha54
10-22-2012, 01:54 PM
I'm about 2 years into a computer science degree. I hope there's a company around here offering internships, I would really love to get paid for this sort of stuff. :p

Learning is ALWAYS useful - don't listen to the detractors - better you spend your time expanding your knowledge as opposed to being a bitter troll type.....

PawnXIIX
10-22-2012, 01:58 PM
I already have a job for when I graduate...it's called a joke... <.<

I love sharing what I make when I'm bored...all about open source and whatnot.

Dipstik
10-22-2012, 02:01 PM
I think I saw Dravak and Dipstick in another thread. You need to be quick, they aren't going to troll themselves.

Well sometimes when I'm really bored...

Dipstik
10-22-2012, 02:03 PM
Two things:

1. That was a joke...
2. I have a lot to learn and I was bored and made this in my spare time, forgive me for sharing it.

He be trollin'. You hatin'.

kitzune
10-22-2012, 02:33 PM
This sounds very interesting guys.

Just curious wouldn't you want the hood to auto collect until

next upgrade needs to be chosen
next building to build needs input
a "hood sleep cycle occurs" so if you set the hood owner sleeps between 00:15 and 8:00 am then no collections happen and buildings will be reset for the collection start period. so any collection period less then 8 hours will be reset to 8 assuming that 8 hour is collected before sleep period.

Ramshutu
10-22-2012, 02:39 PM
This sounds very interesting guys.

Just curious wouldn't you want the hood to auto collect until

next upgrade needs to be chosen
next building to build needs input
a "hood sleep cycle occurs" so if you set the hood owner sleeps between 00:15 and 8:00 am then no collections happen and buildings will be reset for the collection start period. so any collection period less then 8 hours will be reset to 8 assuming that 8 hour is collected before sleep period.


I would say yes to all the above.

The original Simulation I had made this difficult, but I have been reworking things a bit to build in a better structure to allow ALL of the above.

PawnXIIX
10-22-2012, 02:44 PM
This sounds very interesting guys.

Just curious wouldn't you want the hood to auto collect until

next upgrade needs to be chosen
next building to build needs input
a "hood sleep cycle occurs" so if you set the hood owner sleeps between 00:15 and 8:00 am then no collections happen and buildings will be reset for the collection start period. so any collection period less then 8 hours will be reset to 8 assuming that 8 hour is collected before sleep period.


If will auto collect until the money for the lowest ROI upgrade becomes available. If there is enough money and an upgrade/construction available, it will commence that upgrade/construction.

The input would involve some GUI because otherwise if it ran on command line only then it would be waiting on user input before continue with the update method.

The sleep cycle, we'll see about that. I never really planned on making this run a legitimate situation. Like I said, the furthest I made it to was 2 level 1 gas stations, 1 level 4 laundromat, 1 level 3 laundromat, and 2 level 1 pizza parlor I believe. Those were the only buildings I programmed in at the time.