92 lines
3.9 KiB
Python
92 lines
3.9 KiB
Python
from board import Board
|
|
import random
|
|
|
|
class Game:
|
|
def __init__(self):
|
|
self.board = Board()
|
|
|
|
def show_board(self):
|
|
self.b = []
|
|
for row in range(8):
|
|
if row==0: self.b.append('0')
|
|
if row == 1: self.b.append('1')
|
|
if row==2: self.b.append('2')
|
|
if row == 3: self.b.append('3')
|
|
if row==4: self.b.append('4')
|
|
if row == 5: self.b.append('5')
|
|
if row==6: self.b.append('6')
|
|
if row == 7: self.b.append('7')
|
|
for column in range(8):
|
|
if self.board.boardlist[row][column].has_piece():
|
|
self.piece = self.board.boardlist[row][column].piece.name
|
|
self.color=self.board.boardlist[row][column].piece.color
|
|
if self.piece == 'rook':
|
|
if self.color=='white':
|
|
self.b.append('r')
|
|
else: self.b.append('R')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
elif self.piece == 'pawn':
|
|
if self.color=='white':
|
|
self.b.append('p')
|
|
else:
|
|
self.b.append('P')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
elif self.piece == 'knight':
|
|
if self.color=='white':
|
|
self.b.append('h')
|
|
else:
|
|
self.b.append('H')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
elif self.piece == 'bishop':
|
|
if self.color=='white':
|
|
self.b.append('b')
|
|
else:
|
|
self.b.append('B')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
elif self.piece == 'queen':
|
|
if self.color=='white':
|
|
self.b.append('q')
|
|
else:
|
|
self.b.append('Q')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
elif self.piece == 'king':
|
|
if self.color=='white':
|
|
self.b.append('k')
|
|
else:
|
|
self.b.append('K')
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
else:
|
|
# wyswietla puste miejsca
|
|
self.b.append(' ')
|
|
print(self.b)
|
|
self.b = []
|
|
self.b.append(' ')
|
|
self.b.append('0')
|
|
self.b.append('1')
|
|
self.b.append('2')
|
|
self.b.append('3')
|
|
self.b.append('4')
|
|
self.b.append('5')
|
|
self.b.append('6')
|
|
self.b.append('7')
|
|
print(self.b)
|
|
# sprawdzenie
|
|
# H
|
|
# self.board.calc_moves(self.board.boardlist[7][6].piece, 7, 6)
|
|
# print(self.board.boardlist[7][6].piece.valid_moves)
|
|
# P
|
|
# print(self.board.boardlist[6][0].piece.valid_moves)
|
|
# R
|
|
#print(self.board.boardlist[5][1].piece.color)
|
|
#print(self.board.boardlist[5][1].piece.valid_moves)
|
|
def make_move_rival(self):
|
|
self.przeciwnik = input(str('Podaj ruch: '))
|
|
self.from_row = int(self.przeciwnik[0])
|
|
self.from_column = int(self.przeciwnik[1])
|
|
self.to_row = int(self.przeciwnik[3])
|
|
self.to_column = int(self.przeciwnik[4])
|
|
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)
|
|
|