private void AddNormalMovesFrom(List <PossibleMove> possibleMoves, Square from, Direction dir) { if (!from.TryGetBorder(dir, out var next)) { return; } if (next.Color == _currentTurn.Other) { var jump = next.GetBorder(dir); if (jump is null || jump.IsNotEmpty || !CanCaptureInDirection(dir, from)) { return; } int chainLength = NormalChainLength(from, jump, next); if (chainLength > _minCaptureSequence) { _minCaptureSequence = chainLength; possibleMoves.Clear(); } if (chainLength >= _minCaptureSequence) { possibleMoves.Add(PossibleMove.CaptureMove(from, jump, next, chainLength > 1)); } return; } if (next.IsEmpty && !MustCapture && CanMoveInDirection(dir, from)) { possibleMoves.Add(PossibleMove.NormalMove(from, next)); } }
private void AddFlyingMovesFrom(List <PossibleMove> possibleMoves, Square from, Direction dir) { Square?victim = null; for (var next = from.GetBorder(dir); next is not null; next = next.GetBorder(dir)) { if (next.IsEmpty && victim is not null) { int chainLength = FlyingChainLength(from, next, victim); if (chainLength > _minCaptureSequence) { _minCaptureSequence = chainLength; possibleMoves.Clear(); } if (chainLength >= _minCaptureSequence) { possibleMoves.Add(PossibleMove.CaptureMove(from, next, victim, chainLength > 1)); } continue; } if (next.Color == _currentTurn.Other && victim is null) { var jump = next.GetBorder(dir); if (jump is null || jump.IsNotEmpty) { return; } victim = next; continue; } if (next.IsEmpty) { if (!MustCapture) { possibleMoves.Add(PossibleMove.NormalMove(from, next)); } continue; } return; } }