交叉匹配二维数组
尝试实现更大规模的井字游戏,
该游戏就可以有超过 3 行和列,
只要找到 4 个连续模式(水平、垂直或交叉),
玩家就是赢家
我已经找到了水平和垂直数学实现,
但是无法找到一种方法来识别二维数组中某个字符的交叉模式
考虑以下二维数组
`
char[][] char2d={
{'*','o','o','*'},
{'o','*','o','o'},
{'o','o','*','o'},
{'o','o','o','*'}
}
`
我如何检查'*'字符是否有四个连续的交叉模式这个二维数组
trying to implement a bigger scale of tic tac toe game
this game can have more than 3 rows and columns
whenever a 4 consecutive pattern is found(horizantal,vertical or cross)
the player is the winner
i already found the horizantal and vertical mathcing implemantation
but can't find a way to identify the cross pattern of a certain charcter inside a 2d array
consider the following 2d array
`
char[][] char2d={
{'*','o','o','*'},
{'o','*','o','o'},
{'o','o','*','o'},
{'o','o','o','*'}
}
`
how can i check if the '*' character has four consecutive cross pattern in this 2d array
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果给定的起始位置是长度为
s
且充满字符的向下对角线(如图所示,从左到右前进),则此函数返回
.true
c通过微小的改变,您可以测试向上的对角线。在
NxN
板上,只能在顶部的(N-s+1)x(N-s+1)
区域中存在对角线起点 -左角和下角。This function returns
true
if the given start position is a downwards diagonal (as drawn in your picture, advancing left-to-right) of lengths
full of characterc
.With a small change you can test for the upwards diagonal. And in an
NxN
board there can only be starts-of-diagonal in a(N-s+1)x(N-s+1)
area at the top-left and bottom-corners.另一个...
Another one...
您可以使用
IntStream
检查对角线是否只有'*'
:You can use
IntStream
to check if the diagonals have only'*'
: