游戏点数和数据结构 [英] Data structure for game Dots and Boxes

查看:112
本文介绍了游戏点数和数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表示游戏状态的好数据结构将是什么?点和框 ?我想出了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