Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- board=[[-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1],
- [-1, -1, -1, -1, -1, -1, -1, -1]]
- chessPiece = []
- class Figure():
- name = None
- pos = []
- pos_out = []
- def __init__(self, pos_1, pos_2) :
- self.pos_out = [pos_1, pos_2+1]
- 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] = len(chessPiece)
- pass
- def __del__ (self) :
- board[pos_1][pos_2] = -1
- pass
- def output (self) :
- print(f"{self.name}")
- print(f"Position is {self.pos_out[0]}{self.pos_out[1]}")
- pass
- class Pawn(Figure):
- def __init__ (self, pos_1, pos_2, name = "Pawn") :
- """Создание пешки"""
- self.name = name
- super().__init__(pos_1, pos_2)
- print(f"The {self.name} on the board")
- pass
- def __del__ (self) :
- print(f"The {self.name} is dead")
- pass
- def kill_check(self) :
- if self.pos[1] > 4 :
- if self.pos[0] - 1 > -1 :
- if board[self.pos[0]-1][self.pos[1]-1] != -1 :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]-1][self.pos[1]-1]].name} on {chessPiece[board[self.pos[0]-1][self.pos[1]-1]].pos_out[0]}{chessPiece[board[self.pos[0]-1][self.pos[1]-1]].pos_out[1]}.")
- if self.pos[0] - 1 < 8 :
- if board[self.pos[0]+1][self.pos[1]-1] != -1 :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]+1][self.pos[1]-1]].name} on {chessPiece[board[self.pos[0]+1][self.pos[1]-1]].pos_out[0]}{chessPiece[board[self.pos[0]+1][self.pos[1]-1]].pos_out[1]}.")
- else :
- if self.pos[0] - 1 > -1 :
- if board[self.pos[0]-1][self.pos[1]-1] != -1 :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]-1][self.pos[1]+1]].name} on {chessPiece[board[self.pos[0]-1][self.pos[1]+1]].pos_out[0]}{chessPiece[board[self.pos[0]-1][self.pos[1]+1]].pos_out[1]}.")
- if self.pos[0] - 1 < 8 :
- if board[self.pos[0]+1][self.pos[1]-1] != -1 :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]+1][self.pos[1]+1]].name} on {chessPiece[board[self.pos[0]+1][self.pos[1]+1]].pos_out[0]}{chessPiece[board[self.pos[0]+1][self.pos[1]+1]].pos_out[1]}.")
- class Knight(Figure):
- def __init__ (self, pos_1, pos_2, name = "Knight") :
- """Создание коня"""
- self.name = name
- super().__init__(pos_1, pos_2)
- print(f"The {self.name} on the board")
- pass
- def __del__ (self) :
- print("The {self.name} is dead")
- pass
- def kill_check(self):
- if all(self.pos[0]-2>0, self.pos[1]-1>0, board[self.pos[0]-2][self.pos[1]-1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]-2][self.pos[1]-1]].name} on {chessPiece[board[self.pos[0]-2][self.pos[1]-1]].pos_out[0]}{chessPiece[board[self.pos[0]-2][self.pos[1]-1]].pos_out[1]}.")
- if all(self.pos[0]-2>0, self.pos[1]+1<8, board[self.pos[0]-2][self.pos[1]+1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]-2][self.pos[1]+1]].name} on {chessPiece[board[self.pos[0]-2][self.pos[1]+1]].pos_out[0]}{chessPiece[board[self.pos[0]-2][self.pos[1]+1]].pos_out[1]}.")
- if all(self.pos[0]+2<8, self.pos[1]-1>0, board[self.pos[0]+2][self.pos[1]-1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]+2][self.pos[1]-1]].name} on {chessPiece[board[self.pos[0]+2][self.pos[1]-1]].pos_out[0]}{chessPiece[board[self.pos[0]+2][self.pos[1]-1]].pos_out[1]}.")
- if all(self.pos[0]+2<8, self.pos[1]+1<8, board[self.pos[0]+2][self.pos[1]+1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]+2][self.pos[1]+1]].name} on {chessPiece[board[self.pos[0]+2][self.pos[1]+1]].pos_out[0]}{chessPiece[board[self.pos[0]+2][self.pos[1]+1]].pos_out[1]}.")
- if all(self.pos[1]-2>0, self.pos[0]-1>0, board[self.pos[1]-2][self.pos[0]-1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[1]-2][self.pos[0]-1]].name} on {chessPiece[board[self.pos[1]-2][self.pos[0]-1]].pos_out[0]}{chessPiece[board[self.pos[1]-2][self.pos[0]-1]].pos_out[1]}.")
- if all(self.pos[1]-2>0, self.pos[0]+1<8, board[self.pos[1]-2][self.pos[0]+1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[1]-2][self.pos[0]+1]].name} on {chessPiece[board[self.pos[1]-2][self.pos[0]+1]].pos_out[0]}{chessPiece[board[self.pos[1]-2][self.pos[0]+1]].pos_out[1]}.")
- if all(self.pos[1]+2<8, self.pos[0]-1>0, board[self.pos[1]+2][self.pos[0]-1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[1]+2][self.pos[0]-1]].name} on {chessPiece[board[self.pos[1]+2][self.pos[0]-1]].pos_out[0]}{chessPiece[board[self.pos[1]+2][self.pos[0]-1]].pos_out[1]}.")
- if all(self.pos[1]+2<8, self.pos[0]+1<8, board[self.pos[1]+2][self.pos[0]+1]!=-1) :
- print(f"{self.name} can kill {chessPiece[board[self.pos[1]+2][self.pos[0]+1]].name} on {chessPiece[board[self.pos[1]+2][self.pos[0]+1]].pos_out[0]}{chessPiece[board[self.pos[1]+2][self.pos[0]+1]].pos_out[1]}.")
- class Queen(Figure):
- def __init__ (self, pos_1, pos_2, name = "Queen") :
- """Создание Ферзя"""
- self.name = name
- super().__init__(pos_1, pos_2)
- print(f"The {self.name} on the board")
- pass
- def __del__ (self) :
- print(f"The {self.name} is dead")
- pass
- def kill_check(self) :
- i=self.pos[0]+1
- while i<=7:
- if board[i][self.pos[1]]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][self.pos[1]]].name} on {chessPiece[board[i][self.pos[1]]].pos_out[0]}{chessPiece[board[i][self.pos[1]]].pos_out[1]}.")
- break
- i+=1
- i=self.pos[0]-1
- while i>=0:
- if board[i][self.pos[1]]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][self.pos[1]]].name} on {chessPiece[board[i][self.pos[1]]].pos_out[0]}{chessPiece[board[i][self.pos[1]]].pos_out[1]}.")
- break
- i-=1
- i=self.pos[1]+1
- while i<=7:
- if board[self.pos[0]][i]!=-1:
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]][i]].name} on {chessPiece[board[self.pos[0]][i]].pos_out[0]}{chessPiece[board[self.pos[0]][i]].pos_out[1]}.")
- break
- i+=1
- i=self.pos[1]-1
- while i>=0:
- if board[self.pos[0]][i]!=-1:
- print(f"{self.name} can kill {chessPiece[board[self.pos[0]][i]].name} on {chessPiece[board[self.pos[0]][i]].pos_out[0]}{chessPiece[board[self.pos[0]][i]].pos_out[1]}.")
- break
- i-=1
- i=self.pos[0]+1; j=self.pos[1]+1
- while i<=7 or j<=7:
- if board[i][j]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][j]].name} on {chessPiece[board[i][j]].pos_out[0]}{chessPiece[board[i][j]].pos_out[1]}.")
- break
- i+=1; j+=1
- i=self.pos[0]-1; j=self.pos[1]-1
- while i>=0 or j>=0:
- if board[i][j]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][j]].name} on {chessPiece[board[i][j]].pos_out[0]}{chessPiece[board[i][j]].pos_out[1]}.")
- break
- i-=1; j-=1
- i=self.pos[0]-1; j=self.pos[1]+1
- while i>=0 or j<=7:
- if board[i][j]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][j]].name} on {chessPiece[board[i][j]].pos_out[0]}{chessPiece[board[i][j]].pos_out[1]}.")
- break
- i-=1; j+=1
- i=self.pos[0]+1; j=self.pos[1]-1
- while i<=7 or j>=0:
- if board[i][j]!=-1:
- print(f"{self.name} can kill {chessPiece[board[i][j]].name} on {chessPiece[board[i][j]].pos_out[0]}{chessPiece[board[i][j]].pos_out[1]}.")
- break
- i+=1; j-=1
- def checkEmpty(pos) :
- if ord(pos[0]) < 73 :
- pos_1 = ord(pos[0]) - 65
- else :
- pos_1 = ord(pos[0]) - 97
- if board[pos_1][int(pos[1]) - 1] == -1 :
- return True
- else :
- return False
- def chooseOperation() :
- operatoin = ("1 - Add chess piece", "2 - Find kill", "0 - Exit")
- for i in operatoin:
- print(i)
- numOfOperation = int(input())
- return numOfOperation
- chess = ("1 - Queen", "2 - Pawn", "3 - Knight", "0 - Cancel")
- while True :
- choose = chooseOperation()
- if choose == 1 :
- print("Who should I add to the board?")
- for i in chess:
- print(i)
- choosePiece = int(input())
- print("Please use the Latin layout: A-H, a-h, 1-8")
- 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.")
- elif choosePiece == 2 :
- 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(Pawn(coord[0], int(coord[1]) - 1))
- else :
- print("This place is not free.")
- elif choosePiece == 3 :
- 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(Knight(coord[0], int(coord[1]) - 1))
- else :
- print("This place is not free.")
- elif choosePiece == 0 :
- print("Creation canceled!")
- else :
- print("Select the correct option: ")
- elif choose == 2 :
- print("Для какой фигуры ищем цель?")
- for i in range(len(chessPiece)) :
- print(f"{i+1} - {chessPiece[i].name}")
- piece = int(input()) - 1
- chessPiece[piece].kill_check()
- else :
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement