Skip to content

Commit

Permalink
Merge pull request #1 from xboard/release
Browse files Browse the repository at this point in the history
Release v1.0
  • Loading branch information
xboard authored Jan 25, 2021
2 parents 7bbfbb8 + f4a6654 commit 39448ab
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/cmake-build-debug-coverage/
/cmake-build-release/
/cmake-build-release-quiet/
/build
/.vscode
/main_submit.cpp
/a.out
/cppcheck.txt
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ My submission to [CodeCup](https://www.codecup.nl/zuniq) 2021. Ranked [15º](ht

## Setting up the build

Dependencies:
* `g++ 7.5+` or `clang++ 3.8+`
* `CMake 3.16+`

The test suite uses [Catch](https://github.com/catchorg/Catch2) v2.13 but it is already included in the `lib` directory.

After cloning this repository (or uncompressing a [release](https://github.com/xboard/mcts_zuniq/release)), go to the source code diretory and write:
```shell
mkdir -p build
cd build/
Expand All @@ -36,14 +43,32 @@ in directory `build/`

<p align="center"><img src="/img/zuniq_black.gif" alt="Playing as black"/></p>

## References

* [An Introduction to Monte Carlo Tree Search](https://github.com/italiancpp/cppday19/blob/master/An%20Introduction%20toMonte%20Carlo%20Tree%20Search%20-%20Manlio%20Morini.pdf)
Click [here](https://www.codecup.nl/zuniq/rules.php) to learn the rules of Zuniq and how to comunicate with zuniq engine.


## Code Structure

There are two main CMake executable targets:
* `zuniq` runs the game engine.
* `zuniq_tests` or `all_tests` runs [Catch2](https://github.com/catchorg/Catch2) tests.


All engine internal data structures and algorithms are in file `zuniq.hpp` with some monte carlo tree search configuration parameters in file `config.hpp`. File `main.cpp` is just a driver to run the engine and `tests_runner.cpp` is a driver for test cases in `tests.cpp`.

The competition has a technical restriction that submissions must be in a single file, and thats what the python script `generate_submission_file.py` does, generating the file `main_submit.cpp` to be submitted.

Just for convenience during the competition there is a `compile.sh` that runs the single file generation script and build (using competition C++ build flag parameters) to an `a.out` executable (which is as similar as possible to the `zuniq` executable generated by CMake).

Script `static-analysis.sh` is used in `.github/workflow/cmake.yml` Github Actions workflow.

## Zuniq API and simple app

Boris_de_Wilde's [API](https://dewildeit.nl/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config) and
[web app](https://dewildeit.nl/zuniq/) to play against your own bot.
[web app](https://dewildeit.nl/zuniq/) to play against this (or other) engine in a web interface.


## Monte Carlo Tree Search references

* [Monte Carlo Tree Search](https://en.wikipedia.org/wiki/Monte_Carlo_tree_search)
* [An Introduction to Monte Carlo Tree Search](https://github.com/italiancpp/cppday19/blob/master/An%20Introduction%20toMonte%20Carlo%20Tree%20Search%20-%20Manlio%20Morini.pdf)
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

# author: Flavio Regis de Arruda
FILE=main_submit.cpp

rm $FILE
Expand Down
11 changes: 0 additions & 11 deletions gen_test.py

This file was deleted.

1 change: 1 addition & 0 deletions generate_submission_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# author: Flavio Regis de Arruda

import re
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "zuniq.hpp"

int main() {
assert(false); // should never abort. If it does, define NDEBUG.
cerr << "Zuniq version 1.0.0" << " (" << __DATE__ << " " << __TIME__ << ")" << endl;
#ifdef QUIET_MODE
cerr << "Zuniq rules: https://www.codecup.nl/zuniq/rules.php" << endl;
Expand Down
1 change: 1 addition & 0 deletions static-analysis.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# author: Flavio Regis de Arruda

# Remove files from previous executions.
rm -f cppcheck.txt clang-tidy.txt
Expand Down
6 changes: 6 additions & 0 deletions zuniq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ class MCTSAgent : public Agent {
MCTSNode root = MCTSNode(sgs, nullptr, make_optional<Move>(), rng_);
for (uint32_t i = 0; i < num_rounds_; i++) {
if ((i % 10 == 0) && (timer.elapsed_milli() >= ts_->max_move_time(ctx))) {
#ifndef QUIET_MODE
cerr << "[I]: num_rounds: " << i << "/" << num_rounds_ << endl;
#endif
break;
}
MCTSNode *node = &root;
Expand Down Expand Up @@ -1027,12 +1029,16 @@ void game_loop() {
}
} else if (holds_alternative<Move>(parsed)) {
Move move = std::get<Move>(parsed);
#ifndef QUIET_MODE
cerr << "[I]: Opp took " << opponent_timer.elapsed_milli() << "ms " << IO::format_move(move) << '\n';
#endif
bool is_winning = false;
if (!board.is_valid(move)) throw std::runtime_error("Move " + IO::format_move(move) + " is invalid!");
board.apply_move(move);
++round_number;
#ifndef QUIET_MODE
cerr << "[I]: rnd " << round_number << " #avail_moves " << board.get_available_moves().size() << endl;
#endif
elapsed_time += timer.elapsed_milli();
timer.start();
if (round_number < NUM_RANDOM_MOVE_ROUNDS)
Expand Down

0 comments on commit 39448ab

Please sign in to comment.