pat
This commit is contained in:
parent
c4b4c7392f
commit
b8d8a2a1ec
Binary file not shown.
Binary file not shown.
12
main.py
12
main.py
@ -1,14 +1,14 @@
|
|||||||
from game import Game
|
from game import Game
|
||||||
import time
|
#import time
|
||||||
game = Game()
|
game = Game()
|
||||||
game2 = Game()
|
game2 = Game()
|
||||||
game.printBoard()
|
game.printBoard()
|
||||||
game2.printBoard()
|
game2.printBoard()
|
||||||
ruch=None
|
ruch = None
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
#time.sleep(1)
|
||||||
ruch=game.nextMove(ruch)
|
ruch = game.nextMove(ruch)
|
||||||
game.printBoard()
|
game.printBoard()
|
||||||
time.sleep(1)
|
#time.sleep(1)
|
||||||
ruch=game2.nextMove(ruch)
|
ruch = game2.nextMove(ruch)
|
||||||
game2.printBoard()
|
game2.printBoard()
|
33
move.py
33
move.py
@ -40,23 +40,27 @@ class Move:
|
|||||||
#usuwanie ruchów z valid_moves, które mogłyby doprowadzić do szachowania króla
|
#usuwanie ruchów z valid_moves, które mogłyby doprowadzić do szachowania króla
|
||||||
self.boot_piece = []
|
self.boot_piece = []
|
||||||
self.piece_row_column = []
|
self.piece_row_column = []
|
||||||
|
self.number_of_pieces = 0
|
||||||
for r in range(0, 8):
|
for r in range(0, 8):
|
||||||
for c in range(0, 8):
|
for c in range(0, 8):
|
||||||
if self.board.boardlist[r][c].has_piece():
|
if self.board.boardlist[r][c].has_piece():
|
||||||
|
self.number_of_pieces = self.number_of_pieces +1
|
||||||
if self.board.boardlist[r][c].piece.color != color:
|
if self.board.boardlist[r][c].piece.color != color:
|
||||||
self.kopia = []
|
self.kopia = []
|
||||||
for move in self.board.boardlist[r][c].piece.valid_moves:
|
for move in self.board.boardlist[r][c].piece.valid_moves:
|
||||||
if Move.check_szach(self, color, r, c, move[0], move[1]) is False:
|
if Move.check_szach(self, color, r, c, move[0], move[1]) is False:
|
||||||
self.kopia.append(move)
|
self.kopia.append(move)
|
||||||
self.board.boardlist[r][c].piece.valid_moves=self.kopia
|
self.board.boardlist[r][c].piece.valid_moves=self.kopia
|
||||||
|
if self.number_of_pieces == 2:
|
||||||
|
exit(0)
|
||||||
#spis pól z figurami, które mają możliwość ruchu
|
#spis pól z figurami, które mają możliwość ruchu
|
||||||
for r in range(8):
|
for r in range(8):
|
||||||
for c in range(8):
|
for c in range(8):
|
||||||
if self.board.boardlist[r][c].has_piece() and self.board.boardlist[r][c].piece.color != color:
|
if self.board.boardlist[r][c].has_piece() and self.board.boardlist[r][c].piece.color != color:
|
||||||
if (len(self.board.boardlist[r][c].piece.valid_moves)>0):
|
if len(self.board.boardlist[r][c].piece.valid_moves) > 0:
|
||||||
self.boot_piece.append(self.board.boardlist[r][c])
|
self.boot_piece.append(self.board.boardlist[r][c])
|
||||||
if (len(self.boot_piece)==0):
|
#pat
|
||||||
print("MAT")
|
if len(self.boot_piece) == 0:
|
||||||
exit(0)
|
exit(0)
|
||||||
#losowanie figury
|
#losowanie figury
|
||||||
self.value = random.randrange(0, len(self.boot_piece))
|
self.value = random.randrange(0, len(self.boot_piece))
|
||||||
@ -70,8 +74,7 @@ class Move:
|
|||||||
self.move_final_column = self.move_final_square[1]
|
self.move_final_column = self.move_final_square[1]
|
||||||
return self.move_initial_row, self.move_initial_column, self. move_final_row, self.move_final_column #, self.x
|
return self.move_initial_row, self.move_initial_column, self. move_final_row, self.move_final_column #, self.x
|
||||||
def calc_moves(self, piece, row, column):
|
def calc_moves(self, piece, row, column):
|
||||||
#piece.delete_moves()
|
piece.delete_moves()
|
||||||
piece.valid_moves=[]
|
|
||||||
if piece.name == 'rook':
|
if piece.name == 'rook':
|
||||||
Rook.rook_moves(self, piece, row, column)
|
Rook.rook_moves(self, piece, row, column)
|
||||||
pass
|
pass
|
||||||
@ -110,29 +113,29 @@ class Move:
|
|||||||
if self.board.boardlist[r][c].has_piece():
|
if self.board.boardlist[r][c].has_piece():
|
||||||
if self.board.boardlist[r][c].piece.color == color:
|
if self.board.boardlist[r][c].piece.color == color:
|
||||||
Move.calc_moves(self, self.board.boardlist[r][c].piece, r, c)
|
Move.calc_moves(self, self.board.boardlist[r][c].piece, r, c)
|
||||||
elif self.board.boardlist[r][c].piece.name=='king':
|
elif self.board.boardlist[r][c].piece.name == 'king':
|
||||||
self.king_position = (r, c)
|
self.king_position = (r, c)
|
||||||
for r2 in range(8):
|
for r2 in range(8):
|
||||||
for c2 in range(8):
|
for c2 in range(8):
|
||||||
if self.board.boardlist[r2][c2].has_piece():
|
if self.board.boardlist[r2][c2].has_piece():
|
||||||
if self.board.boardlist[r2][c2].piece.color == color:
|
if self.board.boardlist[r2][c2].piece.color == color:
|
||||||
if self.king_position in self.board.boardlist[r2][c2].piece.valid_moves:
|
if self.king_position in self.board.boardlist[r2][c2].piece.valid_moves:
|
||||||
self.board.boardlist[final_row][final_column].piece=self.previous_piece
|
self.board.boardlist[final_row][final_column].piece = self.previous_piece
|
||||||
self.board.boardlist[initial_row][initial_column].piece= self.piece
|
self.board.boardlist[initial_row][initial_column].piece = self.piece
|
||||||
for rowxd2 in range(8):
|
for rowxd2 in range(8):
|
||||||
for columnxd2 in range(8):
|
for columnxd2 in range(8):
|
||||||
if self.board.boardlist[rowxd2][columnxd2].has_piece():
|
if self.board.boardlist[rowxd2][columnxd2].has_piece():
|
||||||
if self.board.boardlist[rowxd2][columnxd2].piece.color == color:
|
if self.board.boardlist[rowxd2][columnxd2].piece.color == color:
|
||||||
Move.calc_moves(self, self.board.boardlist[rowxd2][columnxd2].piece, rowxd2,columnxd2)
|
Move.calc_moves(self, self.board.boardlist[rowxd2][columnxd2].piece, rowxd2, columnxd2)
|
||||||
return True
|
return True
|
||||||
self.board.boardlist[final_row][final_column].piece = self.previous_piece
|
self.board.boardlist[final_row][final_column].piece = self.previous_piece
|
||||||
self.board.boardlist[initial_row][initial_column].piece = self.piece
|
self.board.boardlist[initial_row][initial_column].piece = self.piece
|
||||||
for rowxd in range(8):
|
for r3 in range(8):
|
||||||
for columnxd in range(8):
|
for c3 in range(8):
|
||||||
if self.board.boardlist[rowxd][columnxd].has_piece():
|
if self.board.boardlist[r3][c3].has_piece():
|
||||||
if self.board.boardlist[rowxd][columnxd].has_piece():
|
if self.board.boardlist[r3][c3].has_piece():
|
||||||
if self.board.boardlist[rowxd][columnxd].piece.color == color:
|
if self.board.boardlist[r3][c3].piece.color == color:
|
||||||
Move.calc_moves(self, self.board.boardlist[rowxd][columnxd].piece, rowxd, columnxd)
|
Move.calc_moves(self, self.board.boardlist[r3][c3].piece, r3, c3)
|
||||||
return False
|
return False
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def numbers_to_letters(number):
|
def numbers_to_letters(number):
|
||||||
|
Loading…
Reference in New Issue
Block a user