mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Make cell values binary
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user