add train/test files and builder code
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- ChessBot-Dataset.py +53 -0
- ChessBot-dataset-0.1.0.zip +0 -3
- test/chesspgn_1.pgn +0 -0
- test/chesspgn_106.pgn +0 -0
- test/chesspgn_111.pgn +0 -0
- test/chesspgn_130.pgn +0 -0
- test/chesspgn_148.pgn +0 -0
- test/chesspgn_152.pgn +0 -0
- test/chesspgn_179.pgn +0 -0
- test/chesspgn_182.pgn +0 -0
- test/chesspgn_184.pgn +0 -0
- test/chesspgn_186.pgn +0 -0
- test/chesspgn_202.pgn +0 -0
- test/chesspgn_206.pgn +0 -0
- test/chesspgn_212.pgn +0 -0
- test/chesspgn_213.pgn +0 -0
- test/chesspgn_218.pgn +0 -0
- test/chesspgn_222.pgn +0 -0
- test/chesspgn_231.pgn +0 -0
- test/chesspgn_259.pgn +0 -0
- test/chesspgn_271.pgn +0 -0
- test/chesspgn_292.pgn +0 -0
- test/chesspgn_305.pgn +0 -0
- test/chesspgn_306.pgn +0 -0
- test/chesspgn_308.pgn +0 -0
- test/chesspgn_310.pgn +0 -0
- test/chesspgn_312.pgn +0 -0
- test/chesspgn_327.pgn +0 -0
- test/chesspgn_346.pgn +0 -0
- test/chesspgn_365.pgn +0 -0
- test/chesspgn_372.pgn +0 -0
- test/chesspgn_373.pgn +0 -0
- test/chesspgn_379.pgn +0 -0
- test/chesspgn_381.pgn +0 -0
- test/chesspgn_387.pgn +0 -0
- test/chesspgn_389.pgn +0 -0
- test/chesspgn_390.pgn +0 -0
- test/chesspgn_403.pgn +0 -0
- test/chesspgn_417.pgn +0 -0
- test/chesspgn_419.pgn +0 -0
- test/chesspgn_424.pgn +0 -0
- test/chesspgn_440.pgn +0 -0
- test/chesspgn_458.pgn +0 -0
- test/chesspgn_465.pgn +0 -0
- test/chesspgn_486.pgn +0 -0
- test/chesspgn_509.pgn +0 -0
- test/chesspgn_522.pgn +0 -0
- test/chesspgn_532.pgn +0 -0
- test/chesspgn_536.pgn +0 -0
- test/chesspgn_560.pgn +0 -0
ChessBot-Dataset.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import glob, os, chess.pgn
|
| 2 |
+
from datasets import (
|
| 3 |
+
GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
|
| 4 |
+
Features, Value, Array2D
|
| 5 |
+
)
|
| 6 |
+
from adversarial_gym.chess_env import ChessEnv
|
| 7 |
+
|
| 8 |
+
class ChessPGNDataset(GeneratorBasedBuilder):
|
| 9 |
+
VERSION = "0.0.1"
|
| 10 |
+
|
| 11 |
+
def _info(self):
|
| 12 |
+
return DatasetInfo(
|
| 13 |
+
description="Chess positions + moves + results, streamed from PGN shards",
|
| 14 |
+
features=Features({
|
| 15 |
+
"state": Array2D((8,8), dtype="int8"),
|
| 16 |
+
"action": Value("int16"),
|
| 17 |
+
"result": Value("int8"),
|
| 18 |
+
})
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
def _split_generators(self, dl_manager):
|
| 22 |
+
# data_dir is the root of your dataset repo
|
| 23 |
+
data_dir = self.config.data_dir
|
| 24 |
+
return [
|
| 25 |
+
SplitGenerator(
|
| 26 |
+
name=Split.TRAIN,
|
| 27 |
+
gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"train","*.pgn"))}
|
| 28 |
+
),
|
| 29 |
+
SplitGenerator(
|
| 30 |
+
name=Split.TEST,
|
| 31 |
+
gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"test","*.pgn"))}
|
| 32 |
+
),
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
def _generate_examples(self, shards):
|
| 36 |
+
uid = 0
|
| 37 |
+
for path in sorted(shards):
|
| 38 |
+
with open(path, "r") as f:
|
| 39 |
+
while (game := chess.pgn.read_game(f)) is not None:
|
| 40 |
+
board = game.board()
|
| 41 |
+
base = {"1-0":1,"0-1":-1}.get(game.headers["Result"], 0)
|
| 42 |
+
for move in game.mainline_moves():
|
| 43 |
+
state = ChessEnv.get_piece_configuration(board)
|
| 44 |
+
state = state if board.turn else -state
|
| 45 |
+
action = ChessEnv.move_to_action(move)
|
| 46 |
+
result = base * (-1 if board.turn == 0 else 1)
|
| 47 |
+
yield uid, {
|
| 48 |
+
"state": state.astype("int8"),
|
| 49 |
+
"action": int(action),
|
| 50 |
+
"result": int(result),
|
| 51 |
+
}
|
| 52 |
+
uid += 1
|
| 53 |
+
board.push(move)
|
ChessBot-dataset-0.1.0.zip
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:3ab9e11d0af2b6e6fe2831837dbb96446d882ab544ae96d7e184f130f078b4f9
|
| 3 |
-
size 2547657186
|
|
|
|
|
|
|
|
|
|
|
|
test/chesspgn_1.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_106.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_111.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_130.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_148.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_152.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_179.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_182.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_184.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_186.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_202.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_206.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_212.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_213.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_218.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_222.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_231.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_259.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_271.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_292.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_305.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_306.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_308.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_310.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_312.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_327.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_346.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_365.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_372.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_373.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_379.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_381.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_387.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_389.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_390.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_403.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_417.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_419.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_424.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_440.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_458.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_465.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_486.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_509.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_522.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_532.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_536.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test/chesspgn_560.pgn
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|