Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

What's a good Networking solution for a turn-based game?

Discussion in 'Multiplayer' started by aer0ace, Apr 22, 2016.

  1. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    I'm looking to add multiplayer to my game, and I've quickly skimmed over Photon Unity Networking (PUN) and Unity's native solution. I'll preface with saying, I have about an intermediate level experience with network game programming.

    What would some folks recommend using for a turn-based game?
    The only game I'm familiar with for multiplayer turn-based is Frozen Synapse, so that's sort of what I'm looking for. Basically, lobby/room/session asynchronous support, where turns are updated based on a glob of data downloaded, unpacked and played for the next turn.

    I like the idea that Photon has server and lobby support built in. However the Marco Polo solution that I saw provided a real-time solution that basically syncs positional data. This kind of indicates to me that data is just replicated, and it doesn't really have server authority. I'm used to having a server build independent of the client build, with shared codebases, but the server running headless.

    On the other hand, the Unity Networking tutorial that I saw provides a LAN solution, but doesn't immediately show anything like Photon's lobby and dedicated server features. I skimmed over this pretty fast, but I'm pretty sure that the LAN example is basically using one of the connected Unity clients as the game server, which isn't what I really want either.

    Any recommendations? Perhaps I'm not reading into the PUN and Unity Networking solutions deep enough to realize that either (or both) solution(s) are usable for my situation?

    Thanks in advance.
     
  2. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Well, no responses. I found more info on the Photon site, in that there is a Photon Turn-Based module(?), so I'll try that.

    I'm not sure what the difference is between Photon's API and PUN. It sounds like PUN provides a more Unity-friendly API, but also means it's another dependency to worry about. But it also looks like it's supported pretty well too.
     
  3. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    Some late thoughts from me then, if you havent yet decided.

    Proposing the best solution for your turn-based game depends on its style. Do the players play one after another, or all at the same time with only the actions being turn-based? The first type is very easy, simply buffer all actions like moving a unit or attacking one in a FILO list and send it to the other players who then execute those.
    If you are using a client-server and not peer-to-peer approach you should send each action seperately to let the server execute and check if its valid and no cheat attempt. If thats not the case, spread the packet out to all clients who then apply the actions as well.

    The second type of turn-based games would need a similar system but with a new feature that prevents two players colliding with performed actions (player 1 attacks player 2 unit which player 2 currently uses elsewhere, but doesnt recognize it because of a lag). This approach is called Lockstep (famous article) and does exactly what I described above (clients send actions to server, checks and sends it further to the other clients) but every peer delays the execution of the sent actions and their own in fixed time intervals. In these, every client awaits one single packet from the other players which contains all actions performed in this interval. This ensures synchronous gameplay. Contra would be that the clients need to pause the execution of the game if one peer is lagging and cannot send his update packet, because they would be out of sync otherwise.
     
  4. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    @SirNiklas I appreciate your response. But, I suppose I seem to have left my question pretty open-ended. I was more looking for answers regarding the differences between UNET, Photon and/or PUN, or if there are any other packages that I should be looking at. When I was doing my initial research, most of the documentation covered mainly real-time games. It wasn't until I discovered Photon Turn-based that I had an idea of how these packages operate. It's a little concerning that Photon is client-authoritative, but I'm not going to worry about it, since Photon provides servers to house the data, at a free/cheap cost. I do see that Photon also provides dedicated server packages, but I'm pretty sure they're much pricier, but that is definitely a solution if I truly wanted server-side authority.

    As for UNET, I haven't researched much further, as it really didn't look like it provided much beyond LAN capabilities. If I'm wrong, I'd like to know how a UNET solution would work for online games. i.e., what server solutions are available, and what are the steps to integrating those servers with UNET?

    It just seems like Photon/PUN is a more all-in-one solution, and it seems to be a great alternative, despite the lack of control you get when using their servers. I'll accept using data replication as opposed to full client-server authoring.

    And as far as turn-based game mechanics go, I know I mentioned Frozen Synapse as my only experience, and that wasn't quite true. I just have the most experience playing with it. I have had some play experience with XCOM, and that is more along the lines I'm talking about. It's a typical tactical turn-based game, and not really the "simultaneous turn-based" that Frozen Synapse is known for.
     
  5. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    Good that you specified it now, because I can only show you the theoretical approach. I never worked with Photon or UNet.

    If you really want to have everything ready for you, without implementing the networking on your own it just depends on the type of hosting in my opinion. UNet leaves it open to you how deep you want to dive into network programming. Photon is resembling the old Unity multiplayer API which might make it easier for certain people to understand it.