From 010e4a626cdd02cc9725ed446da889280645aa6d Mon Sep 17 00:00:00 2001 From: Agata Halik Date: Thu, 8 Jun 2023 21:37:15 +0200 Subject: [PATCH] =?UTF-8?q?dzia=C5=82aj=C4=85cy=20next=5Fmove=20i=20printb?= =?UTF-8?q?oard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- board.py | 11 +++++++---- game.py | 17 ++++++++++++++++- knight.py | 4 +--- main.py | 51 ++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/board.py b/board.py index fc405d6..cc07ff9 100644 --- a/board.py +++ b/board.py @@ -162,7 +162,6 @@ 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 @@ -174,8 +173,7 @@ class Board: 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 0 - + return self.board.boardlist[to_row][to_column].piece.color def move_boot(self, color): self.boot_piece = [] self.piece_row_column = [] @@ -189,6 +187,9 @@ class Board: self.value = random.randrange(0, len(self.boot_piece)) self.initial = self.boot_piece[self.value] while len(self.initial.piece.valid_moves) == 0: + #print('xddd') + #print(self.initial.piece) + #print(self.initial.piece.valid_moves) self.value = random.randrange(0, len(self.boot_piece)) self.initial = self.boot_piece[self.value] self.initial_row=self.initial.row @@ -217,7 +218,9 @@ class Board: #print(self.board.boardlist[self.final_row][self.final_column].piece.name) #print(self.initial_row, self.initial_column) #print(self.final_row, self.final_column) - return 0 + + self.ruch = str(self.initial_row) + str(self.initial_column) + ' ' + str(self.final_row) + str(self.final_column) + return self.ruch diff --git a/game.py b/game.py index f96fceb..358c0d8 100644 --- a/game.py +++ b/game.py @@ -5,7 +5,7 @@ class Game: def __init__(self): self.board = Board() - def show_board(self): + def printBoard(self): self.b = [] for row in range(8): if row==0: self.b.append('0') @@ -79,6 +79,19 @@ class Game: # R #print(self.board.boardlist[5][1].piece.color) #print(self.board.boardlist[5][1].piece.valid_moves) + def nextMove(self, ruch): + if ruch == 'noone': + return Board.move_boot(self, 'white') + + else: + self.from_row = int(ruch[0]) + self.from_column=int(ruch[1]) + self.to_row=int(ruch[3]) + self.to_column=int(ruch[4]) + 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) + + """ def make_move_rival(self): self.przeciwnik = input(str('Podaj ruch: ')) self.from_row = int(self.przeciwnik[0]) @@ -88,4 +101,6 @@ class Game: return Board.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column) def make_move_boot(self, color): return Board.move_boot(self, color) + """ + diff --git a/knight.py b/knight.py index c35740e..537ceea 100644 --- a/knight.py +++ b/knight.py @@ -2,6 +2,4 @@ from piece import Piece from square import Square class Knight(Piece): def __init__(self, color): - super().__init__("knight", color) - -#test \ No newline at end of file + super().__init__("knight", color) \ No newline at end of file diff --git a/main.py b/main.py index 30f14ad..1ea4572 100644 --- a/main.py +++ b/main.py @@ -2,27 +2,52 @@ from game import Game #def mainloop(self): # game = self.game game = Game() -game.show_board() +game2 = Game() +game.printBoard() +print('') +game2.printBoard() +print('') boot_color = 'white' #11 21 a=0 +ruch='noone' while True: + print('') + a=a+1 + print(a) + ruch = game.nextMove(ruch) + if(ruch==1): + game.printBoard() + print(game) + exit(0) + game.printBoard() + print('') a = a + 1 print(a) - if game.make_move_boot('white') == 1: - print("Przegrana") - game.show_board() - break + ruch = game2.nextMove(ruch) + if (ruch == 1): + game2.printBoard() + print(game2) + exit(0) + game2.printBoard() + + + # a = a + 1 + #print(a) + #if game.make_move_boot('white') == 1: + # print("Przegrana") + # game.show_board() + # break #if game.make_move_rival()==1: # print("Przegrana") # break - game.show_board() - print('') - if game.make_move_boot('black') == 1: - print("Przegrana") - game.show_board() - break - game.show_board() - print('') + #game.show_board() + #print('') + #if game.make_move_boot('black') == 1: + # print("Przegrana") + # game.show_board() + # break + #game.show_board() + #print('')