-
Notifications
You must be signed in to change notification settings - Fork 0
/
halma_agent.py
100 lines (94 loc) · 3.96 KB
/
halma_agent.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import numpy as np
din = open('input.txt', 'r+')
game_type = din.readline().split()
#print("game_type : ", game_type[0])
playing_color = din.readline().split()
#print("color to play : ",playing_color[0])
ttime = din.readline().split()
total_time = float(ttime[0])
#print("total game time : ", total_time)
board_matrix = []
for i in range(16):
a = din.readline().split()
x = a[0]
bm = [x[b] for b in range(0,len(x))]
#print("each : ",bm)
board_matrix.append(bm)
#print(board_matrix)
din.close()
if playing_color[0] == "WHITE":
player_turn = "W"
elif playing_color == "BLACK":
player_turn = "B"
pawn_location = dict()
parent_child = dict()
class halma_agent:
def __init__(self):
# self.initiate_halma_agent()
pass
def initiate_halma_agent(self):
self.initial_configuration = board_matrix
# print(self.initial_configuration)
self.halma_agent_turn = player_turn
# print("halma agent palyer colour : ", self.halma_agent_turn)
pawn_location.clear()
for i in range(16):
#print(i)
for j in range(16):
if self.initial_configuration[j][i] == player_turn:
#print("configuration : ",i,j)#location of pawns
pawn_location.update({(j,i) : 1})
#print("location of pawns : ", pawn_location.keys())
for i in pawn_location:
self.current = i
# print(self.current)
self.currenty,self.currentx = i[0],i[1]
#print(self.currenty,self.currentx)
self.matrix_mover(self.currenty,self.currentx)
def matrix_mover(self,currenty,currentx):
self.initial_configuration = board_matrix
self.currenty,self.currentx = currenty,currentx
print("mover : ",self.currenty,currentx)
for j in range(self.currenty-1,self.currenty+2):
for k in range(self.currentx-1,self.currentx+2):
if j >= 0 and k >=0 and j <= 15 and k <= 15 and (self.currenty,self.currentx) != (j,k):
if self.initial_configuration[j][k] == ".":
parent_child.setdefault((self.currenty,self.currentx), []).append((j,k))
#parent_child.update({(self.currenty,self.currentx) : (j,k)})
#print("E : ", parent_child)
elif self.initial_configuration[j][k] == "W" or "B":
self.jump_move_interator(self.currenty,self.currentx,j,k)
def jump_move_interator(self,yold,xold,cuy,cux):
self.initial_configuration = board_matrix
self.yold = yold
self.xold = xold
self.cuy = cuy
self.cux = cux
newy,newx = self.yold - (self.yold-self.cuy) * 2 ,self.xold - (self.xold-self.cux)*2
if newy >= 0 and newx >=0 and newy <= 15 and newx <= 15:
if self.initial_configuration[newy][newx] == ".":
parent_child.setdefault((self.yold,self.xold), []).append((newy,newx))
self.matrix_mover(newy,newx)
#print("J : ", parent_child)
elif self.initial_configuration[newy][newx] == "B" or self.initial_configuration[newy][newx] == "W":
return
#print("parent child relationship dict : ",parent_child)
print("E : ", parent_child)
"""
for j in range(self.cuy-1,self.cuy+2):
for k in range(self.cux-1,self.cux+2):
if j,k >= 0 and j,k <= 15 and (self.cuy,self.cux) != (j,k):
if self.initial_configuration[j][k] == ".":
self.jump_move_iterator
elif self.initial_configuration[j][k] == "W" or "B":
self.jump_move_iterator(k,j)
def
"""
h = halma_agent()
h.initiate_halma_agent()
"""
dout = open('output.txt', 'w+')
dout.write("hello")
dout.write("hi")
dout.close()
"""