SteveBarnegren / SwiftChess

Chess engine and AI written in Swift
MIT License
145 stars 35 forks source link

add legal moves? #18

Closed museum-future closed 4 years ago

museum-future commented 4 years ago

Is there a painless way to display a green circle on the board to show legal moves once a piece is touched?

ghost commented 4 years ago

@museum-future you can use my library to take a list of legal moves in given position: https://github.com/perechnev/ChessKit

SteveBarnegren commented 4 years ago

Hi @museum-future

Yes, there is a method on Board called possibleMoveLocationsForPiece(atLocation:) which returns an array of BoardLocations.

Here is a code snippet from my own chess game:

if let selectedIndex = selectedIndex {
  let selectedLocation = BoardLocation(index: selectedIndex)
  boardView.possibleMovesView.locations = game.board.possibleMoveLocationsForPiece(atLocation: selectedLocation)
}

Hope that helps!