ボードは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;
}