manim-chess 0.0.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- manim_chess-0.0.1.dist-info/METADATA +212 -0
- manim_chess-0.0.1.dist-info/RECORD +9 -0
- manim_chess-0.0.1.dist-info/WHEEL +5 -0
- manim_chess-0.0.1.dist-info/top_level.txt +1 -0
- src/__init__.py +11 -0
- src/board.py +532 -0
- src/evaluation_bar.py +84 -0
- src/game_player.py +711 -0
- src/pieces.py +246 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: manim_chess
|
3
|
+
Version: 0.0.1
|
4
|
+
Home-page: https://github.com/swoyer2/manim_chess
|
5
|
+
Author: Swoyer2
|
6
|
+
Author-email: swoyer.logan@gmail.com
|
7
|
+
License: MIT
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
9
|
+
Description-Content-Type: text/markdown
|
10
|
+
Provides-Extra: dev
|
11
|
+
Requires-Dist: twine>=4.0.2; extra == "dev"
|
12
|
+
|
13
|
+
# Manim Chess
|
14
|
+
|
15
|
+
This is a [Manim Community](https://www.manim.community/) plugin that allows you to generate a chess board/chess game easily.
|
16
|
+
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
```bash
|
21
|
+
pip install manim-chess
|
22
|
+
```
|
23
|
+
|
24
|
+
## Features
|
25
|
+
|
26
|
+
- **Create Chessboard**: Allows you to create and display a chessboard.
|
27
|
+
- **Move Pieces**: Animate piece movement with PGN notation or the simplified notation in the package.
|
28
|
+
- **Special Moves**: Handle special chess moves like castling and en passant.
|
29
|
+
- **Load FEN Strings**: Load and display a board configuration from a FEN string.
|
30
|
+
- **Play PGN Files**: Load and animate moves from PGN files.
|
31
|
+
- **Evaluation Bar**: Allows the creation and ability to display an evaluation bar.
|
32
|
+
- **Update Evaluation Bar**: Can update the value in the evaluation bar with externally obtained evaulations.
|
33
|
+
- **Mark Squares**: Can mark and unmark squares to highlight them.
|
34
|
+
- **Draw Arrows**: Can draw/undraw arrows similar to chess.com
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
In order to use this package you need to run the script using Manim. I have provided some examples on how to use it
|
39
|
+
below.
|
40
|
+
|
41
|
+
|
42
|
+
### Moving Pieces
|
43
|
+
This example initializes the chessboard and shows how you can move a piece.
|
44
|
+
|
45
|
+
![MovingPieces](https://github.com/swoyer2/manim_chess/blob/main/gifs/moving_pieces.gif)
|
46
|
+
|
47
|
+
|
48
|
+
```python
|
49
|
+
from manim import *
|
50
|
+
import manim_chess
|
51
|
+
|
52
|
+
class MovingPieces(Scene):
|
53
|
+
def construct(self):
|
54
|
+
chess_board = manim_chess.Board()
|
55
|
+
chess_board.set_board_from_FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") # Also can set the default board with no arguments
|
56
|
+
|
57
|
+
# Define the moves you want to be done with the default notation (starting_square, ending_square, promotion_piece)
|
58
|
+
# Note that the promotion piece is blank unless a pawn is promoting
|
59
|
+
moves = [('e2', 'e4', ''), ('e7', 'e5', ''), ('g1', 'f3', '')]
|
60
|
+
|
61
|
+
self.add(chess_board)
|
62
|
+
self.wait()
|
63
|
+
manim_chess.play_game(scene=self, board=chess_board, moves=moves)
|
64
|
+
self.wait()
|
65
|
+
```
|
66
|
+
|
67
|
+
### Using a PGN Notation
|
68
|
+
This example demonstrates playing moves from a PGN file on the chessboard. NOTE if you are starting from a different FEN than the standard start of a game, include FEN=your_fen_string
|
69
|
+
|
70
|
+
![PGNExample](https://github.com/swoyer2/manim_chess/blob/main/gifs/PGN_example.gif)
|
71
|
+
|
72
|
+
|
73
|
+
```python
|
74
|
+
from manim import *
|
75
|
+
import manim_chess
|
76
|
+
|
77
|
+
class PGN_Example(MovingCameraScene):
|
78
|
+
def construct(self):
|
79
|
+
chess_board = manim_chess.Board()
|
80
|
+
chess_board.set_board_from_FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") # Also can set the default board with no arguments
|
81
|
+
|
82
|
+
# You can paste a PGN straight from wherever you got your pgn. Just make it a multiline string with """PGN"""
|
83
|
+
moves = manim_chess.convert_from_PGN("""[Event "It (cat.17)"]
|
84
|
+
[Site "Wijk aan Zee (Netherlands)"]
|
85
|
+
[Date "1999.??.??"]
|
86
|
+
[Round "4"]
|
87
|
+
[White "Kasparov Garry (RUS)"]
|
88
|
+
[Black "Topalov Veselin (BUL)"]
|
89
|
+
[Result "1-0"]
|
90
|
+
[ECO "B07"]
|
91
|
+
[WhiteElo "2851"]
|
92
|
+
[BlackElo "2690"]
|
93
|
+
[Annotator ""]
|
94
|
+
[Source ""]
|
95
|
+
[Remark "I"]
|
96
|
+
[WhiteUrl "https://images.chesscomfiles.com/uploads/v1/master_player/4fe1281a-a9df-11e8-8450-4ff4fd58ed06.bb91bfe2.50x50o.77b8f8a95e5e.jpeg"]
|
97
|
+
[WhiteCountry ""]
|
98
|
+
[WhiteTitle ""]
|
99
|
+
[BlackUrl "https://images.chesscomfiles.com/uploads/v1/master_player/e9640f50-c002-11e8-b93d-e56e1835faa8.4a751865.50x50o.dd0ca3584c8b.png"]
|
100
|
+
[BlackCountry ""]
|
101
|
+
[BlackTitle ""]
|
102
|
+
[Link "https://www.chess.com/analysis/game/master/969971?tab=analysis"]
|
103
|
+
|
104
|
+
1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Be3 Bg7 5. Qd2 c6 6. f3 b5 7. Nge2 Nbd7 8. Bh6
|
105
|
+
Bxh6 9. Qxh6 Bb7 10. a3 e5 11. O-O-O Qe7 12. Kb1 a6 13. Nc1 $6 O-O-O $2 14. Nb3 $6
|
106
|
+
exd4 15. Rxd4 c5 16. Rd1 Nb6 17. g3 $6 Kb8 $6 18. Na5 $6 Ba8 19. Bh3 d5 20. Qf4+
|
107
|
+
Ka7 21. Rhe1 d4 $1 22. Nd5 Nbxd5 23. exd5 Qd6 24. Rxd4 $1 cxd4 $2 25. Re7+ $3 Kb6 26.
|
108
|
+
Qxd4+ Kxa5 27. b4+ $1 Ka4 28. Qc3 $1 Qxd5 29. Ra7 $1 Bb7 30. Rxb7 Qc4 31. Qxf6 Kxa3 $2
|
109
|
+
32. Qxa6+ $1 Kxb4 33. c3+ $1 Kxc3 34. Qa1+ $1 Kd2 35. Qb2+ $1 Kd1 36. Bf1 $3 Rd2 37.
|
110
|
+
Rd7 $3 Rxd7 38. Bxc4 bxc4 39. Qxh8 Rd3 40. Qa8 c3 41. Qa4+ Ke1 42. f4 f5 43. Kc1
|
111
|
+
Rd2 44. Qa7 1-0""")
|
112
|
+
|
113
|
+
self.add(chess_board)
|
114
|
+
self.wait()
|
115
|
+
manim_chess.play_game(scene=self, board=chess_board, moves=moves)
|
116
|
+
self.wait()
|
117
|
+
```
|
118
|
+
|
119
|
+
### Evaluation Bar
|
120
|
+
This example shows how to add and adjust the values of the evaluation bar
|
121
|
+
|
122
|
+
![EvalBarExample](https://github.com/swoyer2/manim_chess/blob/main/gifs/eval_bar.gif)
|
123
|
+
|
124
|
+
|
125
|
+
```python
|
126
|
+
from manim import *
|
127
|
+
import manim_chess
|
128
|
+
|
129
|
+
|
130
|
+
class EvalBarExample(MovingCameraScene):
|
131
|
+
def construct(self):
|
132
|
+
chess_board = manim_chess.Board()
|
133
|
+
chess_board.set_board_from_FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") # Also can set the default board with no arguments
|
134
|
+
|
135
|
+
eval_bar = manim_chess.EvaluationBar()
|
136
|
+
eval_bar.move_to(chess_board.get_left()).shift(LEFT*0.5)
|
137
|
+
|
138
|
+
self.add(chess_board, eval_bar)
|
139
|
+
self.wait()
|
140
|
+
self.play(eval_bar.set_evaluation(1.5))
|
141
|
+
self.wait()
|
142
|
+
self.play(eval_bar.set_evaluation(-3))
|
143
|
+
self.wait()
|
144
|
+
```
|
145
|
+
|
146
|
+
### Marking Squares
|
147
|
+
This example shows how to mark and unmark squares on the chessboard.
|
148
|
+
|
149
|
+
![MarkSquaresExample](https://github.com/swoyer2/manim_chess/blob/main/gifs/mark_squares_example.gif)
|
150
|
+
|
151
|
+
|
152
|
+
```python
|
153
|
+
from manim import *
|
154
|
+
import manim_chess
|
155
|
+
|
156
|
+
|
157
|
+
class MarkSquaresExample(MovingCameraScene):
|
158
|
+
def construct(self):
|
159
|
+
chess_board = manim_chess.Board()
|
160
|
+
chess_board.set_board_from_FEN()
|
161
|
+
|
162
|
+
self.add(chess_board)
|
163
|
+
|
164
|
+
chess_board.mark_square('e4')
|
165
|
+
self.wait()
|
166
|
+
chess_board.mark_square('c5')
|
167
|
+
self.wait()
|
168
|
+
chess_board.unmark_square('e4')
|
169
|
+
chess_board.unmark_square('c5')
|
170
|
+
self.wait()
|
171
|
+
```
|
172
|
+
|
173
|
+
### Draw Arrows
|
174
|
+
This is how you would draw and remove arrows.
|
175
|
+
|
176
|
+
![DrawArrowsExample](https://github.com/swoyer2/manim_chess/blob/main/gifs/draw_arrows_example.gif)
|
177
|
+
|
178
|
+
|
179
|
+
```python
|
180
|
+
from manim import *
|
181
|
+
import manim_chess
|
182
|
+
|
183
|
+
|
184
|
+
class DrawArrowsExample(MovingCameraScene):
|
185
|
+
def construct(self):
|
186
|
+
chess_board = manim_chess.Board()
|
187
|
+
chess_board.set_board_from_FEN()
|
188
|
+
|
189
|
+
self.add(chess_board)
|
190
|
+
|
191
|
+
chess_board.draw_arrow('e2', 'e4')
|
192
|
+
self.wait()
|
193
|
+
chess_board.draw_arrow('b8', 'c6')
|
194
|
+
self.wait()
|
195
|
+
chess_board.draw_arrow('b1', 'a3')
|
196
|
+
self.wait()
|
197
|
+
chess_board.remove_arrows()
|
198
|
+
self.wait()
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
### Running the Examples
|
203
|
+
To run any of the examples, execute the script using Manim. For instance, here is an example on how to render the first example with low quality (if you want high quality replace -pql with -hql)
|
204
|
+
|
205
|
+
```sh
|
206
|
+
manim -pql examples.py MovingPieces
|
207
|
+
```
|
208
|
+
|
209
|
+
Replace `MovingPieces` with the class name of the example you want to run.
|
210
|
+
|
211
|
+
### License
|
212
|
+
This project is licensed under the MIT License. See the LICENSE file for more details.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
src/__init__.py,sha256=x6PCRFc18I6rHgyQfwkxsxS7bsi9i0QDd7zvMZX0gFA,199
|
2
|
+
src/board.py,sha256=FIFEiLzssQRtojcIhWCdkiOlaWOaeJqkknSc29bRzsU,19715
|
3
|
+
src/evaluation_bar.py,sha256=ELjhyFPi5x_Q4Gw3U0FLVhQqN55k8rYCu-lpkru4nPo,3655
|
4
|
+
src/game_player.py,sha256=fESDu5eksZK9ic47CwQNgeq1rpkcMKt0O7_X7-E5lp0,31102
|
5
|
+
src/pieces.py,sha256=890HggU4vGv_PgLyUPnJj2p3ZdivoqG5BukjqsS6MeU,7634
|
6
|
+
manim_chess-0.0.1.dist-info/METADATA,sha256=oSYlLtpXsj6LvT7oKQkLmIIs5g31vLrXyA6VdQ_3U7Y,7257
|
7
|
+
manim_chess-0.0.1.dist-info/WHEEL,sha256=5Mi1sN9lKoFv_gxcPtisEVrJZihrm_beibeg5R6xb4I,91
|
8
|
+
manim_chess-0.0.1.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
|
9
|
+
manim_chess-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
src
|