private void FlipAt(bool black, Direction direction, int x, int y) { var dir = DirectionHelper.DirectionToPoint(direction); var targetX = x; var targetY = y; var changes = new List <Point>(); do { ApplyMovement(dir, ref targetX, ref targetY); if (!OnBoard(targetX, targetY) || _game.GetTileAt(targetX, targetY) == Tile.None) { return; } if (IsFriendColor(black, targetX, targetY)) { if (changes.Count > 0) { break; } return; } if (IsEnemyColor(black, targetX, targetY)) { changes.Add(new Point(targetX, targetY)); } } while (true); foreach (var point in changes) { _game.SetTileAt(point.X, point.Y, black ? Tile.Black : Tile.White); } }
private bool HasNeighbours(int x, int y) => Enum.GetValues( typeof(Direction)) .Cast <Direction>() .Any(direction => IsSet(x, y, DirectionHelper.DirectionToPoint(direction)) );