我一直在做一個任務,需要我在matlab中重新創建reversi。Reversi有效移動檢查器
我已經達到了一個突破點,我無法弄清楚如何做一段代碼而不把它變成線性索引。
本質上我需要做的是找出一種方法來添加一個方向向量(即[-1; 0]垂直走向),我已經存在的game_state向量爲了找到它上面的數據。
function legal = legalMove()
d_l = [0, -1];
d_r = [0, 1];
d_u = [-1, 0];
d_d = [1, 0];
d_ul = [-1, -1];
d_ur = [-1, 1];
d_dl = [1, -1];
d_dr = [1, 1];
directions = [d_l d_ul d_u d_ur d_r d_dr d_d d_dl];
valid_moves = zeros(8,8);
for ci = 1:8
for cj = 1:8
if game_state(ci,cj) == 0 %check element = 0 before continuing
for count = 1:8
d = directions(count);
selected =
while selected == player_number * -1 %while the selected piece is of enemy type
%move as long as you find your opponents stones
if you found at least 1 opponent stone and you end up on your own stone
else
end
end
end
else
end
end
end
end
我的第二個問題之後,是實際的循環本身。 雖然我認爲可以使用while循環來確定是否保持當前的方向,但我似乎無法找到一種方法來自己做。
任何援助將不勝感激。
謝謝你的時間!
如果我理解這你只需要做一些像'sel_i = ci + directions(1,count);',然後類似於'sel_j',並檢查'sel_i'和'sel_j'是否在邊界內的董事會。 – wakjah