forked from AndrejaNajev/tetris-AI-bot-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (52 loc) · 2.14 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Main:
def __init__(self, game):
self._game = game
self._playerNames = []
def parse(self, line):
parts = line.split()
if parts[0] == 'settings':
self.set(parts[1:])
elif parts[0] == 'update':
self.update(parts[1:])
def set(self, values):
if values[0] == 'player_names':
self._playerNames = values[1].split(',')
elif values[0] == 'your_bot':
self._game.me.name = values[1]
self._playerNames.remove(values[1])
self._game.enemy.name = self._playerNames[0]
elif values[0] == 'field_width':
self._game.me.field.width = int(values[1])
self._game.enemy.field.width = int(values[1])
elif values[0] == 'field_height':
self._game.me.field.height = int(values[1])
self._game.enemy.field.height = int(values[1])
elif values[0] == 'timebank':
self._game.timebank = values[1]
elif values[0] == 'time_per_move':
self._game.timePerMove = values[1]
def update(self, values):
if values[0] == 'game':
self.updateGame(values[1:])
else:
self.updatePlayer(values[0], values[1:])
def updateGame(self, values):
if values[0] == 'this_piece_position':
self._game.piecePosition = tuple(map(lambda x: int(x), values[1].split(',')))
elif values[0] == 'this_piece_type':
self._game.currentPiece = values[1]
elif values[0] == 'next_piece_type':
self._game.nextPiece = values[1]
elif values[0] == 'round':
self._game.round = int(values[1])
def updatePlayer(self, playerName, values):
if playerName != self._game.me.name:
player = self._game.enemy
else:
player = self._game.me
if values[0] == 'field':
player.field.updateField(map(lambda r: map(lambda x: int(x), r.split(',')), values[1].split(';')))
elif values[0] == 'combo':
player.combo = values[1]
elif values[0] == 'row_points':
player.combo = values[1]