# How do I write a function that checks whether there is a horizontal, vertical or diagonal connect N?

조회 수: 9(최근 30일)
The Legend 2019년 12월 16일
댓글: The Legend 2019년 12월 16일
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표시숨기기 이전 댓글 수: 8
The Legend 2019년 12월 16일
I had commented right before you posted this haha, my bad, sorry. Really appreciate the help!

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by