działający next_move i printboard

This commit is contained in:
Agata Halik 2023-06-08 21:37:15 +02:00
parent d5074b0af9
commit 010e4a626c
4 changed files with 62 additions and 21 deletions

View File

@ -162,7 +162,6 @@ class Board:
straightline_moves(False) straightline_moves(False)
elif piece.name == 'king': elif piece.name == 'king':
king_moves() king_moves()
def move_rival(self, from_row, from_column, to_row, to_column): def move_rival(self, from_row, from_column, to_row, to_column):
#update #update
self.x = self.board.boardlist[from_row][from_column].piece 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 = self.x
self.board.boardlist[to_row][to_column].piece.moved = True self.board.boardlist[to_row][to_column].piece.moved = True
self.board.boardlist[to_row][to_column].piece.delete_moves() 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): def move_boot(self, color):
self.boot_piece = [] self.boot_piece = []
self.piece_row_column = [] self.piece_row_column = []
@ -189,6 +187,9 @@ class Board:
self.value = random.randrange(0, len(self.boot_piece)) self.value = random.randrange(0, len(self.boot_piece))
self.initial = self.boot_piece[self.value] self.initial = self.boot_piece[self.value]
while len(self.initial.piece.valid_moves) == 0: 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.value = random.randrange(0, len(self.boot_piece))
self.initial = self.boot_piece[self.value] self.initial = self.boot_piece[self.value]
self.initial_row=self.initial.row 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.board.boardlist[self.final_row][self.final_column].piece.name)
#print(self.initial_row, self.initial_column) #print(self.initial_row, self.initial_column)
#print(self.final_row, self.final_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

17
game.py
View File

@ -5,7 +5,7 @@ class Game:
def __init__(self): def __init__(self):
self.board = Board() self.board = Board()
def show_board(self): def printBoard(self):
self.b = [] self.b = []
for row in range(8): for row in range(8):
if row==0: self.b.append('0') if row==0: self.b.append('0')
@ -79,6 +79,19 @@ class Game:
# R # R
#print(self.board.boardlist[5][1].piece.color) #print(self.board.boardlist[5][1].piece.color)
#print(self.board.boardlist[5][1].piece.valid_moves) #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): def make_move_rival(self):
self.przeciwnik = input(str('Podaj ruch: ')) self.przeciwnik = input(str('Podaj ruch: '))
self.from_row = int(self.przeciwnik[0]) 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) return Board.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column)
def make_move_boot(self, color): def make_move_boot(self, color):
return Board.move_boot(self, color) return Board.move_boot(self, color)
"""

View File

@ -3,5 +3,3 @@ from square import Square
class Knight(Piece): class Knight(Piece):
def __init__(self, color): def __init__(self, color):
super().__init__("knight", color) super().__init__("knight", color)
#test

51
main.py
View File

@ -2,27 +2,52 @@ from game import Game
#def mainloop(self): #def mainloop(self):
# game = self.game # game = self.game
game = Game() game = Game()
game.show_board() game2 = Game()
game.printBoard()
print('')
game2.printBoard()
print('')
boot_color = 'white' boot_color = 'white'
#11 21 #11 21
a=0 a=0
ruch='noone'
while True: 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 a = a + 1
print(a) print(a)
if game.make_move_boot('white') == 1: ruch = game2.nextMove(ruch)
print("Przegrana") if (ruch == 1):
game.show_board() game2.printBoard()
break 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: #if game.make_move_rival()==1:
# print("Przegrana") # print("Przegrana")
# break # break
game.show_board() #game.show_board()
print('') #print('')
if game.make_move_boot('black') == 1: #if game.make_move_boot('black') == 1:
print("Przegrana") # print("Przegrana")
game.show_board() # game.show_board()
break # break
game.show_board() #game.show_board()
print('') #print('')