Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

click部分代码简化问题 #5

Open
fmscole opened this issue Aug 21, 2018 · 1 comment
Open

click部分代码简化问题 #5

fmscole opened this issue Aug 21, 2018 · 1 comment

Comments

@fmscole
Copy link

fmscole commented Aug 21, 2018

尽管不涉及错误,也不影响什么,
双重循环看起来还是很不舒服,毕竟0(1)的问题变成了0(n^2)的问题了,做如下修改比较好:
def click1(self, event): #click1 because keyword repetition
size = self.board.width
current_player = self.board.get_current_player()
if current_player == 1:
# for i in range(size):
# for j in range(size):
i=(event.x)//30
j=(event.y)//30
ri=(event.x)%30
rj=(event.y)%30
i=i-1 if ri<15 else i
j=j-1 if rj<15 else j

        move = self.board.location_to_move((i, j))
        # if move in self.board.availables:
        #     square_distance = math.pow((event.x - self.chess_board_points[i][j].pixel_x), 2) + math.pow((event.y - self.chess_board_points[i][j].pixel_y), 2)                        
            
        #     if (square_distance <= 200):
        self.cv.create_oval(self.chess_board_points[i][j].pixel_x-10, self.chess_board_points[i][j].pixel_y-10, self.chess_board_points[i][j].pixel_x+10, self.chess_board_points[i][j].pixel_y+10, fill='black')
        self.board.do_move(move)
@zouyih
Copy link
Owner

zouyih commented Jan 12, 2019

谢谢指出!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants