bez komentarzy

This commit is contained in:
Agata Halik 2023-06-13 16:17:23 +02:00
parent 9b1699d65b
commit 60b15d7996
23 changed files with 12 additions and 24 deletions

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.

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class Bishop(Piece): class Bishop(Piece):
@abstractmethod
def straightline_moves(self, piece, row, column, isvertical): def straightline_moves(self, piece, row, column, isvertical):
if isvertical is True: if isvertical is True:
self.direction = [ self.direction = [

View File

@ -21,7 +21,7 @@ class Board:
self.other_row = 0 self.other_row = 0
#pawns #pawns
for column in range(8): for column in range(8):
self.boardlist[self.pawn_row][column] = Square(self.pawn_row, column, Piece("pawn", color)) #do kazdego square przypisuje poczatkowy pawn self.boardlist[self.pawn_row][column] = Square(self.pawn_row, column, Piece("pawn", color))
#rooks #rooks
self.boardlist[self.other_row][0] = Square(self.other_row, 0, Piece("rook", color)) self.boardlist[self.other_row][0] = Square(self.other_row, 0, Piece("rook", color))
self.boardlist[self.other_row][7] = Square(self.other_row, 7, Piece("rook", color)) self.boardlist[self.other_row][7] = Square(self.other_row, 7, Piece("rook", color))

View File

@ -71,7 +71,6 @@ class Game:
for column in range(8): for column in range(8):
if self.board.boardlist[row][column].has_piece(): if self.board.boardlist[row][column].has_piece():
self.piece = self.board.boardlist[row][column].piece self.piece = self.board.boardlist[row][column].piece
#self.board.calc_moves(self.board.boardlist[row][column].piece, row, column)
Move.calc_moves(self, self.piece, row, column) Move.calc_moves(self, self.piece, row, column)
def nextMove(self, ruch): def nextMove(self, ruch):
self.currently_available_moves() self.currently_available_moves()

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class King(Piece): class King(Piece):
@abstractmethod
def king_moves(self, piece, row, column): def king_moves(self, piece, row, column):
self.direction = [ self.direction = [
(0, 1), (0, 1),

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class Knight(Piece): class Knight(Piece):
@abstractmethod
def knight_moves(self, piece, row, column): def knight_moves(self, piece, row, column):
self.possible_moves = [ self.possible_moves = [
(row + 2, column - 1), (row + 2, column - 1),

View File

@ -5,9 +5,7 @@ game2 = Game()
#game2.printBoard() #game2.printBoard()
ruch=None ruch=None
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()

15
move.py
View File

@ -9,7 +9,8 @@ from king import King
import random import random
class Move: class Move:
def szach(self):
pass
def move_rival(self, ruch): def move_rival(self, ruch):
self.from_column = Move.letters_to__numbers(ruch[0]) self.from_column = Move.letters_to__numbers(ruch[0])
self.from_row = int(ruch[1]) self.from_row = int(ruch[1])
@ -27,6 +28,7 @@ class Move:
return self.board.boardlist[self.to_row][self.to_column].piece.color return self.board.boardlist[self.to_row][self.to_column].piece.color
def move_boot(self, color): def move_boot(self, color):
#move.szach(self, color)
self.x, self.initial_row, self.initial_column, self.final_row, self.final_column = Move.random_valid_move(self, color) self.x, self.initial_row, self.initial_column, self.final_row, self.final_column = Move.random_valid_move(self, color)
self.board.boardlist[self.initial_row][self.initial_column].piece = None self.board.boardlist[self.initial_row][self.initial_column].piece = None
Move.mat(self, self.x, self.final_row, self.final_column) Move.mat(self, self.x, self.final_row, self.final_column)
@ -67,7 +69,8 @@ class Move:
return self.x, self.move_initial_row, self.move_initial_column, self. move_final_row, self.move_final_column return self.x, self.move_initial_row, self.move_initial_column, self. move_final_row, self.move_final_column
def calc_moves(self, piece, row, column): def calc_moves(self, piece, row, column):
piece.valid_moves=[] piece.delete_moves()
#piece.valid_moves=[]
if piece.name == 'rook': if piece.name == 'rook':
Rook.straightline_moves(self, piece, row, column,True) Rook.straightline_moves(self, piece, row, column,True)
pass pass
@ -94,12 +97,10 @@ class Move:
def mat(self, x, final_row, final_column): def mat(self, x, final_row, final_column):
if self.board.boardlist[final_row][final_column].has_piece(): if self.board.boardlist[final_row][final_column].has_piece():
if self.board.boardlist[final_row][final_column].piece.name == 'king': if self.board.boardlist[final_row][final_column].piece.name == 'king':
#print(final_column, final_row)
#print(x)
#print(x.color)
#print(self.board.boardlist[final_row][final_column].piece.color)
#self.board.boardlist[final_row][final_column].piece = x
exit(0) exit(0)
#def szach(self,color):
# for
@staticmethod @staticmethod
def numbers_to_letters(number): def numbers_to_letters(number):
if number == 0: if number == 0:

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class Pawn(Piece): class Pawn(Piece):
@abstractmethod
def pawn_moves(self, piece, row, column): def pawn_moves(self, piece, row, column):
if piece.moved == True: if piece.moved == True:
self.steps = 1 self.steps = 1

View File

@ -13,3 +13,6 @@ class Piece:
def delete_moves(self): def delete_moves(self):
self.valid_moves = [] self.valid_moves = []
#def czy_szachuje(self, row, column, color):
# self.ruch=[]

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class Queen(Piece): class Queen(Piece):
@abstractmethod
def straightline_moves(self, piece, row, column, isvertical): def straightline_moves(self, piece, row, column, isvertical):
if isvertical is True: if isvertical is True:
self.direction = [ self.direction = [

View File

@ -1,9 +1,7 @@
from piece import Piece from piece import Piece
from board import Board from board import Board
from square import Square from square import Square
from abc import abstractmethod
class Rook(Piece): class Rook(Piece):
@abstractmethod
def straightline_moves(self, piece, row, column, isvertical): def straightline_moves(self, piece, row, column, isvertical):
if isvertical is True: if isvertical is True:
self.direction = [ self.direction = [

View File

@ -12,7 +12,6 @@ class Square:
def is_rival(self, color): def is_rival(self, color):
if self.has_piece() is True and self.piece.color != color: if self.has_piece() is True and self.piece.color != color:
#print(self.piece.color, color, self.piece.name)
return True return True
def empty_or_rival(self, color): def empty_or_rival(self, color):