游戏点数和数据结构 [英] Data structure for game Dots and Boxes
问题描述
表示游戏状态的好数据结构将是什么?点和框 ?我想出了使用2个布尔型的矩阵,对于水平和垂直线,但也许有一种更优雅的方法来做到这一点(操作: ,检查线,查询方块)
使用一对称为 linesX
和 linesY
的布尔二维数组对我有意义。每个阵列将在给定的X / Y方向上比板上的总平方格多一行/列。以下是使用该解决方案的 check square 的代码示例:
bool isSquareComplete(int x,int y ){
return linesX [x] [y]&& linesX [x + 1] [y]&& linesY [x] [y]&& linesY [x] [y + 1];
}
What would be a good data structure to represent the status of the game Dots and Boxes?
I came up with using 2 matrices of boolean, for horizontal and vertical lines, but maybe there's a more elegant way of doing this (and the operations: add line, check line, check square).
Using a pair of two-dimensional arrays of booleans called linesX
and linesY
makes sense to me. Each array would have one more row/column than the total number of squares on the board in that given X/Y direction. Here's a code sample of check square with that solution:
bool isSquareComplete(int x, int y) {
return linesX[x][y] && linesX[x + 1][y] && linesY[x][y] && linesY[x][y + 1];
}
这篇关于游戏点数和数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!