Blog Posts
Map Generation
One of the fundamental aspects of the game that we needed to address first of all was the random terrain generation in which the game would be played. We chose to create a map using hexagons, as this allowed us effectively 6 directions of motion from each hexagon and would make the map look more natural. We decided that the map should be different every time, so no two games are the same, and so we needed to create an algorithm that would draw us a map which looks random, but also has some predictability about it, in that it has a basic shape to it and will not be toosmall or too large. As well as this, the algorithm also had to be dynamic, so that if we wanted to create a much larger game area for several players then the same code could be used. I decided that the best way to go about doing this would be to use RNG (Random Number Generation) to create a border between the land and sea, and then define the area on the outside of the border to be sea, and inside of it to be land. However this border needed to represent the shape of a coastline, with varying amounts of indents and extensions of land etc. therefore the RNG used determined the direction the the border would continue in from each hexagon tile, weighting the probabilities using the relative closeness of the border to the centre of the map area. This made sure that the map was not too small and had a vague consistent shape to it, however it maintains some variety. The border would continue up to an indent generated from each side, at which point it would move to another part of the algorithm to generate the next side of the map. Unfortunately this could not be used for the entirety of the map as the randomly created indent only represented an x or a y value, rather than a specific coordinate to draw to, and so, in order to make sure that the border created would connect with itself we used the A* pathfinding algorithm to generate the last small section of the border. Once the border had been generated we then needed to assign all of the hexes outside of the border as a ‘sea hex’, and in order to do this we used a variant of BFS (breadth first search) from a point on the map that was guaranteed to always be outside of the land area.