反转对角搜索

问题描述

我从 Java 开始,我想知道如何反转图片中显示的对角线搜索,但从左下到右或从右上到左下。

图中对角搜索的代码为:

// top-left to bottom-right - green diagonals

for (int rowStart = 0; rowStart < rowMax - 4; rowStart++) {
  int count = 0;
  int row,col;
  for (row = rowStart,col = 0; row < rowMax && col < colMax; row++,col++) {
    if (gridTable[row][col] == player) {
      count++;
      if (count >= 4) return 1;
    } else {
      count = 0;
    }
  }
}

// top-left to bottom-right - red diagonals

for (colStart = 1; colStart < colMax - 4; colStart++) {
  count = 0;
  int row,col;
  for (row = 0,col = colStart; row < rowMax && col < colMax; row++,col++) {
    if (gridTable[row][col] == player) {
      count++;
      if (count >= 4) return 1;
    } else {
      count = 0;
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)