chesssnake 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. chesssnake-0.3.1/LICENSE +21 -0
  2. chesssnake-0.3.1/PKG-INFO +138 -0
  3. chesssnake-0.3.1/README.md +118 -0
  4. chesssnake-0.3.1/chesssnake/__init__.py +15 -0
  5. chesssnake-0.3.1/chesssnake/chesslib/Chess.py +2200 -0
  6. chesssnake-0.3.1/chesssnake/chesslib/ChessError.py +114 -0
  7. chesssnake-0.3.1/chesssnake/chesslib/ChessImg.py +128 -0
  8. chesssnake-0.3.1/chesssnake/chesslib/Game.py +94 -0
  9. chesssnake-0.3.1/chesssnake/chesslib/__init__.py +0 -0
  10. chesssnake-0.3.1/chesssnake/chesslib/data/Roboto-Black.ttf +0 -0
  11. chesssnake-0.3.1/chesssnake/chesslib/data/img/0.png +0 -0
  12. chesssnake-0.3.1/chesssnake/chesslib/data/img/1.png +0 -0
  13. chesssnake-0.3.1/chesssnake/chesslib/data/img/B0.png +0 -0
  14. chesssnake-0.3.1/chesssnake/chesslib/data/img/B1.png +0 -0
  15. chesssnake-0.3.1/chesssnake/chesslib/data/img/K0.png +0 -0
  16. chesssnake-0.3.1/chesssnake/chesslib/data/img/K1.png +0 -0
  17. chesssnake-0.3.1/chesssnake/chesslib/data/img/N0.png +0 -0
  18. chesssnake-0.3.1/chesssnake/chesslib/data/img/N1.png +0 -0
  19. chesssnake-0.3.1/chesssnake/chesslib/data/img/P0.png +0 -0
  20. chesssnake-0.3.1/chesssnake/chesslib/data/img/P1.png +0 -0
  21. chesssnake-0.3.1/chesssnake/chesslib/data/img/Q0.png +0 -0
  22. chesssnake-0.3.1/chesssnake/chesslib/data/img/Q1.png +0 -0
  23. chesssnake-0.3.1/chesssnake/chesslib/data/img/R0.png +0 -0
  24. chesssnake-0.3.1/chesssnake/chesslib/data/img/R1.png +0 -0
  25. chesssnake-0.3.1/chesssnake/chesslib/data/img/a.png +0 -0
  26. chesssnake-0.3.1/chesssnake/chesslib/data/img/b.png +0 -0
  27. chesssnake-0.3.1/chesssnake/chesslib/data/img/blankboard.png +0 -0
  28. chesssnake-0.3.1/chesssnake/chesslib/data/img/c.png +0 -0
  29. chesssnake-0.3.1/chesssnake/chesslib/data/img/d.png +0 -0
  30. chesssnake-0.3.1/chesssnake/chesslib/data/img/e.png +0 -0
  31. chesssnake-0.3.1/chesssnake/chesslib/data/img/f.png +0 -0
  32. chesssnake-0.3.1/chesssnake/chesslib/data/img/g.png +0 -0
  33. chesssnake-0.3.1/chesssnake/chesslib/data/img/h.png +0 -0
  34. chesssnake-0.3.1/chesssnake/chesslib/data/img/num1.png +0 -0
  35. chesssnake-0.3.1/chesssnake/chesslib/data/img/num2.png +0 -0
  36. chesssnake-0.3.1/chesssnake/chesslib/data/img/num3.png +0 -0
  37. chesssnake-0.3.1/chesssnake/chesslib/data/img/num4.png +0 -0
  38. chesssnake-0.3.1/chesssnake/chesslib/data/img/num5.png +0 -0
  39. chesssnake-0.3.1/chesssnake/chesslib/data/img/num6.png +0 -0
  40. chesssnake-0.3.1/chesssnake/chesslib/data/img/num7.png +0 -0
  41. chesssnake-0.3.1/chesssnake/chesslib/data/img/num8.png +0 -0
  42. chesssnake-0.3.1/chesssnake/chesslib/data/img/orange.png +0 -0
  43. chesssnake-0.3.1/chesssnake/chesslib/data/img/template.png +0 -0
  44. chesssnake-0.3.1/chesssnake/chesslib/data/init.sql +18 -0
  45. chesssnake-0.3.1/chesssnake/postgres/Game.py +259 -0
  46. chesssnake-0.3.1/chesssnake/postgres/GameError.py +24 -0
  47. chesssnake-0.3.1/chesssnake/postgres/Sql_Utils.py +42 -0
  48. chesssnake-0.3.1/chesssnake/postgres/__init__.py +0 -0
  49. chesssnake-0.3.1/chesssnake.egg-info/PKG-INFO +138 -0
  50. chesssnake-0.3.1/chesssnake.egg-info/SOURCES.txt +54 -0
  51. chesssnake-0.3.1/chesssnake.egg-info/dependency_links.txt +1 -0
  52. chesssnake-0.3.1/chesssnake.egg-info/requires.txt +7 -0
  53. chesssnake-0.3.1/chesssnake.egg-info/top_level.txt +1 -0
  54. chesssnake-0.3.1/pyproject.toml +3 -0
  55. chesssnake-0.3.1/setup.cfg +4 -0
  56. chesssnake-0.3.1/setup.py +41 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Gabriel Becker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.1
