def show(self, state, action, next_state, reward, color = 'red'): dim = 40 rows, cols = len(self.grid) + 0.5, max(map(len, self.grid)) if not hasattr(self, 'window'): self.root = Tk() self.window = gui.GUI(self.root) self.window.config(width=cols * (dim + 12), height=rows * (dim + 12)) my_font = tkfont.Font(family="Arial", size=32, weight="bold") for s in range(self.n_states): r, c = self.state2coord[s] x, y = 10 + c * (dim + 4), 10 + r * (dim + 4) if isinstance(self.grid[r][c], numbers.Number): self.window.create_polygon([x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='blue', width=2) self.window.create_text(x + dim / 2., y + dim / 2., text="{:.1f}".format(self.grid[r][c]), font=my_font, fill='white') else: self.window.create_polygon([x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='white', width=2) self.window.pack() my_font = tkfont.Font(family="Arial", size=32, weight="bold") r0, c0 = self.state2coord[state] r0, c0 = 10 + c0 * (dim + 4), 10 + r0 * (dim + 4) x0, y0 = r0 + dim / 2., c0 + dim / 2. r1, c1 = self.state2coord[next_state] r1, c1 = 10 + c1 * (dim + 4), 10 + r1 * (dim + 4) x1, y1 = r1 + dim / 2., c1 + dim / 2. if hasattr(self, 'oval2'): # self.window.delete(self.line1) # self.window.delete(self.oval1) self.window.delete(self.oval2) self.window.delete(self.text1) self.window.delete(self.text2) # self.line1 = self.window.create_arc(x0, y0, x1, y1, dash=(3,5)) # self.oval1 = self.window.create_oval(x0 - dim / 20., y0 - dim / 20., x0 + dim / 20., y0 + dim / 20., dash=(3,5)) self.oval2 = self.window.create_oval(x1 - dim / 5., y1 - dim / 5., x1 + dim / 5., y1 + dim / 5., fill=color) self.text1 = self.window.create_text(dim, (rows - 0.25) * (dim + 12), font=my_font, text="r= {:.1f}".format(reward), anchor='center') self.text2 = self.window.create_text(2 * dim, (rows - 0.25) * (dim + 12), font=my_font, text="action: {}".format(self.action_names[action]), anchor='center') self.window.update()
def show(self, state, action, next_state, reward): posIdSource = self.idxDestination2positionId[self.source_rank] posIdDestination = self.idxDestination2positionId[ self.destination_rank] posIdStartPoint = self.starting_location dim = 100 rows, cols = len(self.grid) + 0.5, max(map(len, self.grid)) if self.reset_window or not hasattr(self, 'window'): if self.reset_window: self.reset_window = False root = Tk() self.window = gui.GUI(root) self.window.config(width=cols * (dim + 12), height=rows * (dim + 12)) my_font = tkFont.Font(family="Arial", size=10, weight="bold") for posId in range(self.n_positionId): r, c = self.positionId2coord[posId] x, y = 10 + c * (dim + 4), 10 + r * (dim + 4) if self.grid[r][c] == 'r': self.window.create_line(10 + (c + 1) * (dim + 4), 10 + r * (dim + 4), 10 + (c + 1) * (dim + 4), 5 + (r + 1) * (dim + 4), fill='red', width=10) if posId == posIdSource: self.window.create_polygon( [x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='green', width=2) elif posId == posIdDestination: self.window.create_polygon( [x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='blue', width=2) elif posId == posIdStartPoint: self.window.create_polygon( [x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='yellow', width=2) else: self.window.create_polygon( [x, y, x + dim, y, x + dim, y + dim, x, y + dim], outline='black', fill='white', width=2) self.window.pack() my_font = tkFont.Font(family="Arial", size=10, weight="bold") posId = self.id2State[state][0] r0, c0 = self.positionId2coord[posId] r0, c0 = 10 + c0 * (dim + 4), 10 + r0 * (dim + 4) x0, y0 = r0 + dim / 2., c0 + dim / 2. posId = self.id2State[next_state][0] r1, c1 = self.positionId2coord[posId] r1, c1 = 10 + c1 * (dim + 4), 10 + r1 * (dim + 4) x1, y1 = r1 + dim / 2., c1 + dim / 2. if hasattr(self, 'oval2'): # self.window.delete(self.line1) # self.window.delete(self.oval1) self.window.delete(self.oval2) self.window.delete(self.text1) self.window.delete(self.text2) self.window.delete(self.text3) # self.line1 = self.window.create_arc(x0, y0, x1, y1, dash=(3,5)) # self.oval1 = self.window.create_oval(x0 - dim / 20., y0 - dim / 20., x0 + dim / 20., y0 + dim / 20., dash=(3,5)) self.oval2 = self.window.create_oval(x1 - dim / 5., y1 - dim / 5., x1 + dim / 5., y1 + dim / 5., fill='red') self.text1 = self.window.create_text(dim, (rows - 0.25) * (dim + 12), font=my_font, text="r= {:.1f}".format(reward), anchor='center') self.text2 = self.window.create_text( 2 * dim, (rows - 0.25) * (dim + 12), font=my_font, text="action: {}".format(self.action_names[action]), anchor='center') self.text3 = self.window.create_text( 4 * dim, (rows - 0.25) * (dim + 12), font=my_font, text="People in the cab: {}".format( self.idx_people == self.num_destinations), anchor='center') self.window.update()