You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,13 +39,7 @@ The only requirement is a regular Python installation.
39
39
40
40
### About this project
41
41
42
-
This server was developed for use in a university programming course, where students learn Python as their first programming language and work on projects in small groups. Both the framework and the API are designed so that the programming skills acquired during the first term are sufficient to implement new games and clients. However, the use of the server is not limited to educational scenarios.
43
-
44
-
## Operating the server
45
-
46
-
To run the server in a network, edit IP and port in the configuration file (`server/config.py`). TLS along with other settings can also be configured there. If you intend to run the server as a systemd service, you can use the provided unit file. Server and API are implemented in plain Python. Only modules from the standard library are used. This makes the server easy to handle.
47
-
48
-
Learn more in the [Wiki](https://github.com/feberts/python-game-server/wiki).
42
+
This server was developed for use in a programming course, where students learn Python as their first programming language and work on projects in small groups. Both the framework and the API are designed so that basic programming skills are sufficient to implement new games and clients. However, the use of the server is not limited to educational scenarios. Learn more in the [Wiki](https://github.com/feberts/python-game-server/wiki).
49
43
50
44
## Implementing clients
51
45
@@ -56,23 +50,27 @@ Module `game_server_api` provides an API for communicating with the server. It a
56
50
- retrieve the game state
57
51
- passively observe another player
58
52
- restart a game within the current session
59
-
- enable TLS
60
53
61
54
Here is a short demo of the API usage:
62
55
63
56
```py
64
-
from game_server_api import GameServerAPI
57
+
from game_server_api import GameServerAPI, IllegalMove
65
58
66
59
game = GameServerAPI(server='127.0.0.1', port=4711, game='TicTacToe', players=2,
67
60
session='mygame') # pass 'auto' to auto-join a session (default)
68
61
69
-
my_id = game.join() # start/join a session - each client is assigned an ID
70
-
game.move(position=5) # perform a move - the function accepts keyword arguments (**kwargs)
71
-
state = game.state() # returns a dictionary representing the game state, including
72
-
# the ID(s) of the current player(s)
62
+
my_id = game.join() # start/join a session - each client is assigned an ID
63
+
64
+
try:
65
+
game.move(position=5) # perform a move - the function accepts keyword arguments
66
+
except IllegalMove as e:
67
+
print(e)
68
+
69
+
state = game.state() # returns a dictionary representing the game state, including
70
+
# a list of player IDs indicating whose turn it is
73
71
```
74
72
75
-
The [API module](client/game_server_api.py) itself is documented in detail. You should also take a look at the demo clients and the [Wiki](https://github.com/feberts/python-game-server/wiki).
73
+
The [API module](client/game_server_api.py) itself is documented in detail. You can also take a look at the demo clients and the [Wiki](https://github.com/feberts/python-game-server/wiki).
76
74
77
75
## Adding new games
78
76
@@ -87,6 +85,12 @@ To make things even easier, you can use the [template](server/games/template.py)
87
85
88
86
No modifications to the API are required when adding new games. It was designed to be compatible with any game. The function to submit a move accepts keyword arguments (`**kwargs`). These are sent to the server, where they are passed to the corresponding function of the game class as a dictionary. The game state is also sent back as a dictionary. This allows for a maximum of flexibility.
89
87
88
+
## Operating the server
89
+
90
+
To run the server in a network, edit IP and port in the configuration file (`server/config.py`). TLS along with other settings can also be configured there. If you intend to run the server as a systemd service, you can use the provided unit file. Server and API are implemented in plain Python. Only modules from the standard library are used. This makes the server easy to handle.
91
+
92
+
Learn more in the [Wiki](https://github.com/feberts/python-game-server/wiki).
93
+
90
94
## Observer mode
91
95
92
96
An observer will receive the same data as the observed player does when retrieving the game state. This can be useful in a number of ways:
0 commit comments