52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from enum import Enum
|
|
from player import Player
|
|
from move import Move
|
|
from chess_piece import ChessPiece
|
|
from pawn import Pawn
|
|
from rook import Rook
|
|
from knight import Knight
|
|
from bishop import Bishop
|
|
from queen import Queen
|
|
from king import King
|
|
from move import Move
|
|
|
|
class MoveValidity(Enum):
|
|
Valid = 1
|
|
Invalid = 2
|
|
MovingIntoCheck = 3
|
|
StayingInCheck = 4
|
|
|
|
def __str__(self):
|
|
if self.value == 2:
|
|
return 'Invalid move.'
|
|
|
|
if self.value == 3:
|
|
return 'Invalid -- cannot move into check.'
|
|
|
|
if self.value == 4:
|
|
return 'Invalid -- must move out of check.'
|
|
|
|
|
|
# TODO: create UndoException
|
|
class UndoException(Exception):
|
|
pass
|
|
|
|
# create default board setup (y, x) not (x, y)
|
|
# blank spaces are set to none, as seen in the chess_gui_small_view
|
|
DEFAULT_BOARD = [
|
|
[Rook(Player.BLACK), Knight(Player.BLACK), Bishop(Player.BLACK), Queen(Player.BLACK), King(Player.BLACK), Bishop(Player.BLACK), Knight(Player.BLACK), Rook(Player.BLACK)],
|
|
[Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK), Pawn(Player.BLACK)],
|
|
[None, None, None, None, None, None, None, None],
|
|
[None, None, None, None, None, None, None, None],
|
|
[None, None, None, None, None, None, None, None],
|
|
[None, None, None, None, None, None, None, None],
|
|
[Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE), Pawn(Player.WHITE)],
|
|
[Rook(Player.WHITE), Knight(Player.WHITE), Bishop(Player.WHITE), Queen(Player.WHITE), King(Player.WHITE), Bishop(Player.WHITE), Knight(Player.WHITE), Rook(Player.WHITE)]
|
|
]
|
|
|
|
|
|
class ChessModel:
|
|
def __init__(self):
|
|
self.__board = DEFAULT_BOARD
|
|
|
|
# i wanna do easy checking for whether a piece can skip over another piece |