88 lines
3.3 KiB
Python
88 lines
3.3 KiB
Python
from board import Board
|
|
import random
|
|
|
|
class Game:
|
|
def __init__(self):
|
|
self.board = Board()
|
|
|
|
def printBoard(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')
|
|
elif self.piece == 'pawn':
|
|
if self.color=='white':
|
|
self.b.append('p')
|
|
else:
|
|
self.b.append('P')
|
|
elif self.piece == 'knight':
|
|
if self.color=='white':
|
|
self.b.append('h')
|
|
else:
|
|
self.b.append('H')
|
|
elif self.piece == 'bishop':
|
|
if self.color=='white':
|
|
self.b.append('b')
|
|
else:
|
|
self.b.append('B')
|
|
elif self.piece == 'queen':
|
|
if self.color=='white':
|
|
self.b.append('q')
|
|
else:
|
|
self.b.append('Q')
|
|
elif self.piece == 'king':
|
|
if self.color=='white':
|
|
self.b.append('k')
|
|
else:
|
|
self.b.append('K')
|
|
else:
|
|
self.b.append(' ')
|
|
print(self.b)
|
|
self.b = []
|
|
self.b.append(' ')
|
|
self.b.append('A')
|
|
self.b.append('B')
|
|
self.b.append('C')
|
|
self.b.append('D')
|
|
self.b.append('E')
|
|
self.b.append('F')
|
|
self.b.append('G')
|
|
self.b.append('H')
|
|
print(self.b)
|
|
print('')
|
|
|
|
def currently_available_moves(self):
|
|
for row in range(8):
|
|
for column in range(8):
|
|
if self.board.boardlist[row][column].has_piece():
|
|
self.piece = self.board.boardlist[row][column].piece
|
|
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
|
|
def nextMove(self, ruch):
|
|
self.currently_available_moves()
|
|
|
|
if ruch == None:
|
|
return Board.move_boot(self, 'black')
|
|
|
|
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)
|
|
|