[Standards-JIG] proto-JEP: Chess Game Protocol

Richard Dobson richard at dobson-i.net
Thu Aug 24 16:15:35 CDT 2006


> That seems to me a little bit over-complicated. First create a session -
> why? Why not just ask "Would you play chess?" - could you put chess into
> other layer than turn-based layer?

It shouldnt need to be complicated, its just creating a protocol where 
you can reuse as much of the protocol as possible in other scenarios 
without needing to change a thing.

> And even with this protocol, you can do the reuse quite well. One friend
> of mine said he will take the code once finished and modify it to
> tic-tac-toe. He said he will need only to replace the rule checker,
> slightly modify the game board and the "send move" function.
> 
> You can have layers in the implementation and not have them visible in
> the protocol. Could you please demonstrate how would you do the layers?

Sure here you go:

1) Invitation to start a game, similar to jingle this contains a 
description element for the game in question, if a client does not 
understand the game detailed it will reply with an unsupported error.

<iq type='set'
     from='romeo at montague.net'
     to='juliet at capulet.com'
     id='invite1'>
   <invite xmlns='http://www.xmpp.org/protocol/gamesession' 
sid='a73sjjvkla37jfea'>
     <description xmlns='http://www.xmpp.org/protocol/chess'>
       <color>any</color>
       <timelimit mins='10'/>
     </description>
   </invite>
</iq>

2) other user accepts

<iq type='result'
     from='juliet at capulet.com'
     to='romeo at montague.net'
     id='invite1'>
   <accept xmlns='http://www.xmpp.org/protocol/gamesession' 
sid='a73sjjvkla37jfea'>
     <description xmlns='http://www.xmpp.org/protocol/chess'>
       <color>white</color>
       <timelimit mins='10'/>
     </description>
   </accept>
</iq>

3) user says they are ready to start

<iq type='set'
     from='romeo at montague.net'
     to='juliet at capulet.com'
     id='ready1'>
   <ready xmlns='http://www.xmpp.org/protocol/gamesession' 
sid='a73sjjvkla37jfea'/>
</iq>

4) other user acknowledges (once all users have ready status the game 
automatically starts)

<iq type='set'
     from='juliet at capulet.com'
     to='romeo at montague.net'
     id='ready1'/>

5) user has their turn (the nextjid attribute details whos turn it is 
next, useful in games that have more than two players)

<iq type='set'
     from='romeo at montague.net'
     to='juliet at capulet.com'
     id='ready1'>
   <turn xmlns='http://www.xmpp.org/protocol/gamesession' 
sid='a73sjjvkla37jfea' nextjid='juliet at capulet.com'>
     <move xmlns='http://www.xmpp.org/protocol/chess' from='b4' to='b5'/>
   </turn>
</iq>

6) user wishes to leave the game, depending on the game this could lead 
to termination if you are the only other person left.

<iq type='set'
     from='romeo at montague.net'
     to='juliet at capulet.com'
     id='invite1'>
   <leave xmlns='http://www.xmpp.org/protocol/gamesession' 
sid='a73sjjvkla37jfea'/>
</iq>

Using the protocol detailed above the vast majority of the protocol 
stays the same, as does the implementation, the only extra bits that are 
needed are payload items in the invite, accept and turn elements, this 
makes game protocol development far quicker as it allows them to build 
on existing building blocks and also allows implementation to be very 
easy and quick for new games, the basics of this protocol should work 
for pretty much any turn based game, the only things that need adding 
are what happens when you join an already existing game, i.e. 
transmitting to new people who the other people in the game are so they 
can transmit their turns etc to them all.

Richard




More information about the Standards-JIG mailing list