Advertisement

Board representation for a turn-based tactical game

Started by January 23, 2021 06:11 PM
3 comments, last by Alberth 3 years, 9 months ago

Hello,

I'm developing a turn-based tactical game, and i'm struggling with which would be the best way (data structure) to represent de board. The board is composed of squares, but for each game, in different board locations, it may have some blockages (walls or others) between some squares (like HeroQuest or Zombiecide). I'm programming in Java, but I'm searching for some language independent concepts.

Thank you.

Couldn't you just wrap an array of some tile type in a new Board class, exposing the required functionality and call it a day?

Advertisement

I use a 2D array Map(x,y) which is a pointer to a Terrain structure array

So in the map array Map(10,2)) contains a number to look up the Terrain() array

The Terrain array holds a structure/record that contains data about the terrain in the tile like

Can see through bool

Cost to move through (for different terrain types and or unit types)

Blocked Edges within tile (bits used within a byte)

Graphic tile to display

etc etc

so if Terrain(Map(x,y)).MoveThrough then (allow move)

Movecost = Terrain(Map(x,y)).MoveCost

rofellos said:
it may have some blockages (walls or others) between some squares

Assign half the edges of a square to it, eg the upper and right edge. Add two booleans (blocked/unblocked for both edges) or two enum-values (unblocked/wall/bush/etc) to a square and you're done.

The only “problem” you have is that you cannot have blockage at the left and bottom of the playing field. Likely you don't care, but if you do, add an invisible additional row and column at the bottom and left that only exist for storing the blockage information.

For movement, the downside of this minimal solution is that to move left, you first have to check the right edge of the left neighbour square. For turn-based probably not a big deal, but you can avoid that by duplicating the edge information, so both squares neighbouring an edge have the edge information. The latter would also fix your edge of the playing field problem.

This topic is closed to new replies.

Advertisement