From 24efbe7396475b3fb6e04a0486de31c0f0d2d000 Mon Sep 17 00:00:00 2001 From: Agata Halik Date: Fri, 9 Jun 2023 22:48:38 +0200 Subject: [PATCH] class move --- __pycache__/board.cpython-310.pyc | Bin 6091 -> 4134 bytes __pycache__/game.cpython-310.pyc | Bin 2717 -> 2750 bytes __pycache__/move.cpython-310.pyc | Bin 3380 -> 2557 bytes board.py | 81 ----------------------------- game.py | 8 +-- main.py | 2 + move.py | 82 ++++++++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 85 deletions(-) diff --git a/__pycache__/board.cpython-310.pyc b/__pycache__/board.cpython-310.pyc index e0048ffe196450220308ac927b9a052d1edaadf6..bd981b934d6f992e13ad60887bd7393ef808aa23 100644 GIT binary patch delta 288 zcmX@Dzf6HIpO=@50SI1nH>W7cPUL&fs50@NDoZefCdX!T#^oH0QJe2`sxlet0o4>S z0tro)l}ts_ARdSSvcWPS0wxY+>rFQ2vE|kTsZ<3KTAS;6iW#|eKx|zQp+ETtuMBsH zTahV{r^#4kF8bq*x2zwC04k8>t1jyW5 PY(7%Q6rNe{Zr1kNj-APm)BGV3MTRyJ3O|C9(xz#O1d4~L=Ku%}NGQD`ap%B+6MNx`kPt^CBr4u}y9utV!dmm*oA14u`S!i> z+b zZFL3KC=Q~gf2FB2I70z8c~G3-slC!$ve)v@VdNr;=Z^!s!_9MOFZX^g%#5m+z~0_e zFN3Oa^=eNPALh@Z|1}indp{MgM@<9llLze#jLR@O--9@09`pDiud+j}$~^6mIT<;G zI)GAC2BP#T>+45Mz4AEbX`UhZjz)N9z!$*+M+;4ijHmUj zBSx!{Y)S);%tD&=Ep-WAgmSxG%f-fxprNE1Lu`q$h$$OQ%Huj%vF;wULRCZ4mTub( zU1vAA<95^nKs7^+qsO|bf?Y=iAH;dGnn8Pi*N@FGATSF$ffU|`L=rSKn zIm|ne04cNz7kmna1w-%&7rbWNS>2O9%_<9LbVNc z{oFlmV77P=6hh#5mf4S<#s-_`dP`t99E;t zkMMHj(T0(S?U`ef&-M(j(B)MA-QhLS|1auXgAHx32$3bSM!_l%Y?K~wN`U64Br0H4 zB;H`=jFF8OggFB2j2G#kN(gvmNQVKAak}96z5^ZyJd^|GjZw6Ki#`Dt{pTlfc;88> z!(~U`_>+Fe2&W`Z?tAo|cTKvdj>+DlNj!6P6`xO+xh{?ghf~gk6<3 zVM~M+2zy6j`O5w*VI{)elTgSAK&(nxmI-tv)C;gIVac2N5+a;3AR?uAK=cIB6Dhrq zh@S9~o{$N>Pl=u&dO{}jJ|lXrLU)UBprx*hXNF<)0R zV8{Hjnj^iT=1E^sv!pjwmGsq^zxfwms4diUH-aE^_F8V!t&ftzo^;ZWDiEzUP*4ku zpa(K)ZL!(d+jD&xo2uc>P^oRhcVD(21M?wh4-V7vVPn4S0%cA8LOKqsXx# zgM5_BM1zZU8u3Q8bd OGYhBhg6REPy6_J!lI>jp diff --git a/__pycache__/game.cpython-310.pyc b/__pycache__/game.cpython-310.pyc index ad1ee177b1dd3e8eb1a1df3e5a869bb031f76385..752b41b52d5b21f5b1633b9db4398df96560716f 100644 GIT binary patch delta 564 zcmZvYKTE?<6vcD%l4lYVkzz#$Q74Vn`WHn}K|usX7Y88-Qu=}l`BR>)x(U|NrDSsO zQxsPRKSnl3zk!qZP8@_{h94*QUe3Gsyp-R{Ug~*{ratefEtWgp*zuD35t^V#izy(2 z)+0S;0V_0%jKJ8}gdxmFO_*&xFa21#IY1E1n*{3SMu+VcF@+xT-?soUg?57

