-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
executable file
·54 lines (49 loc) · 1.69 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Game launcher.
By default it starts a single-player game with one bot.
* TODO Use the twisted app infrastructure
* TODO delegate to multiple processes
"""
import os
import sys
from sys import argv
from time import sleep
from twisted.internet import reactor, protocol
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.endpoints import connectProtocol
from polemika.mechanics import GameFactory, Bunch
from polemika.smarter_player import MomentAI
from polemika.human_client import HumanPlayer
from polemika.human_client import reset_human_client_state
from polemika.human_client import start_game_loops
from polemika.human_client import init_pygame
from polemika.dummy_player import reset_state, write_on_connection
def start_server(num_pl, time, dwords, lname):
reactor.listenTCP(9022, GameFactory(num_pl, time, dwords, lname))
def start_smart_player(lname):
point = TCP4ClientEndpoint(reactor, "localhost", 9022)
state = Bunch()
reset_state(state)
d = connectProtocol(point, MomentAI({}, state, lname))
d.addCallback(write_on_connection)
def start_human_player(lname):
point = TCP4ClientEndpoint(reactor, "localhost", 9022)
state = Bunch()
reset_state(state)
reset_human_client_state(state)
d = connectProtocol(point, HumanPlayer({}, state, lname))
d.addCallback(write_on_connection)
d.addCallback(start_game_loops, state)
init_pygame()
if __name__ == '__main__':
if len(argv) > 1:
DICT = argv[1]
else:
DICT = "words"
start_server(2, 30, DICT, "server.log")
sleep(0.5)
start_smart_player('ai.log')
start_human_player('human.log')
reactor.run()