Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. from itertools import product
  2. X = ["a", "b", "c", "d", "e", "f", "g", "h"]
  3. Y = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  4.  
  5.  
  6. class Alfiere:
  7.  
  8.     def __init__(self, pos_in_x, pos_in_y):
  9.         self.pos_in_x = pos_in_x
  10.         self.pos_in_y = pos_in_y
  11.  
  12.     def alfiere_moves(self):
  13.         if self.pos_in_x not in X or self.pos_in_y not in Y:
  14.             return print("x o y non esiste")
  15.         x, y = ord(self.pos_in_x), self.pos_in_y
  16.         finale_risult = []
  17.  
  18.         for n in range(1, 9):
  19.             if n <= 8:
  20.                 count = 1
  21.                 moves = list(product([x + count], [y + count]))
  22.                 for x, y in moves:
  23.                     if ord('a') <= x <= ord('h') and 1 <= y <= 8:
  24.                         finale_risult.append((chr(x), y))
  25.                 moves.clear()
  26.  
  27.         x = ord(self.pos_in_x)
  28.         y = self.pos_in_y
  29.         for n in range(1, 9):
  30.             count = 1
  31.             moves_1 = list(product([x - count], [y + count]))
  32.             for x, y in moves_1:
  33.                 if ord('a') <= x <= ord('h') and 1 <= y <= 8:
  34.                     finale_risult.append((chr(x), y))
  35.             moves_1.clear()
  36.  
  37.         x = ord(self.pos_in_x)
  38.         y = self.pos_in_y
  39.         for n in range(1, 9):
  40.             count = 1
  41.             moves_2 = list(product([x - count], [y - count]))
  42.             for x, y in moves_2:
  43.                 if ord('a') <= x <= ord('h') and 1 <= y <= 8:
  44.                     finale_risult.append((chr(x), y))
  45.             moves_2.clear()
  46.  
  47.         x = ord(self.pos_in_x)
  48.         y = self.pos_in_y
  49.         for n in range(1, 9):
  50.             count = 1
  51.             moves_3 = list(product([x + count], [y - count]))
  52.             for x, y in moves_3:
  53.                 if ord('a') <= x <= ord('h') and 1 <= y <= 8:
  54.                     finale_risult.append((chr(x), y))
  55.             moves_3.clear()
  56.  
  57.         return print(finale_risult)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement