db.define_table('rooms',
Field('Player_count','integer',default=0),
Field('P1_id','integer',default=0),
Field('P1_name','string',default=""),
Field('P2_id','integer',default=0),
Field('P2_name','string',default=""),
Field('TS1','integer',default=0), #Tack 1 state
Field('TS2','integer',default=0),
Field('TS3','integer',default=0),
Field('TS4','integer',default=0),
Field('TS5','integer',default=0),
Field('TS6','integer',default=0),
Field('TS7','integer',default=0),
Field('TS8','integer',default=0),
Field('TS9','integer',default=0),
Field('New_tac',default=10),
Field('P_turn','integer',default=0),
Field('Is_over','integer',default=0),
)
db.define_table('room_count',
Field('total','integer',default=0))
The database "rooms" contains the information:
1) number of players in the room
2) p1 id
3) p1 name
..
6) the valiue of the first position, taking that the 9 rock field is represented in the fashion
1 2 3
4 5 6
7 8 9
..
15) The position which was changed on the last move, so we wouldn't have to send all of the 9 variables to see which one changed
16) Which players turn is it now
17) Is the game over
The "room_count" database, just keeps score of how many rooms exist in the database at the moment. When it hits 10000 the databases are wiped and if you were playing in room 9999 at that time, I'm sorry, it's just a fail-safe :)
Game functions on the server
The server-side of the game consists of 4 main functions:
1) join_room(nickname);
2) check_for_player2(r_id,p_id);
3) set_your_tac(r_id,p_id,t_pos);
4) get_tac_info(r_id,p_id);
And 2 helper functions:
1) is_game_over(tack_list,player_number,new_tack)
2) tac_update(room_id,player_number,tack_position)
The function names probably describe them enough. And I'll go into more detail of the python code in a revision of the tutorial if requested. For now I'll leave it at that.
For cross-domain access every function has a:
response.headers["Access-Control-Allow-Origin"] = client_address
The "client address" variable is located in the top of the default.py file text, so you wouldn't have to rewrite the access header value in every function:
client_address='*' - means requests from any domain will be accepted.
If set it to an address like:
client_address='http://zerostatesociety.com' - requests will only accepted from this domain