连接四个javascript游戏问题

连接四个javascript游戏问题,javascript,Javascript,我有以下代码 这是isVictory函数: function isVictory(placedX, placedY) { var i, j, x, y, maxX, maxY, steps, count = 0, directions = [ { x: 0, y: 1 }, // North-South { x: 1, y: 0 }, // East-West { x: 1, y: 1 }, // Northeast-Southwest

我有以下代码

这是isVictory函数:

function isVictory(placedX, placedY) {
  var i, j, x, y, maxX, maxY, steps, count = 0,
    directions = [
      { x: 0, y: 1  }, // North-South
      { x: 1, y: 0  }, // East-West
      { x: 1, y: 1  }, // Northeast-Southwest
      { x: 1, y: -1 }  // Southeast-Northwest
    ];

  // Check all directions
  outerloop:
  for (i = 0; i < directions.length; i++, count = 0) {
    // Set up bounds to go 3 pieces forward and backward
    x =     Math.min(Math.max(placedX - (3 * directions[i].x), 0), circle.length    - 1);
    y =     Math.min(Math.max(placedY - (3 * directions[i].y), 0), circle[0].length - 1);
    maxX =  Math.max(Math.min(placedX + (3 * directions[i].x),     circle.length    - 1), 0);
    maxY =  Math.max(Math.min(placedY + (3 * directions[i].y),     circle[0].length - 1), 0);
    steps = Math.max(Math.abs(maxX - x), Math.abs(maxY - y));

    for (j = 0; j < steps; j++, x += directions[i].x, y += directions[i].y) {
      if (circle[x][y] == circle[placedX][placedY]) {
        // Increase count
        if (++count >= 4) {
        return true;
          break outerloop;
        }
      } else {
        // Reset count
        count = 0;
      }
    }
  }

  //return count >= 4;
}
问题是它没有检查东南西北方向。
你能告诉我怎么了吗?

你可以解释一下西北方向是什么:从右下到左上我刚刚在你的JSFIDLE上尝试了几个快速的游戏-两条对角线都以成功的胜利结束,再次尝试。从右下到左上不起作用当最后一个放置在斜坡顶部或底部时。看起来你有一个更微妙的错误。