How do I write a function that checks whether there is a horizontal, vertical or diagonal connect N?
1 次查看(过去 30 天)
显示 更早的评论
Input:
M = [0,0,0,2,0,0,0;0,0,0,2,0,1,0;0,2,0,1,1,2,0;0,1,2,1,1,1,0;1,2,1,2,2,2,0;2,2,1,2,2,1,2]
Visualization of input:
--------------- x = 1
| | | |o| | | | o = 2
| | | |o| |x| |
| | | |x|x|o| |
| |x|o|x|x|x| |
|x|o|x|o|o|o| |
|o|o|x|o|o|x|o|
---------------
A connect 4 is present:
0 0 0 2 0 0 0
0 0 0 2 0 1 0
0 0 0 1 1 2 0
0 1 2 1 1 1 0
1 2 1 2 2 2 0
2 2 1 2 2 1 2
My question:
How do I write a function that checks whether there is a horizontal, vertical or diagonal connect N (connect 4/5/6 etc. (program is scalable)) in this matrix?
9 个评论
Stephen23
2019-12-16
"This function shouldnt return a 2 value, but a 0 value, idk why that's happning... there's no connect N."
Actually there is. Let me highlight it for you:
0 0 0 2 0 0 0
0 0 0 2 0 0 0
0 *2* 0 1 1 2 0
0 1 *2* 1 1 1 0
1 2 1 *2* 2 2 0
2 2 1 2 *2* 1 2
Why are you still using the outdated answer? Even though I have written around ten times that I updated/fixed my answer, you are still using the version that does not detect anti-diagonals.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!