I am making a board game for college project and it needs to be done in java, the part that i'm stuck in is generating the board game now imagine with me we have a square shaped board and its size is variable meaning the player decides at the beginning of the game, and the board is composed of Cells i have a class defined that represents the cell (UML of class below) and the board is just a 2 dimension array of cells (UML of the game class) and each cell has a biome (MOUNTAIN, PLAIN, DESERT, FOREST, OCEAN) the biomes are defined in a enum, now my problem is i need to generate a random board for each game and the borad needs to fulfill two conditions:
Code of enum of biomes
public enum Biome {
MOUNTAIN, PLAIN, DESERT, FOREST, OCEAN;
}
I guess you will fill your board row by row or column by column.
You know:
int nonOceanBiomeLeft
)while you fill up, for each field you decide randomly (depending on its weight) what you will set. When you place a non-Ocean biome you reduce nonOceanBiomeLeft
by one. If it is already nearby another non-Ocean you stop here for that field, otherwise you need to reduce nonOceanBiomeLeft
one more time and add one to something like int nonOceanBlocked
(if your new field is without neighbor), this is to make sure you do not create a new noOcean biome somewhere and have none left to have the conditions fulfilled. So wenn you have none left you cannot create a noOcean biome.
If you have nonOceanBlocked > 0
you need to watch for the neighbor in the row above if it is an alone nonOcean biome (so save the neighbor info for each field or calculate it on the fly). If your neighbor in the row above is alone you need to add a noOcean and you remove one from nonOceanBlocked
Since this one has a neighbor you don't need to increase nonOceanBlocked
again.
Additionally if you create a new noOcean biome and the last field was an alone noOcean you can decrease nnoOceanBlocked
too.
Be careful with
nonOceanBiomeLeft
is equal to one you cannot place it somewhere it has no neighbor, since you would need to dThis is only a theoretical description of what you could do, but for a college project I guess you should do most of the work yourself ;) I hope it helps you as a starting point for the filling of the board.