本文整理汇总了Python中Board.pack方法的典型用法代码示例。如果您正苦于以下问题:Python Board.pack方法的具体用法?Python Board.pack怎么用?Python Board.pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.pack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Board [as 别名]
# 或者: from Board import pack [as 别名]
def main():
root = Tk()
board = Board(master=root)
board.pack()
#board.mainloop()
eps = EPSILON
#Init Q
Q = np.random.rand(20,20)
trace = np.zeros((20,20))
R = np.zeros((20,20))
goal = board.goal
R[goal.i][goal.j] = 1.0
print "Q initial: "
print_matrix(Q)
for iter2 in range(OUTER_ITER): #Episodes
erase_board(board,s=True)
state = board.get_random_starting_state()
state.set_fill("red")
action = random.choice(range(1,5))
print "Episode: %d" %iter2
while not board.is_valid_action(state,action):
action = random.choice(range(1,5))
for iter in range(INNTER_ITER):
#Take action a
new_i = state_i = state.i
new_j = state_j = state.j
if action == ACTION_DOWN:
new_i +=1
txt = "\\/"
action_name = "DOWN"
elif action == ACTION_UP:
new_i -=1
txt = "/\\"
action_name = "UP"
elif action == ACTION_LEFT:
new_j -=1
txt = "<"
action_name = "LEFT"
elif action == ACTION_RIGHT:
new_j +=1
txt = ">"
action_name = "RIGHT"
Qq = Q[new_i][new_j]
#Observe r
#Observe s'
if board.is_valid_action(state,action):
new_state = board.board_matrix[new_i][new_j]
new_font = "Times " + str(int(Qq*30)) + " bold"
state.addText(txt,new_font) #TAke action
if iter == 0:
state.set_fill("red")
if new_state.color != "red":
new_state.set_fill("green")
#print "TO end up in state: %d,%d" %(new_state.i,new_state.j)
#time.sleep(2)
else:
print "ERROR!"
reward = R[new_i][new_j]
if reward == 1:
if iter2 > 200:
time.sleep(1)
#print "GOAL!!!!"
break
#new_state = board.board_matrix[new_i][new_j]
new_action_pair = find_best_action(board,Q,new_state,eps)
new_action = new_action_pair[0]
new_action_q = new_action_pair[1]
#print "New action is " + str(new_action)
if new_action == ACTION_UP:
qpap_i = new_i - 1
qpap_j = new_j
elif new_action == ACTION_DOWN:
qpap_i = new_i + 1
qpap_j = new_j
elif new_action == ACTION_RIGHT:
qpap_i = new_i
qpap_j = new_j + 1
elif new_action == ACTION_LEFT:
qpap_i = new_i
qpap_j = new_j - 1
Qp = Q[qpap_i][qpap_j]
delta = reward + y*Qp - Qq
trace[new_i][new_j] += 1.0
for i in range(20):
for j in range(20):
cell = board.board_matrix[i][j]
Q[i][j] = Q[i][j] + alpha*delta*trace[i][j]
trace[i][j] = y*lamd*trace[i][j]
#.........这里部分代码省略.........