I am wanting to create a chess engine. I am most familiar with Swift, and super high-performance isn't all that important to me (otherwise I'd likely learn and write it in C++). I need my engine to take in a chess position in an FEN formatted string, which would look something like this: rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2
. It would then process the position and spit out a move in algebraic notation, like Nxd4
.
These specifics aren't all that important, however, as I can program all of this in Swift. What I am wondering is how one would create an API with swift to do this. That is, the url encoded FEN position is passed a parameter to the API like so: https://www.mywebsite.com/chessEngine?position=rnbqkbnr%2Fpp1ppppp%2F8%2F2p5%2F4P3%2F5N2%2FPPPP1PPP%2FRNBQKB1R%20b%20KQkq%20-%201%202
The Swift code would then process this position on the backend, and the response would be something like:
{status:"success",recommendedMove:"Nxd4",moveTime:"12.34"}
Is it even possible to have Swift code process on the back end? My API development experience is limited to taking parameters as url parameters, making an SQL query, and then echoing the query response as a JSON.
Yes, it is possible. Although I haven't built a full site/API with Swift, I know that Vapor uses itself to host its website, and my (albeit limited) experience with it suggests that it would be a good pick. That said, you could also use Kitura or Perfect — try looking up a comparison between them.
Good luck!