- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个枚举,代表迷宫中某个单元格的当前状态,如下所示:
[Flags]
public enum CellInfo : ushort
{
None = 0,
NorthWall = 1,
EastWall = 2,
SouthWall = 4,
WestWall = 8,
AllWalls = NorthWall | EastWall | SouthWall | WestWall
}
有了它,我可以很容易地跟踪每个单元格墙壁的当前状态,例如,如果我想打开东面的墙壁。
var myCell = CellInfo.AllWalls; // initialise a cell with all walls up
myCell ^= CellInfo.EastWall; // east wall now down!
简单!但是,每个单元格都紧挨着另一个单元格,它有自己的墙,所以实际上我总是知道我正在从单元格 a
移动。到细胞 b
,并且为了争论起见,可以说这是向东的运动,我需要拆除 a
的东墙和 b
的西墙:
var a = CellInfo.AllWalls;
var b = CellInfo.AllWalls;
// assume a->b is eastwards
a ^= CellInfo.EastWall;
b ^= CellInfo.WestWall;
现在,我有一个通用的方法来处理这个移动,但是我不喜欢它,它有代码味!太多if
语句,我想知道我是否错过了一些明显的东西 - 一些我可能没有发现的按位逻辑?我已经粘贴了我的 KnockDownWall
下面的方法,它采用单元格网格 ( CellInfo[,]
) 以及 a
的网格位置和 b
表示为Tuple<int,int>
(x,y 位置)
protected static void KnockDownWall(CellInfo[,] cells, Tuple<int, int> target, Tuple<int, int> neighbour)
{
var offsetTarget = Tuple.Create(neighbour.Item1 - target.Item1, neighbour.Item2 - target.Item2);
if(offsetTarget.Item1 == 0)
{
if(offsetTarget.Item2 == -1)
{
cells[target.Item1, target.Item2] ^= CellInfo.NorthWall;
cells[neighbour.Item1, neighbour.Item2] ^= CellInfo.SouthWall;
}
else
{
cells[target.Item1, target.Item2] ^= CellInfo.SouthWall;
cells[neighbour.Item1, neighbour.Item2] ^= CellInfo.NorthWall;
}
}
else
{
if (offsetTarget.Item1 == -1)
{
cells[target.Item1, target.Item2] ^= CellInfo.WestWall;
cells[neighbour.Item1, neighbour.Item2] ^= CellInfo.EastWall;
}
else
{
cells[target.Item1, target.Item2] ^= CellInfo.EastWall;
cells[neighbour.Item1, neighbour.Item2] ^= CellInfo.WestWall;
}
}
}
更新
到目前为止,答案中有大量有用的信息 - 但我担心我一开始就把问题简单化了。 CellInfo
有更多的值存储诸如 N/S/E/W 边界(允许我自由塑造迷宫和围栏区域)、N/S/E/W 解决方案和回溯信息之类的东西——这些都输入到模型中绘制迷宫。将一切都视为细胞而不是墙壁有一些好处。
最佳答案
您对迷宫进行建模的方法存在的问题是每个内墙都被表示两次,需要付出大量努力才能保持内部一致性。更好的方法是通过在南侧额外增加一排并在东侧增加一列来扩展迷宫,并使用两种墙类型而不是四种 - 即单元格北侧的墙和单元东侧的墙:
这张图片显示了一个 2 行 3 列的网格,扩展为 3 行 4 列。红线表示要拆除的墙壁。
为了处理来自特定单元格的所有四个方向的墙壁,制定一种将南墙和西墙识别为相邻单元格的北墙和东墙的方法。
最后,您可以制作两个 bool
的二维数组 - 一个代表水平墙,一个代表垂直墙。这样,各个单元根本就不必存储自己的墙,迷宫将始终保持内部一致:
private const int rows = 10;
private const int cols = 15;
private bool northWalls[,] = new bool[rows+1, cols+1];
private bool westWalls[,] = new bool[rows+1, cols+1];
public bool HasWall(int cellRow, int cellCol, CellInfo dir) {
switch(dir) {
case CellInfo.NorthWall:
return northWalls[cellRow,cellCol];
case CellInfo.WestWall:
return westWalls[cellRow,cellCol];
case CellInfo.EasthWall:
return westWalls[cellRow,cellCol+1];
case CellInfo.SouthhWall:
return northWalls[cellRow+1,cellCol];
}
}
如果您必须使用当前设计,但又想摆脱 KnockDownWall
中的条件,您可以制作两个 3×3 数组,其值为 CellInfo.XyzWall
来自你的实现,并用 offsetTarget.Item1+1, offsetTarget.Item2+1
索引它们:
protected static void KnockDownWall(CellInfo[,] cells, Tuple<int, int> target, Tuple<int, int> neighbour) {
var offsetTarget = Tuple.Create(neighbour.Item1 - target.Item1, neighbour.Item2 - target.Item2);
cells[target.Item1, target.Item2] ^= targetLookup[offsetTarget.Item1+1, offsetTarget.Item2+1];
cells[neighbour.Item1, neighbour.Item2] ^= neighborLookup[offsetTarget.Item1+1, offsetTarget.Item2+1];
}
关于c# - 迷宫墙上的按位逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326141/
我想在 Facebook 墙上(标准 friend /群组的墙上)而不是应用程序上发布消息。使用delphi,我可以登录,但我不知道如何在上面发布消息。有什么建议吗? 最佳答案 我从未使用过 Delp
我的网站上出现了一个奇怪的问题。我做了 facebook 开发者网站所说的完全相同的方式,但仍然遇到同样的问题。问题是,当我在我的网站上单击“喜欢”按钮时,弹出窗口和计数绝对正常,但故事不会在 fac
我正在使用为 facebook 提供的 facebook android sdk 我正在使用他们提供的简单示例并且它的工作非常好,现在在 fb 中登录时显示来自 fb 的表单以在单击按钮时张贴在墙上。
使用此 Tutorail 我成功登录到 Facebook http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-ph
我有一个视频博客网站,您可以在其中喜欢视频。问题是,如果你点击类似 Facebook 的按钮,就会弹出正确的标题、描述和照片。当您提交要在 Facebook 墙上发布的消息后,描述就会消失。 我将 O
(这个真的和这个问题一样,只是给出的答案不相关 add image and description on facebook with sharekit) 如何使用 ShareKit 发送图像链接,以便
我获得了 access_token(具有电子邮件、publish_stream 和 offline_access 权限)。 然后,我执行以下代码: var uri = 'https://graph.f
我有以下 JavaScript 代码来发布/张贴消息到 friend 的墙上,因为此代码仅发布到一个 friend 的墙上。我想做的是,将一条消息发布/发布到多个 friend 的墙上。请提供任何帮助
我已经检查了 API,但它允许发布 URL 而不是图像? 最佳答案 据我在互联网上了解到的信息,Google+ API ( https://developers.google.com/+/mobile
我正在通过 fbgraph API 发布指向我的 fb 帐户的链接。问题是,当我发布指向 fb 的链接时,该链接的左侧会出现一个图标,例如,如果我发布 www.google.com,则 google
所以我想知道,有没有一种方法可以使用 Facebook iOS SDK 在没有 appId 的情况下发布到用户的 Facebook 墙上? 我希望显示一个模态窗口,用户可以输入消息,但我们不希望用户授
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Posting to a wall of a facebook user using the graph api 如
我正在制作一个 iPhone 应用程序,用户希望通过单击一个按钮将所选图像发布到 facebook 墙上。 我有 Actionsheet 按钮。 我希望用户身份验证(loginButtonTapped
我正在尝试将帖子从我的应用程序中集成到墙上。我已经有一个用户可以保存他/她的用户名和密码(加密)的区域。我希望我的程序调用保存的用户名和密码,将其传递给 Facebook 进行身份验证,然后允许应用程
Facebook API 似乎只允许文本、图像、视频和 flash 嵌入通过 API 发布到用户的墙上,但 Spotify 以某种方式发布了这些带有播放按钮、图像等的复杂播放列表。 他们是怎么做到的?
我已经创建了一个应用程序,现在我想使用新的图形 API 在我的 friend 墙上发布一条消息。这可行吗? 我已经在使用 oAuth 和 Graph-api 来获取我所有 friend 的列表。API
我在网上搜索了很多,但我没有找到通过图形 API 在 friend 墙上发帖的工作方式。 我想通过应用程序在 friend 墙上发布消息。 最佳答案 第一次获取好友获取好友列表 [_facebook
我有一个已注册为 Facebook 应用程序的网站 - 我现在有一个应用程序 ID。 我的网站是 ASP.net C#。当用户单击一个按钮时,我希望它将预定义的消息发布到他们的墙上。我期待 Faceb
我的 iOS 应用程序允许人们使用 Facebook 登录,并自动检查您的哪些 friend 当前注册为使用该应用程序。当前未使用该应用程序的所有 friend 都在“邀请”列表中,这与 DrawSo
我已经尝试了很多时间来解决这个问题,但仍然不起作用。 NSString *full = [[NSBundle mainBundle] pathForResource:@"200" ofType:@"p
我是一名优秀的程序员,十分优秀!