|  |  | @ -1,6 +1,10 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | from re import S | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | from shutil import move | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | class GameState: |  |  |  | class GameState: | 
			
		
	
		
		
			
				
					
					|  |  |  |     def __init__(self): |  |  |  |     def __init__(self): | 
			
		
	
		
		
			
				
					
					|  |  |  |         ''' |  |  |  |         ''' | 
			
		
	
	
		
		
			
				
					|  |  | @ -67,10 +71,25 @@ class GameState: | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return True |  |  |  |                 return True | 
			
		
	
		
		
			
				
					
					|  |  |  |         return False |  |  |  |         return False | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |     def Eliminate(self,row,col,nxt_row,nxt_col): |  |  |  |     def Eliminate(self,row,col,nxt_row,nxt_col):#下一步可吃对手的棋 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         return self.board[nxt_row][nxt_col] == '00' or self.board[nxt_row][nxt_col][0] != self.board[row][col][0] and eval(self.board[row][col][1]) >= eval(self.board[nxt_row][nxt_col][1]) |  |  |  |         return self.board[nxt_row][nxt_col] == '00' or self.board[nxt_row][nxt_col][0] != self.board[row][col][0] and eval(self.board[row][col][1]) >= eval(self.board[nxt_row][nxt_col][1]) | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |     # 定义移动方式 |  |  |  |     # 定义移动方式 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     #---------------------------------- | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     #   以下为移动方式的相关规定: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     #       1.下一步的可行位置以二维数组的格式进行记录。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     #       2.getValidMoves返回值为下一步可行位置构成的集合。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     #----------------------------------     | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     def getAllMoves(self): | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         moves=[] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for row in range(len(self.board)): | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             for col in range(len(self.board[row])): | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 player = self.board[row][col][0] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if (player == 'r' and self.red_to_move or player == 'b' and not self.red_to_move): | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     self.moveFunctions[self.board[row][col][1]](row,col,moves) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return moves | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              | 
			
		
	
		
		
			
				
					
					|  |  |  |     def getStdMoves(self,row,col,moves):#输入当前的位置,将可行路径输出给moves |  |  |  |     def getStdMoves(self,row,col,moves):#输入当前的位置,将可行路径输出给moves | 
			
		
	
		
		
			
				
					
					|  |  |  |         directions = [(1,0),(0,1),(-1,0),(0,-1)] |  |  |  |         directions = [(1,0),(0,1),(-1,0),(0,-1)] | 
			
		
	
		
		
			
				
					
					|  |  |  |         enemy_color = 'b' if self.red_to_move else 'r' |  |  |  |         enemy_color = 'b' if self.red_to_move else 'r' | 
			
		
	
	
		
		
			
				
					|  |  | @ -159,20 +178,20 @@ class GameState: | 
			
		
	
		
		
			
				
					
					|  |  |  |                     end_piece = self.board[end_row][end_col] |  |  |  |                     end_piece = self.board[end_row][end_col] | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if end_piece == "--" and not self.inWater(end_row,end_col) and self.moveNotOwnDen(end_row,end_col,enemy_color):  # empty space is valid and Not in Water |  |  |  |                     if end_piece == "--" and not self.inWater(end_row,end_col) and self.moveNotOwnDen(end_row,end_col,enemy_color):  # empty space is valid and Not in Water | 
			
		
	
		
		
			
				
					
					|  |  |  |                         moves.append(Move((row, col), (end_row, end_col), self.board)) |  |  |  |                         moves.append((end_row, end_col)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     elif end_piece == "--" and self.inWater(end_row,end_col): |  |  |  |                     elif end_piece == "--" and self.inWater(end_row,end_col): | 
			
		
	
		
		
			
				
					
					|  |  |  |                         jump_row = end_row - row  #Vertical jump |  |  |  |                         jump_row = end_row - row  #Vertical jump | 
			
		
	
		
		
			
				
					
					|  |  |  |                         jump_col = end_col - col  #Horizontal jump |  |  |  |                         jump_col = end_col - col  #Horizontal jump | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if jump_row != 0 and self.jumpConditions(row,col,end_row,end_col,jump_row,jump_col,enemy_color): |  |  |  |                         if jump_row != 0 and self.jumpConditions(row,col,end_row,end_col,jump_row,jump_col,enemy_color): | 
			
		
	
		
		
			
				
					
					|  |  |  |                             moves.append(Move((row, col), (end_row+(3*jump_row), end_col), self.board)) |  |  |  |                             moves.append((end_row+(3*jump_row), end_col)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                         elif jump_col != 0 and self.jumpConditions(row,col,end_row,end_col,jump_row,jump_col,enemy_color): |  |  |  |                         elif jump_col != 0 and self.jumpConditions(row,col,end_row,end_col,jump_row,jump_col,enemy_color): | 
			
		
	
		
		
			
				
					
					|  |  |  |                             moves.append(Move((row, col), (end_row, end_col+(2*jump_col)), self.board)) |  |  |  |                             moves.append((end_row, end_col+(2*jump_col))) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     elif end_piece[0] == enemy_color and not self.inWater(end_row,end_col) and self.canAttack(row, col, end_row, end_col):  # capture enemy piece |  |  |  |                     elif end_piece[0] == enemy_color and not self.inWater(end_row,end_col) and self.canAttack(row, col, end_row, end_col):  # capture enemy piece | 
			
		
	
		
		
			
				
					
					|  |  |  |                         moves.append(Move((row, col), (end_row, end_col), self.board)) |  |  |  |                         moves.append((end_row, end_col)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                         break |  |  |  |                         break | 
			
		
	
		
		
			
				
					
					|  |  |  |                     else:  # friendly piece |  |  |  |                     else:  # friendly piece | 
			
		
	
		
		
			
				
					
					|  |  |  |                         break |  |  |  |                         break | 
			
		
	
	
		
		
			
				
					|  |  | 
 |