Jump to content
  • Advertisement
  • entries
    19
  • comments
    0
  • views
    963

Project: Fraud Simulator

Refactoring the Economy

KrisWolfe

645 views

The data model merge took place. I broke the code and then rebuilt it. This is actually more fun than I imagined.

So, now I'm working on refactoring the market code to allow it to be extensible as I add in company behavior. All the market decisions were being handled inside the market controller class before, but now with more knowledge of C#, I'm moving it to basically a "flow" controller.

The main loop in the game turn is basically 4 for loops...beginning of the day, middle of the day, end of the day, and finalize. The beginning of the day I build up the lists that I need...which markets are available for consumers to eat from? Who needs employees? Who needs a job?

The middle of the day is where the player's actions gets executed and all the contracts get executed. The UI will collect player actions and here we inject them into the economy. The Job contracts will perform their tasks, pay their employees, remove themselves if they've expired, and send goods to other companies based on the terms of the contracts. Also we randomize the order of the lists so that the same agent doesn't get first mover advantage everyday.

The end of the day is when we execute commands for the AI. Companies hire employees, get contracts, decide on new states for the AI. Finalize is where the economy goes over everything and updates its average market prices and market shares based on the actions of the day.

So my old market code was 500 lines long. Now I'm going to have the actual companies decide what they need to do. Retail companies and manufacturers need to do different things, so I'll have an interface for them that basically say "BeginningOfDay()" but they will be done differently. Interfaces are clean and nice for this.

I also ran into an issue when I was merging data models. I have two interfaces, IAgent, and IEmployee, that are both on the ConsumerAgent class. But if I make an IAgent, it doesn't have access to the IEmployee methods. I started just copying the methods I needed to the IAgent interface, but then I realized I was violating the DRY principle (Don't repeat yourself). I discovered that IAgent can actually implement IEmployee interface, which is hilarious to me. Interfaces are so nice.

I also ran into another issue with interfaces. Production Agents and Retail Agents both have an ICompany interface, which means they both implement a "HireEmployee" method. But it's the exact same method. I'm violating DRY principle by just copy pasting the code. Then I realized I could use both an abstract class Company AND implement interfaces. Mind blown. Seriously. So now when we have financial statements and accounts like "cashOnHand", I don't have to keep copy pasting that property to all these classes.

So, pretty excited to get this code refactored and working. No pictures for awhile since this is all just code, but hopefully show some different employees and companies off as I get them off the ground and rolling.




0 Comments


Recommended Comments

There are no comments to display.

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
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By RoKabium Games
      Metis enemies – "Strank" is a pretty fast creature but with a thin exoskeleton. It can be easily defeated even with the most basic of weapons.
    • By LilFireGames
      Here is a Gameplay video of my school project. Any feedback would be greatly appreciated.
      [media]
      [/media]
    • By LiamBBonney
      Hi, my name is Liam, founder of TheIndieGamesLab! The hub of gaming experimentation. We believe that testing and experimenting with new and unique ideas is incredible important at TheIndieGamesLab. We also understand that when people have created something so different it is important to bring it into the spotlight, whether that be a new mechanic in a game, a new type of visual or even a streamer play testing and experimenting with new games. It is important to break pattern!
      If you feel your work is something unique and fresh we are here to help you not only promote your work but share ideas and experiment further with you. The idea of experimentation is fascinating to us. This is why the name TheIndieGamesLab has been chosen. We are fully aware of the importance of bringing great work and discoveries into the eyes of the public, ESPECIALLY when it’s a new and unique idea!
      Not only will we do our very best to help Indie Game Developers, we are helping any gamer with a new and fresh idea that they want to bring to the table or be displayed in front of the gaming community. This means we are here to help Indie Gamers, Indie Game Devs / Studios and so on! As well as helping the gaming scientists out there trying to bring something fresh to the lab, we want to inspire gamers to start experimenting and create something memorable.
      This is the start of something special. Together we can make TheIndieGamesLab the hub that gaming content creators can come to gain the recognition and support their work deserves! And become a movement! A movement to inspire and create!
      I have also created a discord server providing a platform for indie game developers to communicate with one another to help support each other and upcoming and existing projects. This server lets people get instant support from indie game devs that are just as passionate about it as you! You can also promote you new projects or post updates to your current projects, please com along, I look forward to seeing you there. Let's support each other in this crazy world that is indie games!
      Join now at https://discord.gg/efa6j3a

    • By IGStudios
      We are currently working in a new indie Survival Crafting game, the project "Putrid" is looking for focused resource farming and modifiable environment.
      The project have an advanced state of development with many items and assets.
      We want a programmer with experience in c# to handle the main mechanics of the game.


      here's our Discord: https://discord.gg/hZQYapv
      and here's my mail for any doubts: tyxefield@gmail.com
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!