Compare commits
No commits in common. "455fae8ad1448ca2431fc892f3248c437dc7d3d7" and "4493e3a11015195a7d497ca197aa145a14297f1f" have entirely different histories.
455fae8ad1
...
4493e3a110
22
.github/workflows/automatic-prerelease.yml
vendored
22
.github/workflows/automatic-prerelease.yml
vendored
@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
name: "pre-release"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "main"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
pre-release:
|
|
||||||
name: "Pre Release"
|
|
||||||
runs-on: "ubuntu-latest"
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
|
||||||
with:
|
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
automatic_release_tag: "latest"
|
|
||||||
prerelease: true
|
|
||||||
title: "Development Build"
|
|
20
.github/workflows/tagged-release.yml
vendored
20
.github/workflows/tagged-release.yml
vendored
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: "tagged-release"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
tagged-release:
|
|
||||||
name: "Tagged Release"
|
|
||||||
runs-on: "ubuntu-latest"
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
|
||||||
with:
|
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
prerelease: false
|
|
@ -1,42 +0,0 @@
|
|||||||
from logic.pieces.bishop import Bishop
|
|
||||||
from logic.pieces.king import King
|
|
||||||
from logic.pieces.knight import Knight
|
|
||||||
from logic.pieces.queen import Queen
|
|
||||||
from logic.pieces.rook import Rook
|
|
||||||
from logic.pieces.pawn import Pawn
|
|
||||||
from logic.pieces.piece import Piece
|
|
||||||
from logic.position import Position
|
|
||||||
|
|
||||||
class Board:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._white: dict[Position, Piece] = {}
|
|
||||||
self._black: dict[Position, Piece] = {}
|
|
||||||
|
|
||||||
for x in range(8):
|
|
||||||
pos_w_pawn = Position(x, 1)
|
|
||||||
pos_b_pawn = Position(x, 6)
|
|
||||||
|
|
||||||
self._white[pos_w_pawn] = Pawn(pos_w_pawn)
|
|
||||||
self._black[pos_b_pawn] = Pawn(pos_b_pawn)
|
|
||||||
|
|
||||||
pos_w_piece = Position(x, 0)
|
|
||||||
pos_b_piece = Position(x, 7)
|
|
||||||
|
|
||||||
piece = None
|
|
||||||
if x == 0 or x == 7:
|
|
||||||
piece = Rook
|
|
||||||
elif x == 1 or x == 6:
|
|
||||||
piece = Knight
|
|
||||||
elif x == 2 or x == 5:
|
|
||||||
piece = Bishop
|
|
||||||
elif x == 3:
|
|
||||||
piece = Queen
|
|
||||||
elif x == 4:
|
|
||||||
piece = King
|
|
||||||
assert piece != None, f"Didn't know which piece to assign for {x = }"
|
|
||||||
self._white[pos_w_piece] = piece(pos_w_piece)
|
|
||||||
self._black[pos_b_piece] = piece(pos_b_piece)
|
|
||||||
|
|
||||||
|
|
||||||
def create_board():
|
|
||||||
return Board()
|
|
@ -1,4 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class Bishop(Piece):
|
|
||||||
pass
|
|
@ -1,5 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class King(Piece):
|
|
||||||
pass
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class Knight(Piece):
|
|
||||||
pass
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class Pawn(Piece):
|
|
||||||
def __init__(self, pos) -> None:
|
|
||||||
super().__init__(pos)
|
|
||||||
self.already_moved = False
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
from logic.position import Position
|
|
||||||
|
|
||||||
|
|
||||||
class Piece:
|
|
||||||
def __init__(self, pos) -> None:
|
|
||||||
self.pos = pos
|
|
||||||
|
|
||||||
def position(self) -> Position:
|
|
||||||
return self.pos
|
|
||||||
|
|
||||||
def legal_moves(self, board) -> list[Position]:
|
|
||||||
raise NotImplementedError(f"Can't say what the legal moves are for {type(self).__name__}, the method hasn't been implemented yet")
|
|
@ -1,5 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class Queen(Piece):
|
|
||||||
pass
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
from .piece import Piece
|
|
||||||
|
|
||||||
class Rook(Piece):
|
|
||||||
pass
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
|||||||
class Position:
|
|
||||||
_MIN_POS = 0
|
|
||||||
_MAX_POS = 7
|
|
||||||
|
|
||||||
def __init__(self, x, y) -> None:
|
|
||||||
assert x >= self._MIN_POS and x <= self._MAX_POS, f"Invalid argument: x should be between {self._MIN_POS} and {self._MAX_POS}, but is {x}"
|
|
||||||
assert y >= self._MIN_POS and y <= self._MAX_POS, f"Invalid argument: y should be between {self._MIN_POS} and {self._MAX_POS}, but is {y}"
|
|
||||||
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
|
|
||||||
def __eq__(self, value: object, /) -> bool:
|
|
||||||
if type(value) != type(self):
|
|
||||||
return False
|
|
||||||
return value.x == self.x and value.y == self.y
|
|
||||||
|
|
||||||
def __hash__(self) -> int:
|
|
||||||
return hash((self.x, self.y))
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.x, self.y}"
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
return str(self)
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
from logic.board import create_board
|
|
||||||
from view.tui import TUI
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
board = create_board()
|
|
||||||
|
|
||||||
view = TUI(board)
|
|
||||||
|
|
||||||
view.show()
|
|
@ -1,57 +0,0 @@
|
|||||||
from logic.board import Board
|
|
||||||
from logic.pieces.bishop import Bishop
|
|
||||||
from logic.pieces.king import King
|
|
||||||
from logic.pieces.knight import Knight
|
|
||||||
from logic.pieces.pawn import Pawn
|
|
||||||
from logic.pieces.piece import Piece
|
|
||||||
from logic.pieces.queen import Queen
|
|
||||||
from logic.pieces.rook import Rook
|
|
||||||
from view.view import View
|
|
||||||
|
|
||||||
class TUI(View):
|
|
||||||
def __init__(self, board: Board) -> None:
|
|
||||||
super().__init__(board)
|
|
||||||
|
|
||||||
def show(self) -> None:
|
|
||||||
board_view = [
|
|
||||||
[" " for _ in range(0, 8)]
|
|
||||||
for _ in range(0, 8)
|
|
||||||
]
|
|
||||||
|
|
||||||
for pos, piece in self.board._white.items():
|
|
||||||
board_view[pos.y][pos.x] = self.string_of(piece).upper()
|
|
||||||
|
|
||||||
for pos, piece in self.board._black.items():
|
|
||||||
board_view[pos.y][pos.x] = self.string_of(piece)
|
|
||||||
|
|
||||||
# we reverse the board because (0, 0) in in the bottom left, not top left
|
|
||||||
board_view.reverse()
|
|
||||||
print(self.to_string(board_view))
|
|
||||||
|
|
||||||
def to_string(self, board_view: list[list[str]]) -> str:
|
|
||||||
VER_SEP = "|"
|
|
||||||
HOR_SEP = "-"
|
|
||||||
ROW_SEP = HOR_SEP * (2*len(board_view[0]) + 1)
|
|
||||||
ret = ROW_SEP + "\n"
|
|
||||||
for row_view in board_view:
|
|
||||||
row_str = VER_SEP + VER_SEP.join(row_view) + VER_SEP
|
|
||||||
ret += row_str + "\n"
|
|
||||||
ret += ROW_SEP + "\n"
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def string_of(self, piece: Piece) -> str:
|
|
||||||
type_ = type(piece)
|
|
||||||
if type_ == Pawn:
|
|
||||||
return "p"
|
|
||||||
if type_ == Queen:
|
|
||||||
return "q"
|
|
||||||
if type_ == Bishop:
|
|
||||||
return "b"
|
|
||||||
if type_ == Knight:
|
|
||||||
return "n"
|
|
||||||
if type_ == Rook:
|
|
||||||
return "r"
|
|
||||||
if type_ == King:
|
|
||||||
return "k"
|
|
||||||
raise ValueError(f"Unknown piece type {type(piece)}")
|
|
@ -1,10 +0,0 @@
|
|||||||
from logic.board import Board
|
|
||||||
|
|
||||||
|
|
||||||
class View:
|
|
||||||
def __init__(self, board: Board) -> None:
|
|
||||||
self.board: Board = board
|
|
||||||
|
|
||||||
def show(self) -> None:
|
|
||||||
raise NotImplementedError(f"Can't show the board, the show() method of {type(self)} is not implemented")
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user