This commit is contained in:
Agata Halik 2023-06-09 17:28:57 +02:00
parent 4ec8af3fd7
commit dbc0363aa5
16 changed files with 29 additions and 52 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

54
game.py
View File

@ -24,64 +24,57 @@ class Game:
if self.color=='white': if self.color=='white':
self.b.append('r') self.b.append('r')
else: 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': elif self.piece == 'pawn':
if self.color=='white': if self.color=='white':
self.b.append('p') self.b.append('p')
else: else:
self.b.append('P') self.b.append('P')
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
elif self.piece == 'knight': elif self.piece == 'knight':
if self.color=='white': if self.color=='white':
self.b.append('h') self.b.append('h')
else: else:
self.b.append('H') self.b.append('H')
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
elif self.piece == 'bishop': elif self.piece == 'bishop':
if self.color=='white': if self.color=='white':
self.b.append('b') self.b.append('b')
else: else:
self.b.append('B') self.b.append('B')
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
elif self.piece == 'queen': elif self.piece == 'queen':
if self.color=='white': if self.color=='white':
self.b.append('q') self.b.append('q')
else: else:
self.b.append('Q') self.b.append('Q')
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
elif self.piece == 'king': elif self.piece == 'king':
if self.color=='white': if self.color=='white':
self.b.append('k') self.b.append('k')
else: else:
self.b.append('K') self.b.append('K')
self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
else: else:
# wyswietla puste miejsca
self.b.append(' ') self.b.append(' ')
print(self.b) print(self.b)
self.b = [] self.b = []
self.b.append(' ') self.b.append(' ')
self.b.append('0') self.b.append('A')
self.b.append('1') self.b.append('B')
self.b.append('2') self.b.append('C')
self.b.append('3') self.b.append('D')
self.b.append('4') self.b.append('E')
self.b.append('5') self.b.append('F')
self.b.append('6') self.b.append('G')
self.b.append('7') self.b.append('H')
print(self.b) print(self.b)
print('') print('')
# sprawdzenie
# H def currently_available_moves(self):
# self.board.calc_moves(self.board.boardlist[7][6].piece, 7, 6) for row in range(8):
# print(self.board.boardlist[7][6].piece.valid_moves) for column in range(8):
# P if self.board.boardlist[row][column].has_piece():
# print(self.board.boardlist[6][0].piece.valid_moves) self.piece = self.board.boardlist[row][column].piece
# R self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
#print(self.board.boardlist[5][1].piece.color)
#print(self.board.boardlist[5][1].piece.valid_moves)
def nextMove(self, ruch): def nextMove(self, ruch):
if ruch == 'noone': self.currently_available_moves()
if ruch == None:
return Board.move_boot(self, 'black') return Board.move_boot(self, 'black')
else: else:
@ -92,14 +85,3 @@ class Game:
self.color = Board.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column) 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) 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])
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)
"""

11
main.py
View File

@ -1,20 +1,11 @@
from game import Game from game import Game
#def mainloop(self):
# game = self.game
game = Game() game = Game()
game2 = Game() game2 = Game()
game.printBoard() game.printBoard()
print('')
game2.printBoard() game2.printBoard()
print('') ruch=None
boot_color = 'white'
#11 21
a=0
ruch='noone'
while True: while True:
print(ruch)
ruch = game.nextMove(ruch) ruch = game.nextMove(ruch)
game.printBoard() game.printBoard()
print(ruch)
ruch = game2.nextMove(ruch) ruch = game2.nextMove(ruch)
game2.printBoard() game2.printBoard()

View File

@ -4,8 +4,6 @@ class Piece:
self.color = color self.color = color
self.valid_moves = [] self.valid_moves = []
self.moved = False self.moved = False
# kierunek pionkow, czarne w górę, białe w dół
if color == 'white': if color == 'white':
self.pawn_direction = -1 self.pawn_direction = -1
else: else:

View File

@ -15,13 +15,13 @@ class Square:
if self.has_piece() is True and self.piece.color != color: if self.has_piece() is True and self.piece.color != color:
return True return True
def empty_or_rival(self, color): # sprawdz def empty_or_rival(self, color):
if self.has_piece() is False or self.is_rival(color): # 1 has piece (color) if self.has_piece() is False or self.is_rival(color):
return True return True
else: else:
return False return False
def empty_or_rival_knight(self, color): # sprawdz def empty_or_rival_knight(self, color):
if self.has_piece() is False or self.is_rival(color): # 1 has piece (color) if self.has_piece() is False or self.is_rival(color):
return True return True
else: else:
return False return False