From b8d8a2a1ec72c65a4943bea872b6d132562e22da Mon Sep 17 00:00:00 2001 From: Agata Halik Date: Tue, 20 Jun 2023 16:04:46 +0200 Subject: [PATCH] pat --- __pycache__/move.cpython-310.pyc | Bin 5119 -> 5157 bytes __pycache__/piece.cpython-310.pyc | Bin 951 -> 804 bytes main.py | 12 +++++------ move.py | 33 ++++++++++++++++-------------- piece.py | 2 -- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/__pycache__/move.cpython-310.pyc b/__pycache__/move.cpython-310.pyc index 18287316d11e1afd862627f2ce59012754071200..59fbec1f12a107ccdca3511ef48a8fb996e4ec93 100644 GIT binary patch delta 808 zcmZvZ&ubG=5XaxV-Rx#JyZKo)(H4s$P1`8eDCj{@tkD=j#Gh13#B7vov@tKMC~T;Z zgBLF{2feuwiiey^6+DP1_0s>K=pWFdHxCt^m#En2F8g`&<~uWQcHWPPrL5hsZIjXS zdikldx@^A;Ep7l~x0uh$1A+r&b5C)=;T=B9=C8E>-kobJK66z!7b@*o8)!ncUbwxP+Q;Z?i)?JehNw-xm5?DB??O41@Ax2>PY8QYtkICIol3q5O zTbfbwawk;hqTxjy=ukAZ%{xH#j`W)z*a!aGa&NfiuQq#^z1TmJ*`c}ARUwlYwYF&j z{Wc#qTm3xNkL2R*pO)f5!T~RaG5t_RR!-4Gs9u-mR8Ich8bs+G0SnS(r(v8d{%9+G z{F`Zn!QvL=V3ZW{e2<1OYZMNyQL+yK>oTC#mH)>@%HsjuuMa-=m97fRVHXA}Cv_JF z#u&`td*X5YZ0v+j{D6L>_*>Qikzjgtt=r7n2UUX>-aVDEIvgJk(4+pu@9eH zd%;=xWUX^;QhKKFO>6?D@k^{Y%0+&TSMnkwg+8`RD@UlUl;UH+MHbz}d3b{F5|8sI wq$p1mvl5oXNeNrxlte+IC?Q8C&fxvzwDv-pC47~vKn^3Rg0d$(f)`W0pRVM#j{pDw delta 749 zcmZvZ&ubG=5XaxV{gK_xZklXrX~bfBkhVrqTSPnvRckc1A_WVQP(ta}(rr!5bHykd zD&`>G3UiQ34~fu=J(d0omY&3`^d#b?2ai4UAUbcWV57UtXJ_Wk%=^B#>w`ZBoT}qk zjGpbcE8fdZ=bg6v1sI!WAuAse0`7swn|zE-Pd4~pQK6xP%vXFh%S#xV~lEa%o zBQ8hM4*lW(3R~@*@LSkw;B>A`_+}G4SX6~2BRWF+PhGw4!q7>OI_vW$_?3l~R`GD!bYvu}}$i z)w%jYfcK5<;cN7hbgn~!-frjxoh%DB@E1K~{J=JCI0GjrOVN*nY5-1|`R>ouMmG;- zGGCsF3l}%dKIq3!#Pj%_IEr!WBor}cjew73YaCAFhP58QMa_=~qm8i?{{YjNwcjL% zC?Q;lD-!2$$36=)Tl@AN*JZI7!f#yzG{R06PHCe0wC)v++3M1hhn2b~GO{AVap~m< z54LK_KHz&CS5lMk8o#Dqjf}~~>k>C4Y>B*tBO!%}n-aGr3KHYE=H~P@=}zEBcNTJZ OA)QzHjbr#cz3~fRf~)8N diff --git a/__pycache__/piece.cpython-310.pyc b/__pycache__/piece.cpython-310.pyc index e68cd182529e0d1ee512132aff2b6298a3714584..abeb6f7c273d06a4eafd8517480c1f923d75af90 100644 GIT binary patch delta 109 zcmdnazJ!f8pO=@50SH#Do|v*^BCkKA%EVYzmS6@=j*WeOjEtI-?=sF~ES_A$B*pBf p$u?P*S<8?gsJuu3L~x=KAcKk+fdmK_a{vhr1`b9J&dK%6762!M6LbIo delta 250 zcmZ3&ww;|fpO=@50SFGvoRIQnBCkKA&cs+%o)nH2hA6fa&R_;ju8nPejEpNMUuB$E z|CtG>l8doQC?GR6IaMzuH7B(sH9j}LEVVcpBn1N?HV8WdaWTmF8paxic!m^)V1^{ lWS=~dNsC(mWR@U^5T1OHNs$L+A_oHpBL^o3)8scy763f{IpP2S diff --git a/main.py b/main.py index 68cddeb..2e2acc2 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,14 @@ from game import Game -import time +#import time game = Game() game2 = Game() game.printBoard() game2.printBoard() -ruch=None +ruch = None while True: - time.sleep(1) - ruch=game.nextMove(ruch) + #time.sleep(1) + ruch = game.nextMove(ruch) game.printBoard() - time.sleep(1) - ruch=game2.nextMove(ruch) + #time.sleep(1) + ruch = game2.nextMove(ruch) game2.printBoard() \ No newline at end of file diff --git a/move.py b/move.py index 8edc2a1..c230bd0 100644 --- a/move.py +++ b/move.py @@ -40,23 +40,27 @@ class Move: #usuwanie ruchów z valid_moves, które mogłyby doprowadzić do szachowania króla self.boot_piece = [] self.piece_row_column = [] + self.number_of_pieces = 0 for r in range(0, 8): for c in range(0, 8): 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: self.kopia = [] 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: self.kopia.append(move) 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 for r 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 (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]) - if (len(self.boot_piece)==0): - print("MAT") + #pat + if len(self.boot_piece) == 0: exit(0) #losowanie figury self.value = random.randrange(0, len(self.boot_piece)) @@ -70,8 +74,7 @@ class Move: 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 def calc_moves(self, piece, row, column): - #piece.delete_moves() - piece.valid_moves=[] + piece.delete_moves() if piece.name == 'rook': Rook.rook_moves(self, piece, row, column) pass @@ -110,29 +113,29 @@ class Move: if self.board.boardlist[r][c].has_piece(): if self.board.boardlist[r][c].piece.color == color: 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) for r2 in range(8): for c2 in range(8): if self.board.boardlist[r2][c2].has_piece(): if self.board.boardlist[r2][c2].piece.color == color: 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[initial_row][initial_column].piece= self.piece + self.board.boardlist[final_row][final_column].piece = self.previous_piece + self.board.boardlist[initial_row][initial_column].piece = self.piece for rowxd2 in range(8): for columnxd2 in range(8): if self.board.boardlist[rowxd2][columnxd2].has_piece(): 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 self.board.boardlist[final_row][final_column].piece = self.previous_piece self.board.boardlist[initial_row][initial_column].piece = self.piece - for rowxd in range(8): - for columnxd in range(8): - if self.board.boardlist[rowxd][columnxd].has_piece(): - if self.board.boardlist[rowxd][columnxd].has_piece(): - if self.board.boardlist[rowxd][columnxd].piece.color == color: - Move.calc_moves(self, self.board.boardlist[rowxd][columnxd].piece, rowxd, columnxd) + for r3 in range(8): + for c3 in range(8): + if self.board.boardlist[r3][c3].has_piece(): + if self.board.boardlist[r3][c3].has_piece(): + if self.board.boardlist[r3][c3].piece.color == color: + Move.calc_moves(self, self.board.boardlist[r3][c3].piece, r3, c3) return False @staticmethod def numbers_to_letters(number): diff --git a/piece.py b/piece.py index 2129cd7..b3ab6a0 100644 --- a/piece.py +++ b/piece.py @@ -12,7 +12,5 @@ class Piece: self.valid_moves.append(move) def delete_moves(self): self.valid_moves = [] - def change_where_king(self, move): - self.where_king = move