-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathomoklogic.py
50 lines (42 loc) · 1.47 KB
/
omoklogic.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
from base.logichandler import LogicHandler
from base.string import *
BOARD = "board"
class CustomOMOKLogic(LogicHandler):
def __init__(self):
"""
Develop own your OMOK AI
width and height are board's width and height
empty place is represented integer 0
and your color is represented by number 0 1 2 ...
your color is set automatically.
"""
self.width = 0
self.height = 0
self.my_color = 0
def init_phase(self, msg_type, data):
"""
:param msg_type:
:param data:
:param init_data: {"width": (Integer), "height": (Integer), "color": (Integer)}
:return: None
"""
self.width = data["width"]
self.height = data["height"]
self.my_color = data["color"]
return msg_type, {RESPONSE: OK}
def loop_phase(self, msg_type, data):
"""
:param msg_type:
:param data: message received from server
it consist of {"msg": -, "msg_type": -, "data": { }}
:return: return value is output sending data.
in this game,
if you want to put omok stone at board[x][y],
output is ... dict - { x: n, y: m }
"""
print(data)
board = data[BOARD]
for x in range(self.width):
for y in range(self.height):
if board[x][y] == 0:
return msg_type, {"x": x, "y": y}