Skip to content

Commit

Permalink
initial commit for CrazyAra 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
QueensGambit committed Oct 22, 2018
1 parent a6d03ab commit 53f3060
Show file tree
Hide file tree
Showing 803 changed files with 1,228,097 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,12 @@ venv.bak/
# prevent weights push for mxnet format
*.params
*symbol.json

# avoid pushing any lock files
*.~lock

# avoid pushing the main_config.py file
main_config.py

# avoid pushing log-files generated by uci-communication
CrazyAra-log.txt
Empty file added DeepCrazyhouse/__init__.py
Empty file.
Empty file.
45 changes: 45 additions & 0 deletions DeepCrazyhouse/configs/main_config_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
@file: main_config.py
Created on 24.09.18
@project: crazyara
@author: queensgambit
Main Config definition file used for the project.
Copy and rename this file to main_config.py and adjust the paths accordingly.
"""


main_config = {

# Copy and rename this file to main_config.py

# The training directory includes games from the months: 2016-01 - 2018-07 (excluding 2018-04)
# The validation directory includes games from the month: 2018-04
# The test directory includes games from the month: 2018-08

# The pgn directories contain all files which are converted to plane representation
"pgn_train_dir": "/home/demo_user/datasets/lichess/Crazyhouse/pgn/train/",
"pgn_val_dir": "/home/demo_user/datasets/lichess/Crazyhouse/pgn/val/",
"pgn_test_dir": "/home/demo_user/datasets/lichess/Crazyhouse/pgn/test/",
"pgn_mate_in_one_dir": "/home/demo_user/datasets/lichess/Crazyhouse/pgn/mate_in_one/",

# The plane directories contain the plane representation of the converted board state
# (.zip files which have been compressed by the python zarr library)
"planes_train_dir": "/home/demo_user/datasets/lichess/Crazyhouse/planes/train/",
"planes_val_dir": "/home/demo_user/datasets/lichess/Crazyhouse/planes/val/",
"planes_test_dir": "/home/demo_user/datasets/lichess/Crazyhouse/planes/test/",
"planes_mate_in_one_dir": "/home/demo_user/datasets/lichess/Crazyhouse/planes/mate_in_one/",

# The rec directory contains the plane representation which are used in the training loop of the network
# use the the notebook create_rec_dataset to generate the .rec files:
# (Unfortunately when trying to start training with the big dataset a memory overflow occured.
# therfore the old working solution was used to train the latest model by loading the dataset via batch files)
# "train.idx", "val.idx", "test.idx", "mate_in_one.idx", "train.rec", "val.rec", "test.rec", "mate_in_one.rec"
"rec_dir": "/home/demo_user/datasets/lichess/Crazyhouse/rec/",

# The architecture dir contains the architecture definition of the network in mxnet .symbol format
# These directories are used for inference
"model_architecture_dir": "/home/demo_user/models/Crazyhouse/symbol/",
# the weight directory contains the of the network in mxnet .params format
"model_weights_dir": "/home/demo_user/models/Crazyhouse/params/"
}
110 changes: 110 additions & 0 deletions DeepCrazyhouse/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Project specific ignores
main_config.json


# Gitignore for python - Source: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
58 changes: 58 additions & 0 deletions DeepCrazyhouse/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Crazy House Project Source

## Setup
This project uses MXNet. To install MXNet look at
[https://mxnet.incubator.apache.org/install/index.html](https://mxnet.incubator.apache.org/install/index.html)

Copy and rename the `main_config_sample.py` to `main_config.py`. Adjust the `dataset`
property to the correct location on your file system.

## General project structure
The source code is divided into four main parts: model, training, experiments and
samples. The different parts are located in identically named folders.

The `domain` folder contains domain classes, which present the problem domain of Crazyhouse.
We define 'domain' in the sence of a data class (as it is commonly defined as
e.g. in the Model-View-Controller pattern).
This includes classes to load, store and (pre)process game data, as well as
classes to analyse, evaluate, or modify board positions.

The `training` folder contains classes to train, evaluate and test
neural networks. Each class typically represents a single Trainer, which
later can be setup and run in the different experiments.

The `experiments` folder stores all experiments run for this project. For each
experiment a new jupyter notebook has to be created. The notebook should briefly
describe the experiment setup. The experiments code as well as the resulting
output should be saved directly within the notebook.

The `samples` folder contains a collection of arbitrary python files or
jupyter notebooks, to demonstrate some code or test functionality.


All python code should (more or less) follow the PEP8 standard.


## Folder structure
```
|- domain
| Classes to which describe the Crazyhouse domain for neural networks
|- training
| Setup scripts to be using in training.
| (loading data, setting up learners, ...)
|- experiments
| Folder containing the results of the run experiments.
|- mw000_sample.ipynb
| Demo template to start with
|- {user_id}{id}_{experiment_name}.ipynb
Naming should follow this naming pattern to prevent
merge conficts.
```

---

Avoid committing the outputs of jupyter notebook files by using the script `ipynb_output_filter.py` on the repository
* https://github.com/toobaz/ipynb_output_filter

The repository includes instructions on how to set-up an automatic workflow.

Empty file added DeepCrazyhouse/src/__init__.py
Empty file.
Empty file.
56 changes: 56 additions & 0 deletions DeepCrazyhouse/src/domain/abstract_cls/_GameState.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
@file: _GameState.py
Created on 14.10.18
@project: crazy_ara_refactor
@author: queensgambit
Please describe what the content of this file is about
"""

import chess
import chess.variant


class _GameState:

def __init__(self, board):
self.board = board
self._fen_dic = {}

def apply_move(self, move: chess.Move, remember_state=False):
self.board.push(move)

def get_state_planes(self):

raise NotImplementedError('get_state_planes() should return board_to_planes(self.board, 0, normalize=True)')
return board_to_planes(self.board, 0, normalize=True)

def get_pythonchess_board(self):
return self.board

def is_draw(self):
# check if you can claim a draw - its assumed that the draw is always claimed
return self.board.can_claim_draw()

def is_won(self):
raise NotImplementedError()
# only a is_won() and no is_lost() function is needed because the game is over
# after the player found checkmate successfully
return self.board.is_checkmate()

def get_legal_moves(self):
return self.board.legal_moves

def is_white_to_move(self):
return self.board.turn

def __str__(self):
return self.board.fen()

def get_board_fen(self):
# create an identifier string for the board state by dropping the move clock
return self.board.fen()
#return self.board.fen().rsplit(' ', 1)[0]

def new_game(self):
raise NotImplementedError
8 changes: 8 additions & 0 deletions DeepCrazyhouse/src/domain/abstract_cls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
@file: __init__.py
Created on 14.10.18
@project: crazy_ara_refactor
@author: queensgambit
Please describe what the content of this file is about
"""
Loading

0 comments on commit 53f3060

Please sign in to comment.