samedi 6 février 2021

How to generate random board for a game in java but according to specefic conditions?

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:

  1. 2/3 of the board must be OCEAN
  2. a MOUNTAIN or PLAIN or FOREST or DESERT must have at least one neighbor that is not OCEAN biome and by neighbor i mean in its north, south, east or west. The first condition is easy to implement but the second one i don't know how to i looked around on the net but nothing is similar to my condition. There is an example of a board in the image below (blue cells are OCEAN, yellow is DESERT, light green is PLAIN, green is FOREST and brown is MOUNTAIN).

Code of enum of biomes

public enum Biome {
    MOUNTAIN, PLAIN, DESERT, FOREST, OCEAN;
}

UML of class Cell UML of class Game Example of a board




Aucun commentaire:

Enregistrer un commentaire