Beispiel #1
0
 def rule1(self,piece):
     original_pos = piece.get_current_pos();
     
     #Looking at the board:
     #Down and to the right
     newX = original_pos[0]+1
     newY = original_pos[1]+1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
         if(lookingAt != 0):
             if(lookingAt.getPlayer() == 2):
                 return [new_pos, self.check_if_jump(original_pos, new_pos)]
     
     #Down and to the left
     newX = original_pos[0]+1
     newY = original_pos[1]-1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
         if(lookingAt != 0):
             if(lookingAt.getPlayer() == 2):
                 return [new_pos, self.check_if_jump(original_pos, new_pos)]
                                                 
     #King's only
     if(piece.getIsKing == True):
         
         #Up and to the right
         newX = original_pos[0]-1
         newY = original_pos[1]+1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
             if(lookingAt != 0):
                 if(lookingAt.getPlayer() == 2):
                     return [new_pos, self.check_if_jump(original_pos, new_pos)]
         
         #Up and to the left
         newX = original_pos[0]-1
         newY = original_pos[1]-1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
             if(lookingAt != 0):
                 if(lookingAt.getPlayer() == 2):
                     return [new_pos, self.check_if_jump(original_pos, new_pos)]
         
     return False #None of these triggered the rule
Beispiel #2
0
 def rule3(self,piece):
     original_pos = piece.get_current_pos();
     
     #Looking at the board:
     #Down and to the right
     newX = original_pos[0]+1
     newY = original_pos[1]+1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         if(newX == 7):
             return new_pos
     
     #Down and to the left
     newX = original_pos[0]+1
     newY = original_pos[1]-1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         if(newX == 7):
             return new_pos
                                                 
     #King's only - not required here!
         
     return False #None of these triggered the rule
Beispiel #3
0
 def ruleTemplate(self,piece):
     original_pos = piece.get_current_pos();
     
     #Looking at the board:
     #Down and to the right
     newX = original_pos[0]+1
     newY = original_pos[1]+1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         return True
     
     #Down and to the left
     newX = original_pos[0]+1
     newY = original_pos[1]-1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         return True
                                                 
     #King's only
     if(piece.getIsKing == True):
         
         #Up and to the right
         newX = original_pos[0]-1
         newY = original_pos[1]+1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             return True
         
         #Up and to the left
         newX = original_pos[0]-1
         newY = original_pos[1]-1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             return True
         
     return False #None of these triggered the rule
Beispiel #4
0
 def rule2(self,piece):
     original_pos = piece.get_current_pos();
     
     #Looking at the board:
     #Down and to the right
     newX = original_pos[0]+1
     newY = original_pos[1]+1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         #Start Here
         safe = True
         lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
         #Down and to the right
         newX2 = newX + 1
         newY2 = newY + 1
         new_pos2 = [newX2,newY2]
         if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
             lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
             if(lookingAt2 != 0):
                 if(lookingAt2.getPlayer() == 2):
                     safe = False
         #Down and to the left
         newX2 = newX + 1
         newY2 = newY - 1
         new_pos2 = [newX2,newY2]
         if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
             lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
             if(lookingAt2 != 0):
                 if(lookingAt2.getPlayer() == 2):
                     safe = False
         if(piece.getIsKing == True):
             #Up and to the right
             newX2 = newX - 1
             newY2 = newY + 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             #Up and to the left
             newX2 = newX - 1
             newY2 = newY - 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
         #End Here
         if(safe == True):
             return new_pos
     
     #Down and to the left
     newX = original_pos[0]+1
     newY = original_pos[1]-1
     new_pos = [newX,newY]
     if(self.validateMove(original_pos,new_pos)):
         #Start Here
         safe = True
         lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
         #Down and to the right
         newX2 = newX + 1
         newY2 = newY + 1
         new_pos2 = [newX2,newY2]
         if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
             lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
             if(lookingAt2 != 0):
                 if(lookingAt2.getPlayer() == 2):
                     safe = False
         #Down and to the left
         newX2 = newX + 1
         newY2 = newY - 1
         new_pos2 = [newX2,newY2]
         if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
             lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
             if(lookingAt2 != 0):
                 if(lookingAt2.getPlayer() == 2):
                     safe = False
         if(piece.getIsKing == True):
             #Up and to the right
             newX2 = newX - 1
             newY2 = newY + 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             #Up and to the left
             newX2 = newX - 1
             newY2 = newY - 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
         #End Here
         if(safe == True):
             return new_pos
                                                 
     #King's only
     if(piece.getIsKing == True):
         
         #Up and to the right
         newX = original_pos[0]-1
         newY = original_pos[1]+1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             #Start Here
             safe = True
             lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
             #Down and to the right
             newX2 = newX + 1
             newY2 = newY + 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             #Down and to the left
             newX2 = newX + 1
             newY2 = newY - 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             if(piece.getIsKing == True):
                 #Up and to the right
                 newX2 = newX - 1
                 newY2 = newY + 1
                 new_pos2 = [newX2,newY2]
                 if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                     lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                     if(lookingAt2 != 0):
                         if(lookingAt2.getPlayer() == 2):
                             safe = False
                 #Up and to the left
                 newX2 = newX - 1
                 newY2 = newY - 1
                 new_pos2 = [newX2,newY2]
                 if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                     lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                     if(lookingAt2 != 0):
                         if(lookingAt2.getPlayer() == 2):
                             safe = False
             #End Here
             if(safe == True):
                 return new_pos
         
         #Up and to the left
         newX = original_pos[0]-1
         newY = original_pos[1]-1
         new_pos = [newX,newY]
         if(self.validateMove(original_pos,new_pos)):
             #Start Here
             safe = True
             lookingAt = self.get_board()[new_pos[0]][new_pos[1]]
             #Down and to the right
             newX2 = newX + 1
             newY2 = newY + 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             #Down and to the left
             newX2 = newX + 1
             newY2 = newY - 1
             new_pos2 = [newX2,newY2]
             if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                 lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                 if(lookingAt2 != 0):
                     if(lookingAt2.getPlayer() == 2):
                         safe = False
             if(piece.getIsKing == True):
                 #Up and to the right
                 newX2 = newX - 1
                 newY2 = newY + 1
                 new_pos2 = [newX2,newY2]
                 if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                     lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                     if(lookingAt2 != 0):
                         if(lookingAt2.getPlayer() == 2):
                             safe = False
                 #Up and to the left
                 newX2 = newX - 1
                 newY2 = newY - 1
                 new_pos2 = [newX2,newY2]
                 if((newX2 < 8) and (newX2 >= 0) and (newY2 < 8) and (newY2 >= 0)):
                     lookingAt2 = self.get_board()[new_pos2[0]][new_pos2[1]]
                     if(lookingAt2 != 0):
                         if(lookingAt2.getPlayer() == 2):
                             safe = False
             #End Here
             if(safe == True):
                 return new_pos
             
     return False #None of these triggered the rule