我正在使用二维数组来表示单元格网格。当边缘或 Angular 落的细胞检查到它的邻居将越界时,它会将它们视为永久死亡。
function getCell(row, column) {
if(row === -1 || row === cellMatrix.length || column === -1 || column === cellMatrix[0].length)
{
return 0;
}
else return cellMatrixCopy[row][column];
}
我只是想摆脱滑翔机在到达网格边缘时停止并变成 block 的行为。您将如何“去除”阵列的边缘?
您可以查看完整的实现 here .提前致谢。
最佳答案
How to fake an “infinite” 2d plane?
要创建无限维游戏板,请使用稀疏矩阵表示,其中行和列索引是任意精度整数。大致如下:
map<pair<BigInt,BigInt>, Cell> matrix;
Cell& get_cell(BigInt x, BigInt y)
{
return matrix[make_pair[x,y]];
}
关于javascript - 康威的生命游戏 - 如何伪造一个 "infinite"二维平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18564055/