Make cell values binary

This commit is contained in:
Andrew Cooper
2022-09-02 08:40:46 +10:00
parent b156755ee0
commit 28736b9dbe
2 changed files with 12 additions and 13 deletions

View File

@@ -2,10 +2,8 @@ namespace LifeforTwo;
internal class Board
{
private const int Player1Piece = 100;
private const int Player2Piece = 1000;
private const int Player1Neighbour = 1;
private const int Player2Neighbour = 10;
private const int PieceMask = 0x1100;
private const int NeighbourValueOffset = 8;
private readonly int[,] _cells = new int[7,7];
public int this[Coordinates coordinates]
@@ -27,12 +25,12 @@ internal class Board
for (var y = 1; y <= 5; y++)
{
var coordinates = new Coordinates(x, y);
if (this[coordinates] >= Player1Piece)
var neighbourValue = (this[coordinates] & PieceMask) >> NeighbourValueOffset;
if (neighbourValue > 0)
{
int _playerPiece = this[coordinates] > Player2Piece ? Player2Neighbour : Player1Neighbour;
foreach (var neighbour in coordinates.GetNeighbors())
{
this[neighbour] += _playerPiece;
this[neighbour] += neighbourValue;
}
}
}