class move
This commit is contained in:
parent
24efbe7396
commit
6f53b72324
Binary file not shown.
Binary file not shown.
41
game.py
41
game.py
@ -77,46 +77,7 @@ class Game:
|
||||
|
||||
if ruch == None:
|
||||
return Move.move_boot(self, 'black')
|
||||
|
||||
else:
|
||||
self.from_column = ruch[0]
|
||||
self.from_row = int(ruch[1])
|
||||
self.to_column = ruch[3]
|
||||
self.to_row = int(ruch[4])
|
||||
|
||||
if self.from_column == 'A':
|
||||
self.from_column = 0
|
||||
elif self.from_column == 'B':
|
||||
self.from_column = 1
|
||||
elif self.from_column == 'C':
|
||||
self.from_column = 2
|
||||
elif self.from_column == 'D':
|
||||
self.from_column = 3
|
||||
elif self.from_column == 'E':
|
||||
self.from_column = 4
|
||||
elif self.from_column == 'F':
|
||||
self.from_column = 5
|
||||
elif self.from_column == 'G':
|
||||
self.from_column = 6
|
||||
elif self.from_column == 'H':
|
||||
self.from_column = 7
|
||||
|
||||
if self.to_column == 'A':
|
||||
self.to_column = 0
|
||||
elif self.to_column == 'B':
|
||||
self.to_column = 1
|
||||
elif self.to_column == 'C':
|
||||
self.to_column = 2
|
||||
elif self.to_column == 'D':
|
||||
self.to_column = 3
|
||||
elif self.to_column == 'E':
|
||||
self.to_column = 4
|
||||
elif self.to_column == 'F':
|
||||
self.to_column = 5
|
||||
elif self.to_column == 'G':
|
||||
self.to_column = 6
|
||||
elif self.to_column == 'H':
|
||||
self.to_column = 7
|
||||
self.color = Move.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column)
|
||||
self.color = Move.move_rival(self, ruch)
|
||||
return Move.move_boot(self, self.color)
|
||||
|
||||
|
66
move.py
66
move.py
@ -9,19 +9,27 @@ from king import King
|
||||
import random
|
||||
|
||||
class Move:
|
||||
@staticmethod
|
||||
def move_rival(self, from_row, from_column, to_row, to_column):
|
||||
|
||||
def move_rival(self, ruch):
|
||||
self.from_column = ruch[0]
|
||||
self.from_row = int(ruch[1])
|
||||
self.to_column = ruch[3]
|
||||
self.to_row = int(ruch[4])
|
||||
|
||||
self.to_column = Move.letters_to__numbers(self.to_column)
|
||||
self.from_column = Move.letters_to__numbers(self.from_column)
|
||||
|
||||
#update
|
||||
self.x = self.board.boardlist[from_row][from_column].piece
|
||||
self.board.boardlist[from_row][from_column].piece = None
|
||||
if (self.board.boardlist[to_row][to_column].has_piece()):
|
||||
if (self.board.boardlist[to_row][to_column].piece.name == 'king'):
|
||||
self.board.boardlist[to_row][to_column].piece = self.x
|
||||
self.x = self.board.boardlist[self.from_row][self.from_column].piece
|
||||
self.board.boardlist[self.from_row][self.from_column].piece = None
|
||||
if (self.board.boardlist[self.to_row][self.to_column].has_piece()):
|
||||
if (self.board.boardlist[self.to_row][self.to_column].piece.name == 'king'):
|
||||
self.board.boardlist[self.to_row][self.to_column].piece = self.x
|
||||
exit(0)
|
||||
self.board.boardlist[to_row][to_column].piece = self.x
|
||||
self.board.boardlist[to_row][to_column].piece.moved = True
|
||||
self.board.boardlist[to_row][to_column].piece.delete_moves()
|
||||
return self.board.boardlist[to_row][to_column].piece.color
|
||||
self.board.boardlist[self.to_row][self.to_column].piece = self.x
|
||||
self.board.boardlist[self.to_row][self.to_column].piece.moved = True
|
||||
self.board.boardlist[self.to_row][self.to_column].piece.delete_moves()
|
||||
return self.board.boardlist[self.to_row][self.to_column].piece.color
|
||||
def move_boot(self, color):
|
||||
self.boot_piece = []
|
||||
self.piece_row_column = []
|
||||
@ -49,10 +57,13 @@ class Move:
|
||||
self.board.boardlist[self.final_row][self.final_column].piece = self.x
|
||||
exit(0)
|
||||
self.board.boardlist[self.final_row][self.final_column].piece = self.x
|
||||
|
||||
#pawn promotion
|
||||
if isinstance(self.x, Pawn):
|
||||
if (self.final_row==0) or (self.final_row==7):
|
||||
self.board.boardlist[self.final_row][self.final_column].piece = Queen(self.x.color)
|
||||
Move.pawn_promotion(self, self.x, self.final_row, self.final_column)
|
||||
#if isinstance(self.x, Pawn):
|
||||
# if (self.final_row==0) or (self.final_row==7):
|
||||
# self.board.boardlist[self.final_row][self.final_column].piece = Queen(self.x.color)
|
||||
|
||||
self.board.boardlist[self.final_row][self.final_column].piece.moved = True
|
||||
self.board.boardlist[self.final_row][self.final_column].piece.delete_moves()
|
||||
#zmiana ruchu na litery
|
||||
@ -61,7 +72,12 @@ class Move:
|
||||
|
||||
self.ruch = str(self.initial_column) + str(self.initial_row) + ' ' + str(self.final_column) + str(self.final_row)
|
||||
return self.ruch
|
||||
|
||||
def pawn_promotion(self, x, final_row, final_column):
|
||||
if isinstance(x, Pawn):
|
||||
if (final_row==0) or (final_row==7):
|
||||
self.board.boardlist[final_row][final_column].piece = Queen(x.color)
|
||||
|
||||
@staticmethod
|
||||
def numbers_to_letters(number):
|
||||
if number == 0:
|
||||
number = "A"
|
||||
@ -80,3 +96,23 @@ class Move:
|
||||
elif number == 7:
|
||||
number = "H"
|
||||
return number
|
||||
|
||||
@staticmethod
|
||||
def letters_to__numbers(letter):
|
||||
if letter == 'A':
|
||||
letter = 0
|
||||
elif letter == 'B':
|
||||
letter=1
|
||||
elif letter == 'C':
|
||||
letter = 2
|
||||
elif letter == 'D':
|
||||
letter = 3
|
||||
elif letter == 'E':
|
||||
letter = 4
|
||||
elif letter == 'F':
|
||||
letter = 5
|
||||
elif letter == 'G':
|
||||
letter = 6
|
||||
elif letter == 'H':
|
||||
letter = 7
|
||||
return letter
|
||||
|
Loading…
Reference in New Issue
Block a user