def append_children(self, num, player): if num == 0: for i in range(11): for j in range(19): if self.board[i][j] == 0: temp_move = "P " + str(i) + " " + str(j) b = self.board temp_board = execute(b,temp_move,player) a = Node(temp_board,temp_move, [], 0, 0) #print(a.board) (self.list_children).append(a) if num == 1: if player == 0: ring = 2 marker = 1 if player == 1: ring = -2 marker = -1 if self.won == 0: while (rows_formed(self.board, 0) != []): temp = rows_formed(self.board, 0) lol = [] for j in temp: temp_move = "RS " + str(j[0][0]) + " " + str(j[0][1]) + " RE " + str(j[1][0]) + " " + str(j[1][1]) lol.append(Node(execute(self.board, temp_move, player),temp_move, [], self.num_ring, self.won)) lol1 = [] for i in lol: for j in range(11): for k in range(19): if i.board[j][k] == ring: temp_move = i.move + " X " + str(j) + " " + str(k) ring_num = i.num_ring + 1 if ring_num>2: lol1.append(Node(execute(i.board, temp_move, player), temp_move, i.list_children, ring_num, 1)) else: lol1.append(Node(execute(i.board, temp_move, player), temp_move, i.list_children, ring_num, 0)) max_node = 'null' max_score = -1000 for i in lol1: score = evaluate(i.board, 0) if score>max_score: max_score = score max_node = i self.board = i.board self.move = i.move self.won = i.won self.num_ring = i.num_ring self.list_children = i.list_children if rows_formed(self.board, 0) == []: for i in range(11): for j in range(19): if self.board[i][j] == ring: for (k,l) in valid_move_list(self.board, [i,j]): temp_move = "S " + str(i) + " " + str(j) + " M " + str(k) + " " + str(l) (self.list_children).append(Node(execute(self.board,temp_move,player), temp_move, [], self.num_ring, self.won)) ''' for i in self.list_children: print(get_hex_move(i.move)) print(i.board) print("---------------------------------------------------------------") ''' for i in self.list_children: print(get_hex_move(i.move)) #print(i.board) for i in self.list_children: #print (get_hex_move(i.move)) #print (rows_formed(i.board, 0)) #print (get_hex_move(i.move)) if (rows_formed(i.board, 0) or rows_formed(i.board, 1))!= []: #print (get_hex_move(i.move)) #print (rows_formed(i.board, 0)) if i.won == 0: self.list_children.remove(i) #print("yessss") temp = [] for j in rows_formed(i.board,0): temp_move = i.move + " RS " + str(j[0][0]) + " " + str(j[0][1]) + " RE " + str(j[1][0]) + " " + str(j[1][1]) temp.append(Node(execute(i.board, temp_move, player), temp_move, i.list_children, i.num_ring, i.won)) temp1 = [] for j in temp: for k in range(11): for l in range(19): if j.board[k][l] == ring: temp_move = j.move + " X " + str(k) + " " + str(l) rings_num = j.num_ring + 1 if rings_num > 2: temp1.append(Node(execute(j.board, temp_move, player), temp_move, j.list_children, rings_num, 1)) else: temp1.append(Node(execute(j.board, temp_move, player), temp_move, j.list_children, rings_num, 0)) for j in temp1: (self.list_children).append(j)
else: move = b_to_h[int(temp[i])][int(temp[i+1])] final.append(str(move[0])) final.append(str(move[1])) i = i + 2 turn = turn - 2 return " ".join(final) + "\n" num_moves = 0 while(True): f = open("test.txt", "a") g = open("test1.txt", "a") if ((flag == 0) and (player == 0)): my_move = "P 5 9" + "\n" board = execute(board, my_move, 0) num_moves += 1 flag = 1 sys.stdout.write("P 0 0\n") sys.stdout.flush() else: op_move = str(sys.stdin.readline().strip()) g.write(op_move + "\n") op_move = str(get_board_move(op_move)) f.write(op_move + "\n") board = execute(board, op_move, 1) my_move = minimax(num_moves, board) board = execute(board, my_move, 0) f.write(my_move + "\n") my_move = str(get_hex_move(my_move)) g.write(my_move + "\n")