Support our Sponsors:

Go Back   Touch Arcade > Developer Discussion > Public Game Developers Forum

Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2013, 08:25 AM
ricky.ngk ricky.ngk is offline
Junior Member
iPad 2, iOS 5.x
 
Join Date: Jun 2012
Location: SaiGon
Posts: 12
Send a message via MSN to ricky.ngk Send a message via Skype™ to ricky.ngk
Default Idea for online multiplayer turn-based game with UDP

Dear,

Online multiplayer turn-based game mentioned in this case is like chess, caro (gomoku), Othello online game. Each player makes a move in his turn, submit to host, and wait for other players turn.

Desired criteria:
+ Target: mobile
+ Simple, design for max 4 players per game
+ Keep server in low cost (CPU, bandwidth, transfer rate)
+ Available auto-reconnect if any

So I decide to use UDP. Server works like client discovery and message delivery at all. There’re two problems need to solve:
+ Package transmission mechanism: use UDP punch hole http://www.brynosaurus.com/pub/net/p2pnat/
+ Turn-based mechanism

For turn-based controlling, I have an idea as following:
+ Suppose that a host places two roles: host and client too
+ Client works in 3 states: LOCK (not in turn), INPUT (in turn), and SYNC (submit data to server), with two important properties: seq (sequence index), and turnIndex (turn index of each client)

Host work flow:
Code:
seqNo = 0
userInTurn = 0
while (true)
    if receive_submit() then
        seqNo = seqNo  + 1
        userInTurn = get_next_turn()
    end
    update_game_logic()
    deliver_to_all_clients(seqNo, userInTurn, gamedata)
end
Client work flow:
Code:
seqNo = -1
function On_Receive_Data_Update(ServerSeqNo, currentTurnIndex, gamedata)
    if ServerSeqNo >= seqNo then -- valid seq
        if ServerSeqNo > seqNo -- change state
            if state is LOCK then
                if currentTurnIndex == turnIndex then
                    switch_to_state(INPUT)
                end
            elseif state is INPUT then
                if currentTurnIndex != turnIndex then
                    switch_to_state(LOCK)
                end
           else
                if currentTurnIndex == turnIndex then
                    switch_to_state(INPUT)
                else
                    switch_to_state(LOCK)
                end
           end
        end
 
        update_game_with_data(gamedata)
    end
end
 
function update_client_control()
    if state is INPUT then
       update_game_input()
       if hasEndTurn() then submit() end
    end
end
Please see full post with figure at http://www.guava7.com/2013/online-mu...game-with-udp/

This is only a theoretically mechanism. Point me out if I make any mistake . Thank you in advance!
Reply With Quote
  #2  
Old 03-03-2013, 07:10 AM
MarkFromBitmenStudios's Avatar
MarkFromBitmenStudios MarkFromBitmenStudios is offline
Developer
iPad (4th Gen), iOS 6.x
 
Join Date: Apr 2011
Location: Austria, Europe
Posts: 130
Send a message via AIM to MarkFromBitmenStudios
Default

Apple's GameCenter has support for turn based games out of the box. This may save you a lot of effort. In any case, I don't see the point of using UDP here but I don't think anybody here will go to a technical level explaining stuff.
Reply With Quote
  #3  
Old 03-04-2013, 12:16 AM
MHille's Avatar
MHille MHille is offline
Developer
iPhone 5s, iOS 7.x
 
Join Date: Oct 2011
Location: Melbourne
Posts: 55
Default KISS keep it simple you know what

Apple's turn based API also means you don't have to provide servers.

UDP might look inviting for this but by the time you finish your implementation you will have created a connection based protocol. So in the long run it's more work than any other method.

Matthew
Reply With Quote
  #4  
Old 03-17-2013, 12:54 PM
ricky.ngk ricky.ngk is offline
Junior Member
iPad 2, iOS 5.x
 
Join Date: Jun 2012
Location: SaiGon
Posts: 12
Send a message via MSN to ricky.ngk Send a message via Skype™ to ricky.ngk
Default

Apple API in this case is a good point, I'm learning to use it. But it's not cross-platform
Reply With Quote
  #5  
Old 03-17-2013, 04:34 PM
Hercule's Avatar
Hercule Hercule is offline
Senior Member
 
Join Date: Dec 2010
Posts: 240
Default

If you want a cross-platform solution:

You can loose packets in UDP.
You can ask why all game use UDP intead of TCP ? TCP is a lot more reliable than UDP.

UDP has better performance, put lack of reliability like TCP.
In video game they just do two types of UDP connexion:
- Simple UDP where information can be lost (not sensitive information for the player like statistics or are re-send often like his position )
- Enchanced UDP where they build a mecanism to increase reliability on top of it.
(they try to have almost the same reliability than TCP but with better performance)

Doing your own enchanced UDP will take you several weeks.
For a turn by turn game you should choose probably TCP. It's not an FPS and you don't need high performance. It will be a lot simpler to do, and reliable for your players with bad connections.

On games (xbox360/PC/PS3) I've worked on, I've used Raknet to do everything low level related (punch through, udp reliable etc..). I don't know how much it can cost.

Another advice:
You can also use a master server to create game and help a client to connect to each other, but after that you could use one of the client as a server.
Like that you can scale much more. Most recent game (even AAA FPS) do this.
But it's more complicate, and you can implement it later.
Reply With Quote
  #6  
Old 03-17-2013, 11:46 PM
TheBunny TheBunny is offline
Senior Member
 
Join Date: Nov 2008
Location: Baltimore
Posts: 204
Default

You could probably just use enet

Well proven game networking lib, runs on all platforms.
Does TCP and UDP + data protocol on top...

http://enet.bespin.org
Reply With Quote
  #7  
Old 03-18-2013, 12:06 AM
ricky.ngk ricky.ngk is offline
Junior Member
iPad 2, iOS 5.x
 
Join Date: Jun 2012
Location: SaiGon
Posts: 12
Send a message via MSN to ricky.ngk Send a message via Skype™ to ricky.ngk
Default

Thank @Hercule, a lot of things to do with UDP, I'll take account, and do a testbed for some scenarios, maybe UDP for discovery & TCP for p2p connection in game
@TheBunny: thank for share, I' cloning https://github.com/lsalzman/enet , hope I could understand source code quickly
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Copyright 2012, TouchArcade.com, LLC.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Copyright ©2008 - 2011, TouchArcade.com. Privacy Policy / DMCA Copyright Agent