new
This commit is contained in:
parent
a37c688eef
commit
d6152ad658
14
board.py
14
board.py
@ -25,7 +25,6 @@ class Board:
|
||||
self.pawn_row = 1
|
||||
self.other_row = 0
|
||||
#pawns
|
||||
#self.boardlist[5][1] = Square(5, 1, King(color)) #DO USUNIĘCIA
|
||||
for column in range(8):
|
||||
self.boardlist[self.pawn_row][column] = Square(self.pawn_row, column, Pawn(color)) #do kazdego square przypisuje poczatkowy pawn
|
||||
#rooks
|
||||
@ -63,31 +62,21 @@ class Board:
|
||||
if self.board.boardlist[r][c].piece.color == color:
|
||||
self.boot_piece.append(self.board.boardlist[r][c])
|
||||
#random piece
|
||||
|
||||
self.value = random.randrange(0, len(self.boot_piece))
|
||||
self.initial = self.boot_piece[self.value]
|
||||
while len(self.initial.piece.valid_moves) == 0:
|
||||
#print('xddd')
|
||||
#print(self.initial.piece)
|
||||
#print(self.initial.piece.valid_moves)
|
||||
self.value = random.randrange(0, len(self.boot_piece))
|
||||
self.initial = self.boot_piece[self.value]
|
||||
self.initial_row=self.initial.row
|
||||
self.initial_column = self.initial.column
|
||||
#print(self.initial)
|
||||
#random move
|
||||
self.value = random.randrange(0, len(self.initial.piece.valid_moves))
|
||||
self.final = self.initial.piece.valid_moves[self.value]
|
||||
self.final_row = self.final[0]
|
||||
self.final_column = self.final[1]
|
||||
#print(self.final)
|
||||
#print(self.final_row)
|
||||
#update
|
||||
self.x = self.board.boardlist[self.initial_row][self.initial_column].piece
|
||||
#print(self.board.boardlist[self.initial_row][self.initial_column].piece.name)
|
||||
#print(self.initial_row, self.initial_column)
|
||||
self.board.boardlist[self.initial_row][self.initial_column].piece = None
|
||||
#print(self.final_row, self.final_column)
|
||||
if (self.board.boardlist[self.final_row][self.final_column].has_piece()):
|
||||
if (self.board.boardlist[self.final_row][self.final_column].piece.name== 'king'):
|
||||
self.board.boardlist[self.final_row][self.final_column].piece = self.x
|
||||
@ -95,9 +84,6 @@ class Board:
|
||||
self.board.boardlist[self.final_row][self.final_column].piece = self.x
|
||||
self.board.boardlist[self.final_row][self.final_column].piece.moved = True
|
||||
self.board.boardlist[self.final_row][self.final_column].piece.delete_moves()
|
||||
#print(self.board.boardlist[self.final_row][self.final_column].piece.name)
|
||||
#print(self.initial_row, self.initial_column)
|
||||
#print(self.final_row, self.final_column)
|
||||
if self.initial_column == 0:
|
||||
self.initial_column = "A"
|
||||
elif self.initial_column == 1:
|
||||
|
6
game.py
6
game.py
@ -46,12 +46,11 @@ class Game:
|
||||
else:
|
||||
self.b.append('Q')
|
||||
elif self.piece == 'king':
|
||||
if self.color=='white':
|
||||
if self.color == 'white':
|
||||
self.b.append('k')
|
||||
else:
|
||||
self.b.append('K')
|
||||
else:
|
||||
# wyswietla puste miejsca
|
||||
self.b.append(' ')
|
||||
print(self.b)
|
||||
self.b = []
|
||||
@ -65,6 +64,7 @@ class Game:
|
||||
self.b.append('6')
|
||||
self.b.append('7')
|
||||
print(self.b)
|
||||
print('')
|
||||
|
||||
def currently_available_moves(self):
|
||||
for row in range(8):
|
||||
@ -73,7 +73,7 @@ class Game:
|
||||
|
||||
def nextMove(self, ruch):
|
||||
self.currently_available_moves()
|
||||
if ruch == 'noone':
|
||||
if ruch == None:
|
||||
return Board.move_boot(self, 'white')
|
||||
|
||||
else:
|
||||
|
10
main.py
10
main.py
@ -8,26 +8,18 @@ game2.printBoard()
|
||||
print('')
|
||||
boot_color = 'white'
|
||||
#a=0
|
||||
ruch='noone'
|
||||
ruch=None
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
print('')
|
||||
#a=a+1
|
||||
#print(a)
|
||||
ruch = game.nextMove(ruch)
|
||||
if(ruch==1):
|
||||
game.printBoard()
|
||||
#print(game)
|
||||
exit(0)
|
||||
game.printBoard()
|
||||
print('')
|
||||
#a = a + 1
|
||||
#print(a)
|
||||
ruch = game2.nextMove(ruch)
|
||||
if (ruch == 1):
|
||||
game2.printBoard()
|
||||
#print(game2)
|
||||
exit(0)
|
||||
game2.printBoard()
|
12
move.py
12
move.py
@ -14,7 +14,6 @@ from piece import Piece
|
||||
class Move:
|
||||
@staticmethod
|
||||
def knight_moves(self, piece, row, column):
|
||||
# piece.delete_moves()
|
||||
self.possible_moves = [
|
||||
(row + 2, column - 1),
|
||||
(row + 2, column + 1),
|
||||
@ -66,7 +65,6 @@ class Move:
|
||||
break
|
||||
|
||||
def pawn_moves(self, piece, row, column):
|
||||
# piece.delete_moves()
|
||||
if piece.moved:
|
||||
self.steps = 1
|
||||
else:
|
||||
@ -81,16 +79,10 @@ class Move:
|
||||
piece.add_moves((self.final, column))
|
||||
self.steps = 1
|
||||
self.final = row + (piece.pawn_direction * self.steps)
|
||||
# problem z wierszem
|
||||
# if self.final>7 or self.final<0 or column>7 or column <0:
|
||||
# print(piece.name)
|
||||
# print(self.final, column)
|
||||
if Square.on_board(self.final, column) is True and self.board.boardlist[self.final][
|
||||
column].has_piece() is False:
|
||||
piece.add_moves((self.final, column))
|
||||
|
||||
# diagonal
|
||||
# czy wychodzi poza tablice i czy stoi rywal
|
||||
self.possible_row = row + piece.pawn_direction
|
||||
self.possible_columns = []
|
||||
self.possible_columns = [column - 1, column + 1]
|
||||
@ -100,7 +92,6 @@ class Move:
|
||||
piece.add_moves((self.possible_row, possible_column))
|
||||
|
||||
def king_moves(self, piece, row, column):
|
||||
# piece.delete_moves()
|
||||
self.direction = [
|
||||
(0, 1),
|
||||
(0, -1),
|
||||
@ -133,12 +124,9 @@ class Move:
|
||||
Move.pawn_moves(self, piece, column, row)
|
||||
elif piece.name == 'knight':
|
||||
Move.knight_moves(self, piece, column, row)
|
||||
#knight_moves()
|
||||
elif piece.name == 'bishop':
|
||||
# piece.delete_moves()
|
||||
Move.straightline_moves(self, piece, column, row, False)
|
||||
elif piece.name == 'queen':
|
||||
# piece.delete_moves()
|
||||
Move.straightline_moves(self, piece, column, row, True)
|
||||
Move.straightline_moves(self, piece, column, row, False)
|
||||
elif piece.name == 'king':
|
||||
|
@ -1,5 +1,4 @@
|
||||
class Square:
|
||||
# tworzenie pól
|
||||
def __init__(self, row, column, piece=None):
|
||||
self.row = row
|
||||
self.column = column
|
||||
@ -15,13 +14,13 @@ class Square:
|
||||
if self.has_piece() is True and self.piece.color != color:
|
||||
return True
|
||||
|
||||
def empty_or_rival(self, color): # sprawdz
|
||||
if self.has_piece() is False or self.is_rival(color): # 1 has piece (color)
|
||||
def empty_or_rival(self, color):
|
||||
if self.has_piece() is False or self.is_rival(color):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
def empty_or_rival_knight(self, color): # sprawdz
|
||||
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
|
||||
else:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user