SteveBarnegren / SwiftChess

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

Multi player #7

Closed rasIOS closed 6 years ago

rasIOS commented 6 years ago

Hi How can we code multi player for this game? (Two Phones).

SteveBarnegren commented 6 years ago

Hey @rasIOS

There's two approaches to this. The first is to send the move that you make to the other phone, and keep updating the boards to keep them in sync.

The other way that you can achieve this is to package up the whole game state and send it to the other phone. Have a look at the persistence section of the readme which shows you how you can convert a game to and from a dictionary. You could then serialise this to Json and send it to the other device. The other device can then recreate the whole game state by initialising a new game with that dictionary.

There's no networking included in SwiftChess, but you should be able to send data between players using something like GameKit.