I have the following code that creates a matrix a predefined size and fills it with empty spaces
public class Juego
{
String tablero[][]= new String[15][35];
public Juego()
{
for( int i = 0; i < tablero.length; i++){
for( int j = 0; j < tablero[i].length; j++){
tablero[i][j] = " ";
}
}
I need to fill the matrix with an asterisk by column that receives its position in a random way but has an order that should be seen as "mountains" (that the height of the next is a higher or lower position maximum). But what I do not know how to do is the following: I need that if the level goes up or down in the next asterisk it is more likely that in the next rise or fall, for example that if the next asterisk went higher than previous it is more possible that the next one also goes up. Excuse me if I can not explain well because I do the best I can.
Currently playing with a probability array I get something like that
with the following code
public void generarAsteriscos()
{ int i=14;
int j=0;
tablero[i][j]="*";
while(j<=33 && i>0)
{
int p=definirPosi();
if(i+p<0){
j++;
i++;
tablero[i][j]="*";
}else if(i-p==15){
j++;
tablero[i][j]="*";
}else{
j++;
tablero[i-p][j]="*";
i=i-p;
}
}
}
public int definirPosi()// define donde va el proximo asterisco
{
int[] probabilidades=new int[100];
int cont=0;
while(cont<99)
{
probabilidades[cont]=cont;
cont++;
}
int resultado=(int) (1+ Math.random()*100);
if(resultado==100){
resultado--;
}
if(probabilidades[resultado]>=0 && probabilidades[resultado]<=40)
{
return 1;
}else if(probabilidades[resultado]>50 && probabilidades[resultado]<=80)
{
return -1;
}else{
return 0;
}
but as you will notice the probabilities will always be the same so it will tend to rise, I need to be more balanced that goes up and down or stays but does not generate something like
* * * **
* * * ***
has to generate something random that follows a format similar to this one with respect to the "mountains"