jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Fri Oct 26, 2012 7:56 pm Post subject: Client-Server game of TicTacToe? |
|
|
Best way to realize two player Client-Server game of TicTacToe using FTN95, ClearWin+ and .NET?
I have written this game before for Inferno using Limbo programming language. It was quite easy task because of lightweight threads (procs), blocking channels for thread synchronization + communication and filesystem interface for network sockets.
Available here, if someone is interested
For FTN95-version of a game I thought about using .NET framework for threading and socket connection handling.
For server, I guess I will be using three threads:
UI_thread:
Handles user interaction. Starts the Listen_thread (don't want to block the UI_thread).
Listen_thread:
Listens and accept opponents connection. Starts the Worker_thread and then goes away.
Worker_thread:
Handles opponents connection, moves and messages.
For player turn and thread synchronization, I thought about using just a variable:
Lets name the variable: lambda
Lambda can have values: '1' or '-1'.
'1' means local players turn and '-1' means opponents turn. If we mark the local players pieces on the game board with '1' and opponents pieces with '-1', then we can test if a game piece on the board belongs to the current player or for the opponent by just multiplying piece value by lambda. Positive value means current player and negative value means opponent. So, no need for separate testing functions for each player.
Since lamba variable needs to be accessed from the two different threads: UI_thread and Worker_thread, is it enough just to use LOCK when writing to a variable or do I need more sophisticated locking? |
|