def brain_eval(x, y): wnd = win32gui.GetForegroundWindow() dc = win32gui.GetDC(wnd) rc = win32gui.GetClientRect(wnd) c = str(board[x][y]) win32gui.ExtTextOut(dc, rc[2] - 15, 3, 0, None, c, ()) win32gui.ReleaseDC(wnd, dc)
def brain_eval(x, y): # TODO check if it works as expected wnd = win32gui.GetForegroundWindow() dc = win32gui.GetDC(wnd) rc = win32gui.GetClientRect(wnd) c = str(agent.board[x, y]) win32gui.ExtTextOut(dc, rc[2] - 15, 3, 0, None, c, ()) win32gui.ReleaseDC(wnd, dc)
def brain_eval(x, y): logDebug('brain eval') # TODO check if it works as expected wnd = win32gui.GetForegroundWindow() dc = win32gui.GetDC(wnd) rc = win32gui.GetClientRect(wnd) board = gomoku.get_board() c = str(board[x][y]) win32gui.ExtTextOut(dc, rc[2] - 15, 3, 0, None, c, ()) win32gui.ReleaseDC(wnd, dc)
def text_to_shape(self, text: str) -> Shape: if sys.platform == "win32": # TODO: Calcultating distance between origins of character cells (just in case of spacing) # Add path to device context win32gui.BeginPath(self.dc) win32gui.ExtTextOut(self.dc, 0, 0, 0x0, None, text) win32gui.EndPath(self.dc) # Getting Path produced by Microsoft API points, type_points = win32gui.GetPath(self.dc) # Checking for errors if len(points) == 0 or len(points) != len(type_points): raise RuntimeError( "This should never happen: function win32gui.GetPath has returned something unexpected.\nPlease report this to the developer" ) # Defining variables shape, last_type = [], None mult_x, mult_y = self.downscale * self.xscale, self.downscale * self.yscale # Convert points to shape i = 0 while i < len(points): cur_point, cur_type = points[i], type_points[i] if cur_type == win32con.PT_MOVETO: if last_type != win32con.PT_MOVETO: # Avoid repetition of command tags shape.append("m") last_type = cur_type shape.extend([ Shape.format_value(cur_point[0] * mult_x), Shape.format_value(cur_point[1] * mult_y), ]) i += 1 elif cur_type == win32con.PT_LINETO or cur_type == ( win32con.PT_LINETO | win32con.PT_CLOSEFIGURE): if last_type != win32con.PT_LINETO: # Avoid repetition of command tags shape.append("l") last_type = cur_type shape.extend([ Shape.format_value(cur_point[0] * mult_x), Shape.format_value(cur_point[1] * mult_y), ]) i += 1 elif cur_type == win32con.PT_BEZIERTO or cur_type == ( win32con.PT_BEZIERTO | win32con.PT_CLOSEFIGURE): if last_type != win32con.PT_BEZIERTO: # Avoid repetition of command tags shape.append("b") last_type = cur_type shape.extend([ Shape.format_value(cur_point[0] * mult_x), Shape.format_value(cur_point[1] * mult_y), Shape.format_value(points[i + 1][0] * mult_x), Shape.format_value(points[i + 1][1] * mult_y), Shape.format_value(points[i + 2][0] * mult_x), Shape.format_value(points[i + 2][1] * mult_y), ]) i += 3 else: # If there is an invalid type -> skip, for safeness i += 1 # Clear device context path win32gui.AbortPath(self.dc) return Shape(" ".join(shape)) elif sys.platform == "linux" or sys.platform == "darwin": # Defining variables shape, last_type = [], None def shape_from_text(new_text, x_add): nonlocal shape, last_type self.layout.set_markup( f"<span " f'strikethrough="{str(self.strikeout).lower()}" ' f'underline="{"single" if self.underline else "none"}"' f">" f"{html.escape(new_text)}" f"</span>", -1, ) self.context.save() self.context.scale( self.downscale * self.xscale * self.fonthack_scale, self.downscale * self.yscale * self.fonthack_scale, ) PangoCairo.layout_path(self.context, self.layout) self.context.restore() path = self.context.copy_path() # Convert points to shape for current_entry in path: current_type = current_entry[0] current_path = current_entry[1] if current_type == 0: # MOVE_TO if last_type != current_type: # Avoid repetition of command tags shape.append("m") last_type = current_type shape.extend([ Shape.format_value(current_path[0] + x_add), Shape.format_value(current_path[1]), ]) elif current_type == 1: # LINE_TO if last_type != current_type: # Avoid repetition of command tags shape.append("l") last_type = current_type shape.extend([ Shape.format_value(current_path[0] + x_add), Shape.format_value(current_path[1]), ]) elif current_type == 2: # CURVE_TO if last_type != current_type: # Avoid repetition of command tags shape.append("b") last_type = current_type shape.extend([ Shape.format_value(current_path[0] + x_add), Shape.format_value(current_path[1]), Shape.format_value(current_path[2] + x_add), Shape.format_value(current_path[3]), Shape.format_value(current_path[4] + x_add), Shape.format_value(current_path[5]), ]) self.context.new_path() curr_width = 0 for i, char in enumerate(text): shape_from_text(char, curr_width + self.hspace * self.xscale * i) curr_width += self.get_text_extents(char)[0] return Shape(" ".join(shape)) else: raise NotImplementedError