działający next_move i printboard
This commit is contained in:
parent
d5074b0af9
commit
010e4a626c
11
board.py
11
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
|
||||
|
||||
|
||||
|
||||
|
17
game.py
17
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)
|
||||
"""
|
||||
|
||||
|
||||
|
@ -2,6 +2,4 @@ from piece import Piece
|
||||
from square import Square
|
||||
class Knight(Piece):
|
||||
def __init__(self, color):
|
||||
super().__init__("knight", color)
|
||||
|
||||
#test
|
||||
super().__init__("knight", color)
|
51
main.py
51
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('')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user