2
+ Name: chesssnake
3
+ Version: 0.3.1
4
+ Summary: A Python library for playing, visualizing, and storing chess games.
5
+ Home-page: https://github.com/GabeBecker2048/chesssnake
6
+ Author: Gabe Becker
7
+ Author-email: gabebecker2048@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pillow~=10.4.0
16
+ Provides-Extra: postgres
17
+ Requires-Dist: psycopg2~=2.9.9; extra == "postgres"
18
+ Provides-Extra: postgres-binary
19
+ Requires-Dist: psycopg2-binary~=2.9.9; extra == "postgres-binary"
20
+
21
+ # Chesssnake
22
+
23
+ *chesssnake* is a feature-packed Python library for playing, visualizing, and storing chess games
24
+
25
+ Pronounced "chess - snake", in reference to Python being a type of snake. It is not pronounced cheesecake
26
+
27
+ ## Features
28
+
29
+ - Play chess in Python with an easy-to-use and intuitive API
30
+ - Store and retrieve chess games in a PostgreSQL database, without having to write any sql
31
+ - Highly optimized SQL included
32
+ - Generate PNG or JPEG images files of your game
33
+ - PIL image support for manipulating images of your chess games
34
+ - Includes a highly optimized python-only chess library
35
+
36
+ ## Installation
37
+
38
+ ### Basic Installation
39
+
40
+ To install the core features of Chesssnake, run:
41
+
42
+ ```bash
43
+ pip install chesssnake
44
+ ```
45
+
46
+ ### With PostgreSQL Support
47
+
48
+ This library uses [psycopg2](https://pypi.org/project/psycopg2/) to communicate with postgres. There are two ways to install psycopg2: with a binary or from source
49
+
50
+ To install chesssnake with PostgresSQL support, using psycopg2-binary **(recommended for beginners, development, and for non-serious purposes)**
51
+ ```commandline
52
+ pip install chesssnake[postgres-binary]
53
+ ```
54
+
55
+ To install chesssnake with PostgresSQL support, using psycopg2 from source **(recommended for production and packaging)**
56
+ ```commandline
57
+ pip install chesssnake[postgres]
58
+ ```
59
+
60
+ See [psycopg2 build prerequisites](https://www.psycopg.org/docs/install.html#build-prerequisites) for prerequisites when installing from source
61
+
62
+ ## Usage
63
+ This library's API is focused around a `Game` object. Every `Game` object represents a game between two players
64
+
65
+ ### Basic usage
66
+
67
+ A simple example:
68
+ ```Python3
69
+ from chesssnake import Game
70
+
71
+ # Initialize a new game
72
+ game = Game(white_name="Bob", black_name="Phil")
73
+
74
+ # Make moves
75
+ game.move('e4') # Bob's move
76
+ game.move('e5') # Phil's move
77
+
78
+ # Print the board
79
+ print(game)
80
+
81
+ # make the move, return a PIL image object, and show the board in png format
82
+ game.move('Nc3', img=True).show()
83
+
84
+ # save the board as a png
85
+ game.save('/path/to/your/image1.png')
86
+
87
+ # make the move, and save the board as a png
88
+ game.move('Bc5', save='/path/to/your/image2.png')
89
+ ```
90
+
91
+ ### With PostgreSQL support
92
+
93
+ If you've installed chesssnake with PostgreSQL support, you can store and retrieve games from a database.
94
+
95
+ Before using chesssnake, you must create environment variables that point to your database. There are many ways to do this, but for this example I will use the [python-dotenv](https://pypi.org/project/python-dotenv/) package to load variables from a `.env` file
96
+
97
+ Create a file named `.env`. Add your database information
98
+ ```commandline
99
+ CHESSDB_NAME='name_of_your_postgresql_db'
100
+ CHESSDB_USER='user_for_your_postgresql_db'
101
+ CHESSDB_PASS='password_for_your_postgresql_user'
102
+ CHESSDB_HOST='host_for_your_postgresql_db'
103
+ CHESSDB_PORT='port_for_your_postgres_db'
104
+ ```
105
+ `CHESSDB_HOST` and `CHESSDB_PORT` are optional, and will default to `localhost` and `5432` respectively
106
+
107
+ Now creating and storing games with PostgreSQL is easy:
108
+
109
+ ```Python3
110
+ from chesssnake import Game
111
+ from dotenv import load_dotenv
112
+
113
+ # load our env vars
114
+ load_dotenv()
115
+
116
+ # Initialize a new game with PostgreSQL
117
+ ## If a game already exists in our database, we load the game into memory
118
+ ## If it doesn't, chesssnake creates a new game in the database and loads a new game into memory
119
+ ## Uniqueness of games is determined by unique combinations of "white_id", "black_id", and "group_id" (all BIG INTs)
120
+ game = Game(
121
+ white_id=123,
122
+ black_id=456,
123
+ group_id=789,
124
+ white_name="Bob",
125
+ black_name="Phil",
126
+ sql=True
127
+ )
128
+
129
+ game.move('e4') # Bob's move
130
+ game.move('e5') # Phil's move
131
+
132
+ # update the database with any new moves
133
+ game.update_db()
134
+ ```
135
+
136
+ If you use `auto_sql` instead of `sql`, your games will be automatically updated with every move and with less transactions.
137
+
138
+ For more information on using chesssnake with PostgreSQL, see the docs (coming soon)
@@ -0,0 +1,118 @@
1
+ # Chesssnake
2
+
3
+ *chesssnake* is a feature-packed Python library for playing, visualizing, and storing chess games
4
+
5
+ Pronounced "chess - snake", in reference to Python being a type of snake. It is not pronounced cheesecake
6
+
7
+ ## Features
8
+
9
+ - Play chess in Python with an easy-to-use and intuitive API
10
+ - Store and retrieve chess games in a PostgreSQL database, without having to write any sql
11
+ - Highly optimized SQL included
12
+ - Generate PNG or JPEG images files of your game
13
+ - PIL image support for manipulating images of your chess games
14
+ - Includes a highly optimized python-only chess library
15
+
16
+ ## Installation
17
+
18
+ ### Basic Installation
19
+
20
+ To install the core features of Chesssnake, run:
21
+
22
+ ```bash
23
+ pip install chesssnake
24
+ ```
25
+
26
+ ### With PostgreSQL Support
27
+
28
+ This library uses [psycopg2](https://pypi.org/project/psycopg2/) to communicate with postgres. There are two ways to install psycopg2: with a binary or from source
29
+
30
+ To install chesssnake with PostgresSQL support, using psycopg2-binary **(recommended for beginners, development, and for non-serious purposes)**
31
+ ```commandline
32
+ pip install chesssnake[postgres-binary]
33
+ ```
34
+
35
+ To install chesssnake with PostgresSQL support, using psycopg2 from source **(recommended for production and packaging)**
36
+ ```commandline
37
+ pip install chesssnake[postgres]
38
+ ```
39
+
40
+ See [psycopg2 build prerequisites](https://www.psycopg.org/docs/install.html#build-prerequisites) for prerequisites when installing from source
41
+
42
+ ## Usage
43
+ This library's API is focused around a `Game` object. Every `Game` object represents a game between two players
44
+
45
+ ### Basic usage
46
+
47
+ A simple example:
48
+ ```Python3
49
+ from chesssnake import Game
50
+
51
+ # Initialize a new game
52
+ game = Game(white_name="Bob", black_name="Phil")
53
+
54
+ # Make moves
55
+ game.move('e4') # Bob's move
56
+ game.move('e5') # Phil's move
57
+
58
+ # Print the board
59
+ print(game)
60
+
61
+ # make the move, return a PIL image object, and show the board in png format
62
+ game.move('Nc3', img=True).show()
63
+
64
+ # save the board as a png
65
+ game.save('/path/to/your/image1.png')
66
+
67
+ # make the move, and save the board as a png
68
+ game.move('Bc5', save='/path/to/your/image2.png')
69
+ ```
70
+
71
+ ### With PostgreSQL support
72
+
73
+ If you've installed chesssnake with PostgreSQL support, you can store and retrieve games from a database.
74
+
75
+ Before using chesssnake, you must create environment variables that point to your database. There are many ways to do this, but for this example I will use the [python-dotenv](https://pypi.org/project/python-dotenv/) package to load variables from a `.env` file
76
+
77
+ Create a file named `.env`. Add your database information
78
+ ```commandline
79
+ CHESSDB_NAME='name_of_your_postgresql_db'
80
+ CHESSDB_USER='user_for_your_postgresql_db'
81
+ CHESSDB_PASS='password_for_your_postgresql_user'
82
+ CHESSDB_HOST='host_for_your_postgresql_db'
83
+ CHESSDB_PORT='port_for_your_postgres_db'
84
+ ```
85
+ `CHESSDB_HOST` and `CHESSDB_PORT` are optional, and will default to `localhost` and `5432` respectively
86
+
87
+ Now creating and storing games with PostgreSQL is easy:
88
+
89
+ ```Python3
90
+ from chesssnake import Game
91
+ from dotenv import load_dotenv
92
+
93
+ # load our env vars
94
+ load_dotenv()
95
+
96
+ # Initialize a new game with PostgreSQL
97
+ ## If a game already exists in our database, we load the game into memory
98
+ ## If it doesn't, chesssnake creates a new game in the database and loads a new game into memory
99
+ ## Uniqueness of games is determined by unique combinations of "white_id", "black_id", and "group_id" (all BIG INTs)
100
+ game = Game(
101
+ white_id=123,
102
+ black_id=456,
103
+ group_id=789,
104
+ white_name="Bob",
105
+ black_name="Phil",
106
+ sql=True
107
+ )
108
+
109
+ game.move('e4') # Bob's move
110
+ game.move('e5') # Phil's move
111
+
112
+ # update the database with any new moves
113
+ game.update_db()
114
+ ```
115
+
116
+ If you use `auto_sql` instead of `sql`, your games will be automatically updated with every move and with less transactions.
117
+
118
+ For more information on using chesssnake with PostgreSQL, see the docs (coming soon)
@@ -0,0 +1,15 @@
1
+ import importlib.metadata
2
+
3
+ def check_optional_dependency(dependency):
4
+ try:
5
+ importlib.metadata.version(dependency)
6
+ return True
7
+ except importlib.metadata.PackageNotFoundError:
8
+ return False
9
+
10
+ if check_optional_dependency("psycopg2") or check_optional_dependency("psycopg2-binary"):
11
+ from .postgres.Game import Game
12
+ else:
13
+ from .chesslib.Game import Game
14
+
15
+ __all__ = ['Game']