YU6vlIJl53JSh?U@EwTl|1R1wiiaVUaNaq1vsk95NL>@2o@rkm`tI%KR CB4D`y diff --git a/__pycache__/move.cpython-310.pyc b/__pycache__/move.cpython-310.pyc index b95978dd9528e19521e7b923dba8ffcb58544ec9..fad87f4f7e7e1a040586ff3f9267111079ec4cf0 100644 GIT binary patch literal 2557 zcmb7GNpIUm6rSNGN}?9aikGZT(E`z-L4Y1w6h+W1ZHfdj(l{p~1tDt~n-nS9LpqD$ z00ER!4{d*feeA#J-{@R>(zPhs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m~4%^&cPppf_Bff!FbMtD3*`B;veD9hh=3WX@vyvQB*EAOE`gh1#lAbQ8NW}@ zO(QAnjS5mptGAZU(uTXDlogEZwYsUUK-I61pnIjCCPB~5hUYHmG&*$7LGvI&!fR+JNfR=e;9Jn}_Me?E?OY1)A_} Tx9LT?CIyjX$lSd;EbHF?`Z?Zj diff --git a/board.py b/board.py index f01c3f5..01de96d 100644 --- a/board.py +++ b/board.py @@ -162,84 +162,3 @@ class Board: straightline_moves(False) elif piece.name == 'king': king_moves() - def move_rival(self, from_row, from_column, to_row, to_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 - 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 - def move_boot(self, color): - self.boot_piece = [] - self.piece_row_column = [] - for r in range(0, 8): - for c in range(0, 8): - if self.board.boardlist[r][c].piece != None: - if self.board.boardlist[r][c].piece.color != color: - self.boot_piece.append(self.board.boardlist[r][c]) - - self.value = random.randrange(0, len(self.boot_piece)) - self.initial = self.boot_piece[self.value] - while len(self.initial.piece.valid_moves) == 0: - self.value = random.randrange(0, len(self.boot_piece)) - self.initial = self.boot_piece[self.value] - self.initial_row=self.initial.row - self.initial_column = self.initial.column - self.value = random.randrange(0, len(self.initial.piece.valid_moves)) - self.final = self.initial.piece.valid_moves[self.value] - self.final_row = self.final[0] - self.final_column = self.final[1] - self.x = self.board.boardlist[self.initial_row][self.initial_column].piece - self.board.boardlist[self.initial_row][self.initial_column].piece = None - if (self.board.boardlist[self.final_row][self.final_column].has_piece()): - if (self.board.boardlist[self.final_row][self.final_column].piece.name== 'king'): - 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) - self.board.boardlist[self.final_row][self.final_column].piece.moved = True - self.board.boardlist[self.final_row][self.final_column].piece.delete_moves() - - if self.initial_column == 0: - self.initial_column = "A" - elif self.initial_column == 1: - self.initial_column = "B" - elif self.initial_column == 2: - self.initial_column = "C" - elif self.initial_column == 3: - self.initial_column = "D" - elif self.initial_column == 4: - self.initial_column = "E" - elif self.initial_column == 5: - self.initial_column = "F" - elif self.initial_column == 6: - self.initial_column = "G" - elif self.initial_column == 7: - self.initial_column = "H" - - if self.final_column == 0: - self.final_column = "A" - elif self.final_column == 1: - self.final_column = "B" - elif self.final_column == 2: - self.final_column = "C" - elif self.final_column == 3: - self.final_column = "D" - elif self.final_column == 4: - self.final_column = "E" - elif self.final_column == 5: - self.final_column = "F" - elif self.final_column == 6: - self.final_column = "G" - elif self.final_column == 7: - self.final_column = "H" - self.ruch = str(self.initial_column) + str(self.initial_row) + ' ' + str(self.final_column) + str(self.final_row) - return self.ruch \ No newline at end of file diff --git a/game.py b/game.py index 2956a30..5ac998d 100644 --- a/game.py +++ b/game.py @@ -1,4 +1,5 @@ from board import Board +from move import Move import random class Game: @@ -75,7 +76,7 @@ class Game: self.currently_available_moves() if ruch == None: - return Board.move_boot(self, 'black') + return Move.move_boot(self, 'black') else: self.from_column = ruch[0] @@ -116,7 +117,6 @@ class Game: self.to_column = 6 elif self.to_column == 'H': self.to_column = 7 - - self.color = Board.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column) - return Board.move_boot(self, self.color) + self.color = Move.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column) + return Move.move_boot(self, self.color) diff --git a/main.py b/main.py index 9dda397..9e9e2c3 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,9 @@ game.printBoard() game2.printBoard() ruch=None while True: + #print(ruch) ruch = game.nextMove(ruch) game.printBoard() + #print(ruch) ruch = game2.nextMove(ruch) game2.printBoard() diff --git a/move.py b/move.py index e69de29..fd75309 100644 --- a/move.py +++ b/move.py @@ -0,0 +1,82 @@ +from board import Board +from square import Square +from pawn import Pawn +from knight import Knight +from bishop import Bishop +from rook import Rook +from queen import Queen +from king import King +import random + +class Move: + @staticmethod + def move_rival(self, from_row, from_column, to_row, to_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 + 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 + def move_boot(self, color): + self.boot_piece = [] + self.piece_row_column = [] + for r in range(0, 8): + for c in range(0, 8): + if self.board.boardlist[r][c].piece != None: + if self.board.boardlist[r][c].piece.color != color: + self.boot_piece.append(self.board.boardlist[r][c]) + + self.value = random.randrange(0, len(self.boot_piece)) + self.initial = self.boot_piece[self.value] + while len(self.initial.piece.valid_moves) == 0: + self.value = random.randrange(0, len(self.boot_piece)) + self.initial = self.boot_piece[self.value] + self.initial_row=self.initial.row + self.initial_column = self.initial.column + self.value = random.randrange(0, len(self.initial.piece.valid_moves)) + self.final = self.initial.piece.valid_moves[self.value] + self.final_row = self.final[0] + self.final_column = self.final[1] + self.x = self.board.boardlist[self.initial_row][self.initial_column].piece + self.board.boardlist[self.initial_row][self.initial_column].piece = None + if (self.board.boardlist[self.final_row][self.final_column].has_piece()): + if (self.board.boardlist[self.final_row][self.final_column].piece.name== 'king'): + 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) + 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 + self.initial_column=Move.numbers_to_letters(self.initial_column) + self.final_column=Move.numbers_to_letters(self.final_column) + + self.ruch = str(self.initial_column) + str(self.initial_row) + ' ' + str(self.final_column) + str(self.final_row) + return self.ruch + + def numbers_to_letters(number): + if number == 0: + number = "A" + elif number == 1: + number = "B" + elif number == 2: + number = "C" + elif number == 3: + number = "D" + elif number == 4: + number = "E" + elif number == 5: + number = "F" + elif number == 6: + number = "G" + elif number == 7: + number = "H" + return number