Skip to content

Commit

Permalink
Make alignment methods return true for same square
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Aug 17, 2016
1 parent 1efc88a commit c7a1d0a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/Square.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,17 @@ extension Square {
/// Returns `true` if `self` is aligned with `first` and `second`.
public func isAligned(with first: Square, and second: Square) -> Bool {
return line(with: first)[second]
|| line(with: second)[first]
|| (self == first && self == second)
}

/// Returns `true` if `self` is aligned with `first` and `rest`.
public func isAligned(with first: Square, _ rest: Square...) -> Bool {
let line = self.line(with: first)
for square in rest {
var line = self == first ? Bitboard(square: self) : self.line(with: first)
for square in rest where square != self {
if line == Bitboard(square: self) {
line = self.line(with: square)
}
guard line[square] else {
return false
}
Expand Down

0 comments on commit c7a1d0a

Please sign in to comment.