123 lines
4.5 KiB
Python
123 lines
4.5 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_column = ruch[0]
|
|
self.from_row = int(ruch[1])
|
|
self.to_column = ruch[3]
|
|
self.to_row = int(ruch[4])
|
|
|
|
if self.from_column == 'A':
|
|
self.from_column = 0
|
|
elif self.from_column == 'B':
|
|
self.from_column = 1
|
|
elif self.from_column == 'C':
|
|
self.from_column = 2
|
|
elif self.from_column == 'D':
|
|
self.from_column = 3
|
|
elif self.from_column == 'E':
|
|
self.from_column = 4
|
|
elif self.from_column == 'F':
|
|
self.from_column = 5
|
|
elif self.from_column == 'G':
|
|
self.from_column = 6
|
|
elif self.from_column == 'H':
|
|
self.from_column = 7
|
|
|
|
if self.to_column == 'A':
|
|
self.to_column = 0
|
|
elif self.to_column == 'B':
|
|
self.to_column = 1
|
|
elif self.to_column == 'C':
|
|
self.to_column = 2
|
|
elif self.to_column == 'D':
|
|
self.to_column = 3
|
|
elif self.to_column == 'E':
|
|
self.to_column = 4
|
|
elif self.to_column == 'F':
|
|
self.to_column = 5
|
|
elif self.to_column == 'G':
|
|
self.to_column = 6
|
|
elif self.to_column == 'H':
|
|
self.to_column = 7
|
|
|
|
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)
|
|
|