Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Определить класс «Шахматная фигура» и унаследовать от него классы, соответствующие
- #шахматным фигурам "Queen", "Pawn", «Knight». Задать позицию и определить список
- #фигур, которые может убить некоторая выбранная.
- chessPiece = []
- count = 0
- class ChessPiece() :
- name = None
- pos = []
- def __init__(self, pos_1, pos_2, name) :
- self.name = name
- if ord(pos_1) < 73 :
- pos_1 = ord(pos_1) - 65
- else :
- pos_1 = ord(pos_1) - 97
- self.pos = [pos_1, pos_2]
- board[pos_1][pos_2] = count
- count += 1
- pass
- def __del__ (self) :
- board[pos_1][pos_2] = 0
- def info (self) :
- print(f"It's {self.name}")
- print(f"Position is {chr(self.pos[0]+65)}{self.pos[1]+1}")
- pass
- def findKill (self) :
- """Поиск фигур, которые можно выпилить"""
- pass
- class Queen(ChessPiece) :
- def __init__ (self, pos_1, pos_2, name = "Queen") :
- print("The Queen on the board")
- super().__init__(pos_1, pos_2, name)
- pass
- def __del__ (self) :
- print("The Queen is dead")
- pass
- class Pawn(ChessPiece) :
- def __init__ (self, pos_1, pos_2, name = "Pawn") :
- print("The Pawn on the board")
- super().__init__(pos_1, pos_2, name)
- pass
- def __del__ (self) :
- print("The Pawn is dead")
- pass
- class Knight(ChessPiece) :
- def __init__ (self, pos_1, pos_2, name = "Knight") :
- print("The Knight on the board")
- super().__init__(pos_1, pos_2, name)
- pass
- def __del__ (self) :
- print("The Knight is dead")
- pass
- def checkEmpty(pos) :
- if board[pos[0]][int(pos[1]) - 1] == 0 :
- return True
- else :
- return False
- board = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- chess = ("1 - Queen", "2 - Pawn", "3 - Knight", "0 - Cancel")
- print("Please use the Latin layout: A-H, a-h, 1-8")
- while True :
- print("Who should I add to the board?")
- for i in chess:
- print(i)
- choosePiece = int(input())
- while True :
- if choosePiece == 1 :
- print("Where to put the shape?")
- coord = input("Enter the position of the shape. For example: a7 or D4\n")
- if checkEmpty(coord) :
- chessPiece.append(Queen(coord[0], int(coord[1]) - 1))
- else :
- print("This place is not free.")
- continue
- break
- elif choosePiece == 2 :
- print("Where to put the shape?")
- coord = input("Enter the position of the shape. For example: a7 or D4")
- if checkEmpty(coord) :
- chessPiece.append(Pawn(coord[0], int(coord[1]) - 1))
- else :
- print("This place is not free.")
- continue
- break
- elif choosePiece == 3 :
- print("Where to put the shape?")
- coord = input("Enter the position of the shape. For example: a7 or D4")
- if checkEmpty(coord) :
- chessPiece.append(Knight(coord[0], int(coord[1]) - 1))
- else :
- print("This place is not free.")
- continue
- break
- elif choosePiece == 0 :
- print("Creation canceled!")
- break
- else :
- print("Select the correct option: ")
- choosePiece = int(input())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement