add legal actions
Browse files- ChessBot-Dataset.py +4 -0
ChessBot-Dataset.py
CHANGED
|
@@ -9,6 +9,7 @@ from datasets import (
|
|
| 9 |
Features,
|
| 10 |
Value,
|
| 11 |
Array2D,
|
|
|
|
| 12 |
)
|
| 13 |
import chess
|
| 14 |
from adversarial_gym.chess_env import ChessEnv
|
|
@@ -26,6 +27,7 @@ class ChessPGNDataset(GeneratorBasedBuilder):
|
|
| 26 |
"state": Array2D((8,8), dtype="int8"),
|
| 27 |
"action": Value("int16"),
|
| 28 |
"best_action": Value("int16"), # -1 if not available
|
|
|
|
| 29 |
"result": Value("float32"),
|
| 30 |
})
|
| 31 |
)
|
|
@@ -106,10 +108,12 @@ class ChessPGNDataset(GeneratorBasedBuilder):
|
|
| 106 |
state = ChessEnv.get_piece_configuration(board)
|
| 107 |
state = state if board.turn else -state
|
| 108 |
action = ChessEnv.move_to_action(move)
|
|
|
|
| 109 |
yield uid, {
|
| 110 |
"state": state.astype("int8"),
|
| 111 |
"action": int(action),
|
| 112 |
"best_action": int(best_action),
|
|
|
|
| 113 |
"result": float(result),
|
| 114 |
}
|
| 115 |
uid += 1
|
|
|
|
| 9 |
Features,
|
| 10 |
Value,
|
| 11 |
Array2D,
|
| 12 |
+
Sequence,
|
| 13 |
)
|
| 14 |
import chess
|
| 15 |
from adversarial_gym.chess_env import ChessEnv
|
|
|
|
| 27 |
"state": Array2D((8,8), dtype="int8"),
|
| 28 |
"action": Value("int16"),
|
| 29 |
"best_action": Value("int16"), # -1 if not available
|
| 30 |
+
"legal_actions": Sequence(Value("int16")),
|
| 31 |
"result": Value("float32"),
|
| 32 |
})
|
| 33 |
)
|
|
|
|
| 108 |
state = ChessEnv.get_piece_configuration(board)
|
| 109 |
state = state if board.turn else -state
|
| 110 |
action = ChessEnv.move_to_action(move)
|
| 111 |
+
legal = [int(ChessEnv.move_to_action(m)) for m in board.legal_moves]
|
| 112 |
yield uid, {
|
| 113 |
"state": state.astype("int8"),
|
| 114 |
"action": int(action),
|
| 115 |
"best_action": int(best_action),
|
| 116 |
+
"legal_actions": legal,
|
| 117 |
"result": float(result),
|
| 118 |
}
|
| 119 |
uid += 1
|