Added history — though still need to be checked thoroughly
This commit is contained in:
@@ -53,7 +53,7 @@ public enum Kind: String, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
public class Piece {
|
||||
public class Piece: Hashable {
|
||||
#warning("TODO: To be removed, handle everything through the delegate")
|
||||
internal weak var board: Board?
|
||||
public internal(set) var color: Color
|
||||
@@ -94,6 +94,7 @@ public class Piece {
|
||||
}
|
||||
|
||||
}
|
||||
delegate?.addPieceToTarget(self, target: pos)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -102,4 +103,30 @@ public class Piece {
|
||||
self.position = pos
|
||||
self.color = col
|
||||
}
|
||||
|
||||
/// Two pieces are equal when they share the same kind, color and position
|
||||
public static func == (lhs: Piece, rhs: Piece) -> Bool {
|
||||
return lhs.kind == rhs.kind && lhs.color == rhs.color
|
||||
&& lhs.position == rhs.position
|
||||
}
|
||||
|
||||
/// Two pieces are not equal when they either do not share the same kind,
|
||||
/// color or position
|
||||
public static func != (lhs: Piece, rhs: Piece) -> Bool {
|
||||
return !(lhs == rhs)
|
||||
}
|
||||
|
||||
/// Checks if tho pieces are similar yet not equal.
|
||||
/// They are considered simmilar if they share the same color and the same kind,
|
||||
/// but differ in position.
|
||||
public static func ~= (lhs: Piece, rhs: Piece) -> Bool {
|
||||
return lhs.kind == rhs.kind && lhs.color == rhs.color
|
||||
&& lhs.position != rhs.position
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(kind)
|
||||
hasher.combine(position)
|
||||
hasher.combine(color)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user