检测8x8矩阵中连续值的策略

时间:2013-10-21 00:11:47

标签: c++ path-finding 2d-games

我正在构建一个类似于奥赛罗的益智游戏,我想建立一个帮助玩家学习游戏的教程模式。要做到这一点,我需要检测连续值的水平,垂直和对角线(在这种情况下,白色或黑色),以显示玩家可能做出的下一步动作......

enter image description here

我正在用C ++构建它,但我真的只对使用2D矩阵检测线条的一般策略感兴趣(如果它简化了事情,则可以用于一维数据)。

我目前的策略非常简单,这让我怀疑这是最慢的方式......

for y = 0 to 7
  for x = 0 to 7
    cell = find the first unoccupied cell (no color)
    inspect the 8 surrounding cells to see if they contain a color
      if so, trace the cells in that direction to see if it forms a line of at least 3 contiguous colors
        if so, store the coords of those cells in a list of detected lines

其他想法?

提前感谢您的智慧!

1 个答案:

答案 0 :(得分:1)

Clustering,特别是hierarchical clustering可能会有所帮助。

相关问题