-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_of_use.py
More file actions
73 lines (48 loc) · 2.03 KB
/
Copy pathexample_of_use.py
File metadata and controls
73 lines (48 loc) · 2.03 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
# Crear la clase ChessGame con el Builder, esta clase maneja la logica del juego de ajedrez
from src.core.game import ChessGame
from src.builder import BuilderChess
game: ChessGame = BuilderChess.build_game()
# Inicializa el juego
game.init()
# Visualizacion de FEN
print(game.notation_forsyth_edwards) # rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
# Verifiar si el juego aun no termina
state: bool = game.in_running_game # True or False
# Visualizacion de datos con Rich
from src.term.term_view_components import get_view_term_board
from rich.console import Console
console = Console()
# Imprimir el tablero
view_board = get_view_term_board(game.board)
console.print(view_board)
'''
____________________________
| Board |
|___________________________|
A B C D E F G H
8 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 8
7 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 7
6 X X X X X X X X 6
5 X X X X X X X X 5
4 X X X X X X X X 4
3 X X X X X X X X 3
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
A B C D E F G H
'''
# Realiza un movimiento ejemplo: (d2d4, f7e6, g3f2, h8h6)
# Para promocion de peon se añade al final del movimiento el caracter de la ficha al cual sera promovido (q, r, b, n)
from src.core.protocol_uci import FormatUCI
str_mov = "d2d4"
mov_uci = FormatUCI(str_mov)
game.make_mov(mov_uci)
# Visualiza los cambios imprimiendo otra ves el tablero
console.print(view_board)
# reinicia el juego
game.restart_game()
# ejemplo de obtencion de un movimiento de stockfish
from src.utilities_stockfish import get_mov_uci_chess_bot
fen: str = game.notation_forsyth_edwards # "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" FEN de una posición de ajedrez
#mejor_jugada = get_mov_uci_chess_bot(fen_inicial)
uci: str = get_mov_uci_chess_bot(fen)
print(uci) # Obtiene un best move para usarlo como un movimiento enemigo