板子是int[][]
,我想找到这个形状
1
1
1
使用板上的所有 4 个对称(旋转)变体并记录位置。例如
...
...
... x x x x x x ...
... x x 1 1 x x ...
... x 1 x x x x ...
... x x x x x x ...
...
...
使用 F# 来处理这类问题会更好吗?
下面是我的 c# 代码,用于仅垂直检查模式(水平检查的代码类似)
List<Position> GetMatchVertical(int reelID)
{
List<Position> ret = new List<Position>();
var myReel = board[reelID];
var leftReel = reelID - 1 >= 0 ? board[reelID - 1] : null;
var rightReel = reelID + 1 < boardSize ? board[reelID + 1] : null;
int currentColor = myReel[0];
for (int reelPosition = 1; reelPosition < boardSize; reelPosition++)
{
int nextColor = myReel[reelPosition];
if (currentColor == nextColor)
{
if (leftReel!=null)
{
if (reelPosition + 1 < boardSize && leftReel[reelPosition + 1] == currentColor)
{
ret.Add(logPosition(...));
}
}
if (rightReel!=null)
{
if (reelPosition - 2 >= 0 && rightReel[reelPosition - 2] == currentColor)
{
ret.Add(logPosition(...));
}
}
}
else
{
currentColor = nextColor;
}
}
return ret;
}