Why is is the following function only detecting diagonal functions that that start top left and end bottom right?

3 ビュー (過去 30 日間)
Why is is the following function only detecting diagonal functions that that start top left and end bottom right ( \ ) and doesn't it detect the mirrored version ( / )
Function checking for connect N
function victory = checkVictory(M, N);
victory = 0;
checkWin = @(x)conv2(x,eye(N),'same')>=N | conv2(x,ones(N,1),'same')>=N | conv2(x,ones(1,N),'same')>=N;
teamOne = checkWin(M == 1);
teamTwo = checkWin(M == 2);
if any(teamOne(:)) == 1
victory = 1;
elseif any(teamTwo(:)) == 1
victory = 2;
end
end
Output
---------------
| |x| | | | | |
| |x| | | | |o|
| |o|o| | |o|x|
|o|x|o|x|o|x|x| % <---- Here it doesn't detect the diagonal connect N (4 in this case)
|o|o|x|o|o|o|x|
|o|x|o|x|x|o|o|
---------------
Input piece in column [player 2]: 4
---------------
| |x| | | | | |
| |x| | | | |o|
| |o|o|o| |o|x| % <---- Here it does detect the diagonal connect N (4 in this case)
|o|x|o|x|o|x|x|
|o|o|x|o|o|o|x|
|o|x|o|x|x|o|o|
---------------
Player 2 has won the game!Play again? [yes/no]
Please help me, I'm clueless. All help is greatly appreciated.
  1 件のコメント
Stephen23
Stephen23 2019 年 12 月 16 日
編集済み: Stephen23 2019 年 12 月 16 日
"Please help me, I'm clueless."
Did you try reading my comment which I wrote an hour ago?:
"Why is is the following function only detecting diagonal functions that that start top left and end bottom right ( \ ) and doesn't it detect the mirrored version ( / )"
Not only did I explain this in my comment I also updated my answer with the very simple fix (based on flipud): is there a particular reason why you are continuing to use the old version?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometric Geodesy についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by