public bool CanPlay(Piece piece) { if (IsOutOfBounds(piece.Position) || IsOccupied(piece.Position)) { return false; } return CapturesOpponentPiecesInAnyDirection(piece); }
public void Play(Piece piece) { if (!CanPlay(piece)) { throw new InvalidOperationException($"Invalid move for {piece}"); } pieces.Add(piece); foreach (var direction in Direction.All()) { var line = new PiecesInLine(this, piece, direction); line.FlipOpponents(); } }
public PiecesInLine(Board board, Piece piece, Direction direction) { this.board = board; this.piece = piece; this.direction = direction; }
private bool CapturesOpponentPiecesInAnyDirection(Piece piece) { return Direction.All() .Any(direction => new PiecesInLine(this, piece, direction).CapturesOpponentPieces()); }
private Piece GetNextPiece(Piece thisPiece) { return board.GetPiece(direction.AwayFrom(thisPiece.Position)); }