Sliding pieces moves are now illegal if after piece of same color
This commit is contained in:
@@ -145,38 +145,11 @@ public class Board: CustomStringConvertible, EventDelegate {
|
||||
}
|
||||
|
||||
public func move(src: String, dst: String) throws {
|
||||
guard src.count < 3 else {
|
||||
throw MoveFailure.squareANIsTooLong(an: src)
|
||||
if let from = try Square.Position(with: src),
|
||||
let to = try Square.Position(with: dst)
|
||||
{
|
||||
try move(src: from, dst: to)
|
||||
}
|
||||
guard src.count > 1 else {
|
||||
throw MoveFailure.squareANIsTooShort(an: src)
|
||||
}
|
||||
guard dst.count < 3 else {
|
||||
throw MoveFailure.squareANIsTooLong(an: dst)
|
||||
}
|
||||
guard dst.count > 1 else {
|
||||
throw MoveFailure.squareANIsTooShort(an: dst)
|
||||
}
|
||||
guard let f1 = src.first, let r1 = src.last, r1.isWholeNumber else {
|
||||
return
|
||||
}
|
||||
guard let f2 = dst.first, let r2 = dst.last, r2.isWholeNumber else {
|
||||
return
|
||||
}
|
||||
guard
|
||||
let srcFile = Square.Position.File.init(rawValue: String(f1))?.value
|
||||
else {
|
||||
return
|
||||
}
|
||||
guard
|
||||
let dstFile = Square.Position.File.init(rawValue: String(f2))?.value
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
try move(
|
||||
src: Square.Position(rank: Int8(String(r1))!, file: srcFile),
|
||||
dst: Square.Position(rank: Int8(String(r2))!, file: dstFile))
|
||||
}
|
||||
|
||||
public func move(src: Square.Position, dst: Square.Position) throws {
|
||||
|
||||
Reference in New Issue
Block a user