Skip to content

Commit

Permalink
Merge pull request #25 from whiletruelearn/docker
Browse files Browse the repository at this point in the history
Add docker file, build scripts and minor refactoring
  • Loading branch information
whiletruelearn authored Oct 17, 2024
2 parents b03905c + 63daf0f commit e0332bc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
docker:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image (multi-arch)
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
platforms: linux/amd64,linux/arm64
build-args: |
DOCKER_CLI_EXPERIMENTAL=enabled
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10-slim
ENV TERM=xterm-256color COLORTERM=truecolor

WORKDIR /app

COPY . .

RUN apt-get update && apt-get install -y build-essential libasound2-dev stockfish
RUN pip install --no-cache-dir -r requirements.txt

RUN mv /usr/games/stockfish /usr/local/bin/

RUN pip install -e .

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

# Termichess

A game of chess in your terminal. Built using the amazing TUI framework `Textual`.
A game of chess in your terminal. Built using the amazing TUI framework `Textual`.

## Demo


https://github.com/user-attachments/assets/305f1e5b-9c76-474f-b30e-5bee12ac3be8

## Features
Expand Down Expand Up @@ -40,6 +38,14 @@ After installation, you can start the game by simply running:
- To exit out at any time , Press `q` .
- To restart the game click on the `Restart` button

## Running via Docker

You can also run `termichess` via Docker if that's what you prefer.

`docker run -it ghcr.io/whiletruelearn/termichess:latest termichess`

Note : Please keep `sound` config to off while using `docker`

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Expand Down
9 changes: 6 additions & 3 deletions termichess/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class ChessApp(App):
}
#options-grid {
grid-size: 4;
grid-size: 5;
grid-gutter: 1 2;
grid-columns: 1fr 1fr 1fr 1fr;
grid-columns: 1fr 1fr 1fr 1fr 1fr;
margin-bottom: 1;
}
Expand Down Expand Up @@ -155,6 +155,7 @@ def __init__(self):
self.engine = SimpleEngine.popen_uci("stockfish")
self.move_sound = sa.WaveObject.from_wave_file(f"{ASSETS_PATH}/sound/move.wav")
self.player_color = "white"
self.sound_enabled = True

def compose(self) -> ComposeResult:
yield ConfigScreen()
Expand Down Expand Up @@ -192,6 +193,7 @@ def apply_config(self):

ChessSquare.piece_set = CONF["piece-type"]
self.player_color = CONF["player_color"]
self.sound_enabled = (CONF["sound"] == "on")

if self.player_color == "random":
self.player_color = choice(["white","black"])
Expand Down Expand Up @@ -281,7 +283,8 @@ def update_info(self):
self.info_panel.update_info(turn, status, CONF["difficulty"])

def play_move_sound(self):
self.move_sound.play()
if self.sound_enabled:
self.move_sound.play()

def check_game_over(self):
if self.chess_board.board.is_game_over():
Expand Down
8 changes: 5 additions & 3 deletions termichess/config_screen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.containers import Grid, Center, Vertical
from textual.widgets import Static, Button, RadioButton, RadioSet
from termichess.utils import CONF, THEME_COLORS
from termichess.utils import CONF, THEME_COLORS, PIECE_ASCII_ART


class RetroTitle(Static):
Expand Down Expand Up @@ -29,7 +29,7 @@ def compose(self):



PIECE_TYPES = ["retro","png-v1","geometric", "minimalistic","char","computer1","computer2","computer3","glyph","got","mahabharat","potter","rad","scientist"]


class ConfigScreen(Static):

Expand All @@ -40,10 +40,11 @@ def compose(self):
yield RetroTitle()

with Grid(id="options-grid", classes="options"):
yield ConfigBox("Piece Type", "piece-type", PIECE_TYPES )
yield ConfigBox("Piece Type", "piece-type", list(PIECE_ASCII_ART.keys()) + ['png-v1'])
yield ConfigBox("Board Theme", "board-theme", THEME_COLORS.keys())
yield ConfigBox("Player Color", "player_color", ["white", "black", "random"])
yield ConfigBox("Difficulty Level", "difficulty", ["beginner","easy", "medium", "hard", "super hard"])
yield ConfigBox("Sound", "sound", ["on", "off"])

with Center():
yield Button("Start Game", id="start-game", variant="primary")
Expand All @@ -56,6 +57,7 @@ def on_mount(self):
self.set_radio_button("board-theme", "classic")
self.set_radio_button("player_color", "white")
self.set_radio_button("difficulty", "beginner")
self.set_radio_button("sound", "on")

def set_radio_button(self, radio_set_id: str, value: str):
radio_set = self.query_one(f"#{radio_set_id}")
Expand Down

0 comments on commit e0332bc

Please sign in to comment.