Generate the world.
You will have Width: W and Depth: D(number of tiles in width and in depth). W and D size don't need to cover entire map. You will be generating new "tiles array entries" as player will go deeper.
You have 3(as example) materials: A, B, C (mud, iron, gold [1,2,3 - in array]).
You create "terrain" array sized WxD
You start at terrain(0,0). For this tile generate random number(100)=R.
Single Tile generation:
You create 3 sets <0,a>; <a,b>; <b,100> + if-avaible array at given depth.
a and b will regulate how often material of given type appears at current depth. If-avaible tells if at current depth it is possible to encounter current material (0 for no 1 for yes).
If 0=<R<= a
If a= R <= b
Material_code = 2
If b=R<= 500
Material_code = 3
Before setting every value you check if-avaible array
index 0 1 2 3
material is available at given depth 0 1 1 0 [At depth = 0 it is impossible to encounter gold(3) but you can encounter mud(1) and iron(2)]
You check if if-avaible_array(Material_code,)= 1
If yes: (0,0)= Material_code
If no: generate random number R(100) again.
You do this for Terrain_array from (0,0) to (W,0)
Update of probability:
Once you fill (W,0) You will move to (0,1). Before you do it:
update a, b - in order to show how probability changes with depth (with "a" getting smaller there will be less mud and more iron)
update if-avaible array in order to show if player has reached depth at which he is able to find new minerals.
Fill the row as you did before.
Part II will tell how to do "moving".