Szachy/game.py

126 lines
4.8 KiB
Python
Raw Normal View History

2023-06-08 16:02:55 +02:00
from board import Board
2023-06-08 23:13:34 +02:00
from move import Move
2023-06-08 16:02:55 +02:00
import random
class Game:
def __init__(self):
self.board = Board()
2023-06-08 21:37:15 +02:00
def printBoard(self):
2023-06-08 16:02:55 +02:00
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')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
elif self.piece == 'pawn':
if self.color=='white':
self.b.append('p')
else:
self.b.append('P')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
elif self.piece == 'knight':
if self.color=='white':
self.b.append('h')
else:
self.b.append('H')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
elif self.piece == 'bishop':
if self.color=='white':
self.b.append('b')
else:
self.b.append('B')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
elif self.piece == 'queen':
if self.color=='white':
self.b.append('q')
else:
self.b.append('Q')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
elif self.piece == 'king':
if self.color=='white':
self.b.append('k')
else:
self.b.append('K')
2023-06-08 23:13:34 +02:00
Move.calc_moves(self, self.board.boardlist[row][column].piece, row, column)
2023-06-08 16:02:55 +02:00
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)
2023-06-08 23:55:19 +02:00
2023-06-08 21:37:15 +02:00
def nextMove(self, ruch):
if ruch == 'noone':
return Board.move_boot(self, 'white')
else:
2023-06-08 23:55:19 +02:00
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
2023-06-08 21:37:15 +02:00
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)
2023-06-08 16:02:55 +02:00