Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace termcolor with colored module #40

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ pip install .
chess -h # to see all possible options
```
```
usage: chess [-h] [-t] [-w W] [-b B]
usage: chess [-h] [-t] [-w W] [-b B] [-c]

A python program to play chess against an AI in the terminal.

optional arguments:
-h, --help show this help message and exit
-t, --two to play a 2-player game (default: False)
-w W, --white W color for white player (default: blue)
-b B, --black B color for black player (default: red)
-w W, --white W color for white player (default: white)
-b B, --black B color for black player (default: black)
-c, --checkered use checkered theme for the chess board (default: False)

Enjoy the game!

```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
termcolor
colored
mypy>=0.981
mypy-extensions>=0.4.3
tomli>=2.0.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
},
install_requires=[
'termcolor',
'colored',
],
keywords=['chess', 'game'],
classifiers=["Programming Language :: Python :: 3"],
Expand Down
22 changes: 17 additions & 5 deletions src/Board.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
from src.Piece import Piece
from src.Queen import Queen
from src.Rook import Rook
import colored
from colored import fg, bg, attr

WHITE = True
BLACK = False

TILES = {
0:'#769656',
1:'#EEEED2',
}

class Board:

Expand All @@ -28,8 +34,13 @@ def __init__(self, mateInOne: bool = False, castleBoard: bool = False,
self.currentSide = WHITE
self.movesMade = 0
self.checkmate = False
self.whiteColor = 'blue'
self.blackColor = 'red'
self.whiteColor = 'white'
self.blackColor = 'black'
self.isCheckered = False
self.tileColors = {
0:'#769656',
1:'#BACA44',
}

if not mateInOne and not castleBoard and not passant and not promotion:
self.pieces.extend([Rook(self, BLACK, C(0, 7)),
Expand Down Expand Up @@ -201,12 +212,13 @@ def makeUnicodeStringRep(self, pieces: list[Piece]) -> str:
if p.position == C(x, y):
piece = p
break
on_color = 'on_cyan' if y % 2 == x % 2 else 'on_yellow'
pieceRep = colored(' ', on_color=on_color)
bg_color = bg(self.tileColors[(x+y)%2]) if self.isCheckered else ''
pieceRep = bg_color + ' ' + attr(0)
if piece:
side = piece.side
color = self.whiteColor if side == WHITE else self.blackColor
pieceRep = colored(DISPLAY_LOOKUP[piece.stringRep] + ' ', color=color, on_color=on_color)
fg_color = fg(color)
pieceRep = fg_color + bg_color + DISPLAY_LOOKUP[piece.stringRep] + ' ' + attr(0)
stringRep += pieceRep
stringRep += '\n'
return stringRep.rstrip()
Expand Down
14 changes: 11 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,30 @@ def main() -> None:
'-w',
'--white',
action='store',
default="blue",
default='white',
metavar='W',
help="color for white player"
)
parser.add_argument(
'-b',
'--black',
action='store',
default="red",
default='black',
metavar='B',
help="color for black player"
)
parser.add_argument(
'-c',
'--checkered',
action='store_true',
default=False,
help="use checkered theme for the chess board",
)

args = parser.parse_args()
board.whiteColor = args.white
board.blackColor = args.black

board.isCheckered = args.checkered
try:
if args.two:
twoPlayerGame(board)
Expand Down