Economic strategy or 4,200 bytes in 10 years

    My previous post “ How to make a 3D shooter using JavaScript in a couple of days ” showed that the topic of developing browser games is very interesting and for this reason I decided to devote another weekend to my other idea.

    This time the weekend fell on New Year's holidays and there was a little more free time than usual, that's why I will narrate slowly and start with a little history.

    2002 year. Summer

    Ten years ago I worked as a night watchman, but the watchman of me was not quite ordinary. Since I was a computer freak since childhood (I first met Agat at the age of seven), I came to work with my laptop and modem and really did not sleep until 10 am the next day.

    I spent all night on the net. It was very convenient for me to “work”, because in fact I received money for what I did most often at night, only in this case I don’t have to share a telephone line with someone and it’s very quiet to go around a cup of tea in a dark apartment . And everything was cool and smooth, until suddenly enough frequent interruptions began with the provider, which, for a number of reasons, I could not change. Since I always take work seriously enough, and it was hard not to sleep without a connection, I urgently needed a replacement in the form of “offline” entertainment.

    That's exactly when I downloaded a rather interesting “toy” somewhere. Unfortunately, I can’t remember exactly its name now, most likely “Fish Tycoon”, the Russian programmer wrote it (that's for sure). In the game, it was proposed to build an empire based on fish trade (well, yes, why not), gradually expanding the trading network, it was necessary to master the entire market, which was the result and could in theory lead to victory in the game (it didn’t work out). As a watchman, I worked for about half a year and during this time I managed to play enough.

    Years passed, I changed jobs, went about my business, hired again, moved to another city, created various projects, but often I remembered with warmth those half a year and the “same” game. To be honest, the idea to write an analogue settled in my head probably two years ago, but I always put off this idea for a number of reasons. In addition, it always seemed to me that there would be a lot of code.

    year 2013. Winter

    And then came the next New Year holidays. As expected, I finished all affairs before the end of the year, closed all obligations, and with a clear conscience and fun I met the New Year at home with my family. Waiting for the next replenishment in the family from day to day, I could not afford to drink more than a glass of champagne at the table, so on January 1, when everyone was peacefully sleeping in their beds, I lay and thought over the architecture of the new project.

    Almost immediately, I decided not to focus on fish, although nostalgia forced me to first give the project the code name “fish”, then I decided to ignore the name of the product, leaving only the word “product”.
    And on the night of the first to second, I sat down at my laptop and made the first drafts. Firstly, I clearly decided that I would have a convenient schedule that reflects the market situation in real time and it will definitely be on SVG. Here's one:



    Secondly, I set a goal to develop a simple model in a couple of nights, in which there will be both an element of risk and a practical calculation.

    So, what ultimately happened

    Having no knowledge in economics and finance, I built the model according to my own rules. The most important figure is the cost of goods in a specific period of time (purchase value), I calculate it using the time of day and sine, as well as a certain number of calls to Math.random ().
    Having this figure as a starting point, it’s quite easy to come up with an option to calculate the price of a sale, and if you get a couple of these values ​​and spice them up with a number of “accidents”, you can get a buyer's activity coefficient.

    In order to sell the purchased goods, we need to have a sales place and an employee who will do this.
    To do this, I implemented a model of a small store, which can easily be transformed into a warehouse, other options for stores or an office. You can also add several options for employees - managers to increase the profitability of trade operations and accountants who will help optimize taxation.

    The whole code is very simple, you can change various formulas and coefficients ad infinitum, I admit, I stuck on this business once until 5 in the morning. The result was a game in the game.

    Back to the process. The game cycle is calculated on a 24-hour basis, from 23:00 to 5:00 the next day, any trading operations are stopped, and the market does not work on weekends, so you can’t buy a new batch of goods. The rest of the time the trading process takes place automatically, in the cycle the probability of sales is calculated, its volume, taking into account the number of sellers in the store.
    By the way, sellers know how much time they already work, how much product they have already sold, this can be used in the future to simulate the process of increasing experience in trading or for example, to demand an increase in salary threatening the owner with dismissal.

    In order not to wait long before night or weekend passes, you can use various options for accelerating the x5 and x10 process so that the day runs unnoticed.

    At startup, a small help on the game process and a list of buttons that are more convenient to use than a mouse are issued.

    When buying and selling goods, we gradually rest against the ceiling of the size of the stocks of goods, then we still need to rent stores and hire sellers, a daily calculation is issued of how much has been sold, for what amount, rental costs, sellers' payments are calculated and the result is summed up.
    By the way, all events are broadcast in the log and you can always pause and delve into the details of what is happening.

    You can talk for a long time about what other moments await during the game, but then it will not be so interesting to play .

    I almost forgot, in the topic name appears “4200 bytes” - this is the size after packing and gzip compression of all .js files of the project.

    Remembering the wishes of the readers of the previous topic, I posted all the sources on github for a detailed study.
    This version will not be updated and no shortcomings will be fixed, I want to leave this project for myself, but if someone suddenly lights up with an idea - please use it for health.

    Last time a lot of questions were written personally, this time I suggest writing everything in the comments to the post.

    Also popular now: