Game of Life ArrayIndexOutofBounds

前端 未结 2 398
再見小時候
再見小時候 2021-01-27 07:32

I\'m doing the Conway\'s game of life. I\'m pretty sure I\'m close to finished, but when I run it, I get Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsExcep

2条回答
  •  再見小時候
    2021-01-27 07:47

    As I can see, you basically have two choices:

    1. apply finite bounds, that is, for the cells in the first and last columns and rows, you implement an additional check when counting the number of 'living' neighbours.

    2. apply periodic bounds, that is, the cells on the leftmost column and the cells on the rightmost column are considered as neighbours. With the help of modular arithmetic, these cells don't need to be handled separately from others.

提交回复
热议问题