Skip to content

Commit

Permalink
ENH: improved imports + some names
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentAuriau committed Nov 4, 2023
1 parent 4962a6e commit beb8024
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Special thanks and dedication to LeMerluche, crushing its opponents on chess.com

## How to play with interface
```python
from pyalapin.interface.interface import MyApp
from pyalapin.interface import ChessApp

if __name__ == '__main__':
MyApp(
ChessApp(
play_with_ai=False # Set to True if you want to play agains AI
).run()

Expand All @@ -24,11 +24,9 @@ if __name__ == '__main__':
<img align="right" src="docs/scholars_mate_command.gif">

```python
import sys
sys.path.append("python/")
import python.engine as engine
from pyalapin.engine import ChessGame

game = engine.engine.Game(
game = ChessGame(
automatic_draw=True, # Set to True if you want
# to have each turn drawn in terminal
ai=False, # set to True if you want to play agains AI
Expand Down
1 change: 1 addition & 0 deletions pyalapin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
pyalapin, chess python package.
"""
# from .interface import interface as interface

__version__ = "0.0.1"
__author__ = "Vincent Auriau"
1 change: 1 addition & 0 deletions pyalapin/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .engine import ChessGame
2 changes: 1 addition & 1 deletion pyalapin/engine/color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Color:
class Color(object):
GREEN = "\x1b[32m"
WHITE = "\033[0m"
RED = "\x1b[31m"
8 changes: 4 additions & 4 deletions pyalapin/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import pyalapin.engine.material as material


class Color:
class Color(object):
GREEN = "\x1b[32m"
WHITE = "\033[0m"
RED = "\x1b[31m"


class Cell:
class Cell(object):
"""
Cell class representing a base element of a board.
Expand Down Expand Up @@ -387,7 +387,7 @@ def is_threatened(
return False


class Board:
class Board(object):
"""
Board class representing the chess board.
Expand Down Expand Up @@ -937,7 +937,7 @@ def draw(self, printing=True):
return whole_text


class Game:
class ChessGame(object):
"""
Game class, used to play a chess game, interact with the board and move pieces.
Expand Down
2 changes: 1 addition & 1 deletion pyalapin/engine/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pyalapin.engine.material as material


class Move:
class Move(object):
"""Base class for material movement.
Implements various checks and is able to operate a piece movement along additional actions such as taking an
Expand Down
1 change: 1 addition & 0 deletions pyalapin/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .interface import ChessApp, BoardInterface
15 changes: 7 additions & 8 deletions pyalapin/interface/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import os
import time

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
Expand All @@ -12,7 +11,7 @@

from kivy.graphics import Rectangle, Color, Canvas

from pyalapin.engine.engine import Game
from pyalapin.engine.engine import ChessGame


class LoginScreen(GridLayout):
Expand Down Expand Up @@ -56,15 +55,15 @@ def __init__(self, row, column, **kwargs):
self.column = column


class TableScreen(GridLayout):
class BoardInterface(GridLayout):
"""
Main class to represent and display the board, as well as to play a chess game.
Attributes
----------
path_to_illustrations: str
Path to the images to use to display cells & pieces
game: engine.Game
game: engine.ChessGame
game to actually represent
ai_playing: bool
whether or not an AI is playing (only one of the players for now)
Expand All @@ -89,7 +88,7 @@ def __init__(self, game, **kwargs):
game: engine.Game to represent
"""
super(TableScreen, self).__init__(**kwargs)
super(BoardInterface, self).__init__(**kwargs)
self.path_to_illustrations = "illustrations"
self.game = game

Expand Down Expand Up @@ -378,7 +377,7 @@ def click_cell(self, event):
self.update()


class MyApp(App):
class ChessApp(App):
"""
Main app to use to play game, by calling MyApp().buil() and then player.
"""
Expand All @@ -394,6 +393,6 @@ def build(self):
"""
Builds the game and the display board along with it.
"""
game = Game(automatic_draw=False, ai=self.play_with_ai)
game = ChessGame(automatic_draw=False, ai=self.play_with_ai)
print("game created")
return TableScreen(game)
return BoardInterface(game)
5 changes: 3 additions & 2 deletions run_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyalapin.interface.interface import MyApp
from pyalapin.interface import ChessApp
# import pyalapin.interface as interface

if __name__ == "__main__":
MyApp(play_with_ai=False).run()
ChessApp(play_with_ai=False).run()

0 comments on commit beb8024

Please sign in to comment.