-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_examples.py
More file actions
96 lines (87 loc) · 2.88 KB
/
user_examples.py
File metadata and controls
96 lines (87 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from manim import *
from src.manim_chessrender import *
class InitializeChessBoard(MovingCameraScene):
"""
Scene to demonstrate initializing the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
chessboard.initialize_board()
self.add(chessboard.board)
self.wait(2)
class MovePieceExample(MovingCameraScene):
"""
Scene to demonstrate moving a piece on the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
chessboard.initialize_board()
self.add(chessboard.board)
self.wait(1)
self.play(chessboard.execute_move('e2e4'))
self.wait(2)
class LoadFENExample(MovingCameraScene):
"""
Scene to demonstrate loading a FEN string into the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
chessboard.load_fen(fen)
self.add(chessboard.board)
self.wait(2)
class CastlingExample(MovingCameraScene):
"""
Scene to demonstrate castling on the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
chessboard.initialize_board()
self.add(chessboard.board)
self.wait(1)
# Move pieces to prepare for castling
moves = ['e2e4', 'e7e5', 'g1f3', 'g8f6', 'f1e2', 'f8e7']
for move in moves:
self.play(chessboard.execute_move(move))
self.play(chessboard.execute_move('e1g1')) # Kingside castling
self.wait(2)
class EnPassantExample(MovingCameraScene):
"""
Scene to demonstrate the en passant move on the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
chessboard.initialize_board()
self.add(chessboard.board)
self.wait(1)
# Move pieces to prepare for en passant
moves = ['e2e4', 'e7e5', 'd2d4', 'e5d4', 'c2c4']
for move in moves:
self.play(chessboard.execute_move(move))
self.play(chessboard.execute_move('d4c3')) # En passant
self.wait(2)
class PlayPGNExample(MovingCameraScene):
"""
Scene to demonstrate playing moves from a PGN file on the chessboard.
"""
def construct(self):
chessboard = ChessBoard()
chessboard.initialize_board()
self.add(chessboard.board)
self.wait(1)
games = chessboard.load_pgn_and_get_games("./example/example.pgn")
game = games[0]
for move in game:
self.play(chessboard.execute_move(move.uci()))
self.wait(0.5)
if __name__ == "__main__":
scenes = [
InitializeChessBoard,
MovePieceExample,
LoadFENExample,
CastlingExample,
EnPassantExample,
PlayPGNExample]
for scene in scenes:
scene_instance = scene()
scene_instance.render()