I have to implement the AI for Abalone game and I'm wondering what is the best way to represent the board logic using Java without wasting too much resources in all checks and updates routines involved.Is better use various lists? A matrix of Cell objects? Any suggestion?
Efficient way to represent hexagonal board logic for abalone-like games
java;design;artificial intelligence
1) since the board has a fixed-size that you're just going to be feeding into an AI anyway, you could just represent it as a one-dimensional array with the right number of cells, where each cell represents a space on the board. Mapping that one-dimensional array to the screen for presentation might be a little weird, but it's a problem you only have to solve once.The same would apply to validating moves; you could either create an adjacency matrix that tells which cells are adjacent to others, or come up with logic to determine adjacency. Either way, it would be a one-time cost.2) Notice that every hex grid is also a two-axis grid, except that the axes are 60 or 120 degress from each other, instead of 90 degrees like grids where X and Y are perpendicular. (Old hex-tile boardgames used this trick to label the hexes 1, 2, 3 in one direction, and AA, BB, CC in the other, skewed, direction.)I've looked at source code for computer implementations of board games that use (2), and they provided routines like find a line between hexes or find the distance between hexes. That was a long time ago, so the details are lost to time, but I remember it wasn't too hard.(It was more integer math rather than the Pythagorean stuff. ;))