Sliding pieces moves are now illegal if after piece of same color
This commit is contained in:
@@ -7,6 +7,7 @@ enum Command: Equatable {
|
||||
case move(from: String, to: String)
|
||||
case history(command: String? = nil)
|
||||
case highlightThreatened(color: Color)
|
||||
case highlightPositions(of: Square.Position)
|
||||
|
||||
init?(rawValue: String) {
|
||||
let args = rawValue.lowercased().split(separator: " ")
|
||||
@@ -28,16 +29,25 @@ enum Command: Equatable {
|
||||
case "history", "h":
|
||||
self = .history()
|
||||
case "highlight" where args.count == 2, "hi" where args.count == 2:
|
||||
let color: Color =
|
||||
let color: Color? =
|
||||
switch args[1] {
|
||||
case "w", "white":
|
||||
.White
|
||||
case "b", "black":
|
||||
.Black
|
||||
default:
|
||||
.White
|
||||
nil
|
||||
}
|
||||
self = .highlightThreatened(color: color)
|
||||
if let c = color {
|
||||
self = .highlightThreatened(color: c)
|
||||
return
|
||||
}
|
||||
|
||||
if let position = try? Square.Position(with: String(args[1])) {
|
||||
self = .highlightPositions(of: position)
|
||||
return
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -81,6 +91,14 @@ while command != .quit {
|
||||
print(ts.count)
|
||||
print(board.text(with: [color: Array(ts)]))
|
||||
}
|
||||
case .highlightPositions(let pos):
|
||||
if let square = board.getSquareInfo(on: pos),
|
||||
let piece =
|
||||
square.piece
|
||||
{
|
||||
let color = Board.TerminalColors(fg: .def, bg: .green)
|
||||
print(board.text(with: [color: piece.legalPositions]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user