functioncountCapturedStones(board) { // N x N 的棋盤 const N = board.length; // 建立一個二維陣列,並且我們把它填滿false,象徵我們目前還沒拜訪過此棋 const visited = Array.from({ length: N }, () =>Array(N).fill(false));
functioncountCapturedStones(board) { // N x N 的棋盤 const N = board.length; // 建立一個二維陣列,並且我們把它填滿false,象徵我們目前還沒拜訪過此棋 const visited = Array.from({ length: N }, () =>Array(N).fill(false));
for (let i = 0; i < N; i++) { for (let j = 0; j < N; j++) { // 判斷當前的棋子是否為氣或者已經被拜訪過 if (board[i][j] !== '.' && !visited[i][j]) { // W or B const color = board[i][j]; // 拿這個顏色棋子去跑dfs,並且回傳我們總共可以提取多少棋子 const capturedStones = dfs(i, j, color);
functioncountCapturedStones(board) { // N x N 的棋盤 const N = board.length; // 建立一個二維陣列,並且我們把它填滿false,象徵我們目前還沒拜訪過此棋 const visited = Array.from({ length: N }, () =>Array(N).fill(false));
for (let i = 0; i < N; i++) { for (let j = 0; j < N; j++) { // 判斷當前的棋子是否為氣或者已經被拜訪過 if (board[i][j] !== '.' && !visited[i][j]) { // W or B const color = board[i][j]; // 拿這個顏色棋子去跑dfs,並且回傳我們總共可以提取多少棋子 const capturedStones = dfs(i, j, color);
I’m a software engineer and a small business owner with extensive experience in leading teams and planning software architectures and guidelines. If you are interested in me, you can follow my resume.