我一直在做一项任务,需要我在 matlab 中重新创建黑白棋。
我遇到了一个断点,我无法弄清楚如何在不将其转换为线性索引的情况下执行一段代码。
本质上,我需要做的是想办法将方向向量(即 [-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 循环来确定是否保持当前方向,但我似乎无法找到自己的方法。
任何援助将不胜感激。
谢谢你的时间!