# Mine game Stochastic process example

Today I will be continuing with looking into the topic of Stochastic process in statistics which is more or less a fancy formal way of random rather than deterministic processes.

There is a whole world of examples that come to mind when it comes to this, and there are or course many great examples that have all ready been made over the years. However in this post I will be going over a basic example of this kind of system that comes up when it comes to making a basic idle game. In such games there is often some kind of resource that the player gains over time by clicking something, having a way to automate the process of gaining resources without having to click, and having a way to gain a large sum of resources while away from playing.

## 1 - The source code for a mine function

So the general idea that I have here is to have a mine function that will take some arguments that have to do with the count of mine events, the method to use to come up for amounts or ores, and a collection of ores. This kind of function by default could be like a pure function if I do design it that way, but in any case it would never be a true pure function because I can always give it a mine method that makes used of Math.random. Also this is a post on the topic of the concept of a Stochastic process rather than a deterministic system, so by default it will make use of Math.random.

### 1.1 - The mine function

So then here is the source code of the mine function that I have in mind. I actually return the function within another function by way of following the IIFE module pattern in javaScript. Inside the body of the IIFE I have some hard coded defaults for ores and mine methods.

When it comes to the mine methods I have a single random method that involves the use of a single call of Math.random, and single pure that involves just a single call of an expression that does not make use of Math.random, and is more in line with the concept of a pure function. In other words a function that will always return the same result for the same arguments.

### 1.2 - Basic example of the mine function

Now to test this mine function out to see if it works the way I want it to. There are three general ways I might go about using this mine function one is to make use of it when it comes to a player clicking something that will result in a single mine event each time it is clicked. The other user case is to have a main app loop update method that will call this mine method once every game update tick. Then there is also adding an away production feature, where a large number of ticks will be done in one shot, once, when the app first starts up after that player was not playing for a while and came back to my site.

## 2 - Conclusion

This kind of function is something that I am using, or should be using, at the core of some of my idle games. In the event that I am not there is still using some kind of system that is not all that far off from what this is. I do not think that an idle game has to be completely stochastic in nature, many good idle games are not that much. However there is still a degree of randomness when it comes to a player making some kind of action or not.

I often do work on improving the source code and experience of some of these games and many other projects that are like this. So it is highly likely that I will be coming back to this now and then in the future.