Advertisement
Norvager

L7

Jun 1st, 2021
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. #Определить класс «Шахматная фигура» и унаследовать от него классы, соответствующие
  2. #шахматным фигурам "Queen", "Pawn", «Knight». Задать позицию и определить список
  3. #фигур, которые может убить некоторая выбранная.
  4. chessPiece = []
  5. count = 0
  6. class ChessPiece() :
  7.     name = None
  8.     pos = []
  9.     def __init__(self, pos_1, pos_2, name) :
  10.         self.name = name
  11.         if ord(pos_1) < 73 :
  12.             pos_1 = ord(pos_1) - 65
  13.         else :
  14.             pos_1 = ord(pos_1) - 97
  15.         self.pos = [pos_1, pos_2]
  16.         board[pos_1][pos_2] = count
  17.         count += 1
  18.         pass
  19.     def __del__ (self) :
  20.         board[pos_1][pos_2] = 0
  21.     def info (self) :
  22.         print(f"It's {self.name}")
  23.         print(f"Position is {chr(self.pos[0]+65)}{self.pos[1]+1}")
  24.         pass
  25.     def findKill (self) :
  26.         """Поиск фигур, которые можно выпилить"""
  27.         pass
  28.  
  29. class Queen(ChessPiece) :
  30.     def __init__ (self, pos_1, pos_2, name = "Queen") :
  31.         print("The Queen on the board")
  32.         super().__init__(pos_1, pos_2, name)
  33.         pass
  34.     def __del__ (self) :
  35.         print("The Queen is dead")
  36.         pass
  37.    
  38. class Pawn(ChessPiece) :
  39.     def __init__ (self, pos_1, pos_2, name = "Pawn") :
  40.         print("The Pawn on the board")
  41.         super().__init__(pos_1, pos_2, name)
  42.         pass
  43.     def __del__ (self) :
  44.         print("The Pawn is dead")
  45.         pass
  46.  
  47. class Knight(ChessPiece) :
  48.     def __init__ (self, pos_1, pos_2, name = "Knight") :
  49.         print("The Knight on the board")
  50.         super().__init__(pos_1, pos_2, name)
  51.         pass
  52.     def __del__ (self) :
  53.         print("The Knight is dead")
  54.         pass
  55.  
  56. def checkEmpty(pos) :
  57.     if board[pos[0]][int(pos[1]) - 1] == 0 :
  58.         return True
  59.     else :
  60.         return False
  61.  
  62. board = [[0, 0, 0, 0, 0, 0, 0, 0],
  63.          [0, 0, 0, 0, 0, 0, 0, 0],
  64.          [0, 0, 0, 0, 0, 0, 0, 0],
  65.          [0, 0, 0, 0, 0, 0, 0, 0],
  66.          [0, 0, 0, 0, 0, 0, 0, 0],
  67.          [0, 0, 0, 0, 0, 0, 0, 0],
  68.          [0, 0, 0, 0, 0, 0, 0, 0],
  69.          [0, 0, 0, 0, 0, 0, 0, 0]]
  70. chess = ("1 - Queen", "2 - Pawn", "3 - Knight", "0 - Cancel")
  71. print("Please use the Latin layout: A-H, a-h, 1-8")
  72. while True :
  73.     print("Who should I add to the board?")
  74.     for i in chess:
  75.         print(i)
  76.     choosePiece = int(input())
  77.     while True :
  78.         if choosePiece == 1 :
  79.             print("Where to put the shape?")
  80.             coord = input("Enter the position of the shape. For example: a7 or D4\n")
  81.             if checkEmpty(coord) :
  82.                 chessPiece.append(Queen(coord[0], int(coord[1]) - 1))
  83.             else :
  84.                 print("This place is not free.")
  85.                 continue
  86.             break
  87.         elif choosePiece == 2 :
  88.             print("Where to put the shape?")
  89.             coord = input("Enter the position of the shape. For example: a7 or D4")
  90.             if checkEmpty(coord) :
  91.                 chessPiece.append(Pawn(coord[0], int(coord[1]) - 1))
  92.             else :
  93.                 print("This place is not free.")
  94.                 continue
  95.             break
  96.         elif choosePiece == 3 :
  97.             print("Where to put the shape?")
  98.             coord = input("Enter the position of the shape. For example: a7 or D4")
  99.             if checkEmpty(coord) :
  100.                 chessPiece.append(Knight(coord[0], int(coord[1]) - 1))
  101.             else :
  102.                 print("This place is not free.")
  103.                 continue
  104.             break
  105.         elif choosePiece == 0 :
  106.             print("Creation canceled!")
  107.             break
  108.         else :
  109.             print("Select the correct option: ")
  110.             choosePiece = int(input())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement