检查二维数组中某个索引周围索引的最佳方法
我正在研究我必须制作的细菌生命游戏。
基本上我有一个 2d 字符串数组,比如说 20 x 20。
检查某个索引周围的所有 8 个点的最佳方法是什么。每个索引都应该代表一种细菌。对于每个细菌(索引),我必须检查该索引周围的 8 个点中是否有另一个细菌,如果索引中有细菌,则仅用“*”星号表示。
检查每个索引周围的所有 8 个点的最佳方法是什么,因为根据某个索引周围的索引中的内容,我必须做出某些更改等。
我想到的唯一想法是有一堆if 语句检查所有 8 个位置,我想知道是否有更好的方法来执行此
操作,例如: 第 1 行 - www ,第 2 行 = wOw ,第 3 行 - www ,
如果我位于 O 索引,那么检查某个字符串周围的所有索引点的最佳方法是什么。
抱歉,我不太擅长解释我的问题,英语不好:o。
感谢您的帮助。
I'm working on this bacteria life game thing I have to make.
Basically I have a 2d string array let's say 20 by 20.
What would be the best way to check all 8 spots around a certain index. Each index is suppose to represent a bacteria. For each bacteria(index) I have to check to see if any of the 8 spots around this index has another bacteria in it, if the index has a bacteria in it, it's represented simply by a "*", asterik.
What would be the best way to go about checking all 8 spots around each index, because based on what is in the indices around a certain index I have to make certain changes etc.
The only idea I have come up with is having a bunch of if statements to check all 8 spots, I was wondering if there is a better way to do this
ex:
row 1 - www , row 2 = wOw , row 3 - www ,
if I am at the O index, what would be the best way to check all the index spots around it for a certain string.
Sorry, I am not very good at explaining my problems, bad english :o.
thanks for any of the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以你有这样的东西
so you have something like this
以下是我过去完成此任务的方法:
Here is how I've accomplished this in the past: