Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hex #172

Merged
merged 68 commits into from
Mar 31, 2022
Merged

Hex #172

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
3b42e05
some little changes to make the evaluator framework easier to use
Aug 9, 2021
d9f95ae
merge current upstream to StrategoAra
Aug 27, 2021
bdf30b0
merge current upstream to StrategoAra part 2, missed optionsuci.cpp
Aug 27, 2021
e0531d1
Inverse if condition for style
BluemlJ Sep 21, 2021
42bcb5c
update commit for openSpiel repository
BluemlJ Sep 21, 2021
b6fb581
if condition inverse v2
BluemlJ Sep 21, 2021
f0e7cf8
v3
BluemlJ Sep 21, 2021
b1f26d9
update open_spiel
Nov 22, 2021
e5b7b8d
add Dark Hex
Nov 22, 2021
b093d5b
remove two small errors
Nov 22, 2021
67043f6
add HEX and Dark Hex
Nov 22, 2021
4731933
update openSpiel - Dark Hex and Hex
Nov 22, 2021
60890d1
removed Pie rule from dark hex
Nov 22, 2021
52868a0
Update CMakeLists.txt
BluemlJ Nov 23, 2021
459200e
set config to OpenSpielAra
Nov 30, 2021
25e192f
add Dockerfile for Hex
Nov 30, 2021
3c41df0
set Build mode to release instead of relwithdebinfo
Nov 30, 2021
b0ed202
qMerge branch 'hex' of github.com:BluemlJ/CrazyAra into hex
Nov 30, 2021
dda1233
update open_spiel
Nov 30, 2021
ff00cdb
update OpenSpiel Hex for DGX use
Dec 2, 2021
0b69eee
update OpenSpiel
Dec 2, 2021
9ccb8ef
remove ply from copied init state in selfplay
Dec 2, 2021
a7a390d
getPlane OpenSpielState
Dec 2, 2021
e9d19fb
update getStatesPlane and model architecture
Dec 3, 2021
8e289e3
OpenSpiel update v2
Dec 3, 2021
3252d0a
OpenSpiel update
Dec 3, 2021
237a2ca
update Open_Spiel
Dec 21, 2021
e48ca72
update Open_Spiel now correct
Dec 21, 2021
e2e503e
change rl_config and update amount of test samples needed
Dec 21, 2021
ece0463
Casesensitivity and yes
Dec 21, 2021
849de39
remove error from last commit - empty return
Dec 21, 2021
4c40a9a
enable tournament mode also for games other then Stratego
Dec 21, 2021
7a94b19
flip actions for white
Dec 28, 2021
699d6e0
fix the boardsize for temporary test2
Dec 28, 2021
b0a9ca6
fix the boardsize for temporary test3
Dec 28, 2021
9240689
fix the boardsize for temporary test4
Dec 28, 2021
47ed43a
fix the boardsize for temporary test5
Dec 28, 2021
7a6cc9e
fix the boardsize for temporary test5
Dec 28, 2021
42d2919
fix the boardsize for temporary test6
Dec 28, 2021
2ce766b
fix the boardsize for temporary test7
Dec 28, 2021
0036a5b
fix the boardsize for temporary test8 - infinity and beyond
Dec 28, 2021
1ec8975
update OpenSpiel
Mar 8, 2022
d1a053c
update OpenSpiel
Mar 8, 2022
7dfb2e4
Update Variants.h for Stratego and Hex
BluemlJ Mar 30, 2022
a610ead
Update variants.h
BluemlJ Mar 30, 2022
b61fa42
Update variants.yml
BluemlJ Mar 30, 2022
7a40680
Update variants.yml
BluemlJ Mar 30, 2022
1913240
Create only_new_variants.yml
BluemlJ Mar 30, 2022
9b8bf09
Update only_new_variants.yml
BluemlJ Mar 30, 2022
5b4175a
Create only_new_variants.yml
BluemlJ Mar 30, 2022
c740457
Update only_new_variants.yml
BluemlJ Mar 30, 2022
95d8d5b
Update only_new_variants.yml
BluemlJ Mar 30, 2022
db85165
Merge branch 'master' into hex
BluemlJ Mar 30, 2022
6c8afbd
Update CMakeLists.txt
BluemlJ Mar 30, 2022
ebc806f
Merge branch 'master' into hex
BluemlJ Mar 31, 2022
90ed941
Delete only_new_variants.yml
QueensGambit Mar 31, 2022
fb4a338
Delete train_config_template.py
BluemlJ Mar 31, 2022
158238e
Delete rl_config.py
BluemlJ Mar 31, 2022
c694df9
Delete Dockerfile_Hex
BluemlJ Mar 31, 2022
27c4a2e
Update openspielstate.cpp
BluemlJ Mar 31, 2022
25f81a8
Update openspielstate.cpp
BluemlJ Mar 31, 2022
b12072d
Update selfplay.cpp
BluemlJ Mar 31, 2022
1a3295f
Delete openBoard()
QueensGambit Mar 31, 2022
e9ecf62
Update CMakeLists.txt
BluemlJ Mar 31, 2022
50c710a
Update variants.h
BluemlJ Mar 31, 2022
5f0066c
Delete openBoard()
QueensGambit Mar 31, 2022
92cfeb6
Add Configs again
BluemlJ Mar 31, 2022
842911b
Update train_confi_template.py
BluemlJ Mar 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/variants.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: variants

on: [ pull_request, workflow_dispatch ]
Expand Down Expand Up @@ -33,17 +32,17 @@ jobs:
pwd
chmod +x install.sh
sudo ./install.sh

- name: Configure CMake
working-directory: ${{github.workspace}}/engine
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
mkdir build
cmake -B ./build/chess -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=1 -DMODE_LICHESS=0 -DMODE_XIANGQI=0 -DMODE_STRATEGO=0 .
cmake -B ./build/lichess -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=1 -DMODE_XIANGQI=0 -DMODE_STRATEGO=0 .
cmake -B ./build/xiangqi -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=0 -DMODE_XIANGQI=1 -DMODE_STRATEGO=0 .
cmake -B ./build/stratego -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=0 -DMODE_XIANGQI=0 -DMODE_STRATEGO=1 .
cmake -B ./build/chess -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=1 -DMODE_LICHESS=0 -DMODE_XIANGQI=0 -DMODE_STRATEGO=0 -DMODE_OPEN_SPIEL=0 .
cmake -B ./build/lichess -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=1 -DMODE_XIANGQI=0 -DMODE_STRATEGO=0 -DMODE_OPEN_SPIEL=0 .
cmake -B ./build/xiangqi -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=1 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=0 -DMODE_XIANGQI=1 -DMODE_STRATEGO=0 -DMODE_OPEN_SPIEL=0 .
cmake -B ./build/stratego -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=0 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=0 -DMODE_XIANGQI=0 -DMODE_STRATEGO=1 -DMODE_OPEN_SPIEL=0 .
cmake -B ./build/hex -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_PROFILING=0 -DUSE_RL=0 -DBACKEND_TENSORRT=0 -DBACKEND_MXNET=0 -DBACKEND_TORCH=0 -DUSE_960=0 -DBUILD_TESTS=0 -DMODE_CRAZYHOUSE=0 -DMODE_CHESS=0 -DMODE_LICHESS=0 -DMODE_XIANGQI=0 -DMODE_STRATEGO=0 -DMODE_OPEN_SPIEL=1 .

- name: Build
# Build your program with the given configuration
Expand All @@ -52,6 +51,7 @@ jobs:
cmake --build ${{github.workspace}}/engine/build/lichess --config ${{env.BUILD_TYPE}}
cmake --build ${{github.workspace}}/engine/build/xiangqi --config ${{env.BUILD_TYPE}}
cmake --build ${{github.workspace}}/engine/build/stratego --config ${{env.BUILD_TYPE}}
cmake --build ${{github.workspace}}/engine/build/hex --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/engine
Expand All @@ -62,3 +62,4 @@ jobs:
./build/lichess/MultiAra
./build/xiangqi/XiangqiAra
./build/stratego/StrategoAra
./build/hex/OpenSpielAra
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[submodule "engine/3rdparty/Stockfish"]
path = engine/3rdparty/Stockfish
url = https://github.com/QueensGambit/Stockfish.git
[submodule "engine/3rdparty/open_spiel"]
path = engine/3rdparty/open_spiel
url = https://github.com/BluemlJ/open_spiel.git
branch = thesis
[submodule "engine/3rdparty/Fairy-Stockfish"]
path = engine/3rdparty/Fairy-Stockfish
url = https://github.com/xsr7qsr/Fairy-Stockfish.git
[submodule "engine/3rdparty/blaze"]
path = engine/3rdparty/blaze
url = https://bitbucket.org/blaze-lib/blaze.git
[submodule "engine/3rdparty/open_spiel"]
path = engine/3rdparty/open_spiel
url = https://github.com/BluemlJ/open_spiel.git
1 change: 0 additions & 1 deletion DeepCrazyhouse/configs/rl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ class UCIConfigArena:
Centi_Temperature: int = 60



Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ class TrainObjects:
momentum_schedule = None
metrics = None
variant_metrics = None

2 changes: 1 addition & 1 deletion engine/3rdparty/open_spiel
Submodule open_spiel updated 383 files
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ if (MODE_OPEN_SPIEL OR MODE_STRATEGO)
"3rdparty/open_spiel/open_spiel/games/chess/*.cc"
"3rdparty/open_spiel/open_spiel/games/hex.h"
"3rdparty/open_spiel/open_spiel/games/hex.cc"
"3rdparty/open_spiel/open_spiel/games/dark_hex.h"
"3rdparty/open_spiel/open_spiel/games/dark_hex.cc"
)
endif()

Expand Down
16 changes: 11 additions & 5 deletions engine/src/environments/open_spiel/openspielstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ inline void OpenSpielState::check_variant(int variant)
void OpenSpielState::set(const std::string &fenStr, bool isChess960, int variant)
{
check_variant(variant);
if (currentVariant == open_spiel::gametype::SupportedOpenSpielVariants::HEX) {
info_string_important("NewInitialState from string is not implemented for HEX.");
return;
}
spielState = spielGame->NewInitialState(fenStr);
}

void OpenSpielState::get_state_planes(bool normalize, float *inputPlanes, Version version) const
{
std::fill(inputPlanes, inputPlanes+StateConstantsOpenSpiel::NB_VALUES_TOTAL(), 0.0f);
// TODO
//info_string_important(StateConstantsOpenSpiel::NB_VALUES_TOTAL());
std::vector<float> v(spielGame->ObservationTensorSize());
spielState->ObservationTensor(spielState->CurrentPlayer(), absl::MakeSpan(v));
std::copy( v.begin(), v.end(), inputPlanes);
}

unsigned int OpenSpielState::steps_from_null() const
Expand All @@ -86,6 +85,13 @@ std::string OpenSpielState::fen() const

void OpenSpielState::do_action(Action action)
{
auto player = spielState->CurrentPlayer();
if(player == 1){
int X = action / 11; //currently easier to set board size fix; change it later
int Y = action % 11;
spielState->ApplyAction(Y*11+X);
return;
}
spielState->ApplyAction(action);
}

Expand Down
20 changes: 11 additions & 9 deletions engine/src/environments/open_spiel/openspielstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#include "open_spiel/spiel.h"
#include "open_spiel/games/chess.h"
#include "open_spiel/games/hex.h"
#include "open_spiel/games/dark_hex.h"

namespace open_spiel {
namespace gametype {
enum SupportedOpenSpielVariants : uint8_t {
HEX = 0, // 11x11 board
CHESS = 1,
YORKTOWN = 2,
DARKHEX = 1,
CHESS = 2,
YORKTOWN = 3,
};
}
}
Expand All @@ -47,33 +49,33 @@ class StateConstantsOpenSpiel : public StateConstantsInterface<StateConstantsOpe
{
public:
static uint BOARD_WIDTH() {
return open_spiel::chess::kDefaultBoardSize;
return open_spiel::hex::kDefaultBoardSize;
}
static uint BOARD_HEIGHT() {
return open_spiel::chess::kDefaultBoardSize;
return open_spiel::hex::kDefaultBoardSize;
}
static uint NB_CHANNELS_TOTAL() {
return 34U; // TODO
return 9; // TODO
}
static uint NB_LABELS() {
return 2272U; // TODO
return 121; // NB_CHANNELS_TOTAL()*BOARD_HEIGHT()*BOARD_WIDTH(); // TODO
}
static uint NB_LABELS_POLICY_MAP() {
return 5184U; // TODO
return BOARD_HEIGHT()*BOARD_WIDTH(); // TODO
}
static uint NB_AUXILIARY_OUTPUTS() {
return 0U;
}
static int NB_PLAYERS() {
return open_spiel::chess::NumPlayers();
return open_spiel::hex::kNumPlayers;
}
static std::string action_to_uci(Action action, bool is960) {
// TODO use actual uci for this
return std::to_string(action);
}
template<PolicyType p = normal, MirrorType m = notMirrored>
static MoveIdx action_to_index(Action action) {
return 0; // TODO
return action; // TODO
}
static void init(bool isPolicyMap) {
return; // pass
Expand Down
2 changes: 2 additions & 0 deletions engine/src/rl/selfplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ Result SelfPlay::generate_arena_game(MCTSAgent* whitePlayer, MCTSAgent* blackPla
gamePGN.white = whitePlayer->get_name();
gamePGN.black = blackPlayer->get_name();
unique_ptr<StateObj> state= make_unique<StateObj>();
//unique_ptr<StateObj> state = init_starting_state_from_raw_policy(*rawAgent, 0, gamePGN, variant, is960, rlSettings->rawPolicyProbabilityTemperature);

if (fen != "") {
// set starting fen
state->set(fen, is960, variant);
Expand Down
4 changes: 2 additions & 2 deletions engine/src/uci/crazyara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ void CrazyAra::uci_loop(int argc, char *argv[])
#ifdef USE_RL
else if (token == "selfplay") selfplay(is);
else if (token == "arena") arena(is);
#ifdef MODE_STRATEGO
// Test if the new modes are also usable for chess and others

else if (token == "mctsmatch") mctsarena(is, "", "");
else if (token == "mctstournament") mctstournament(is);
else if (token == "tournament") evaltournament(is);
#endif
#endif
else
cout << "Unknown command: " << cmd << endl;
Expand Down Expand Up @@ -416,6 +415,7 @@ void CrazyAra::mctstournament(istringstream &is)
for(int i = 0;i<combinations.size();i++){
std::istringstream iss (combinations[i] + std::to_string(numberofgames));
mctsarena(iss, "", "");

}

exit(0);
Expand Down
8 changes: 6 additions & 2 deletions engine/src/uci/variants.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const static vector<string> availableVariants = {
#endif
#ifdef MODE_OPEN_SPIEL
"hex",
"darkhex",
#endif
};

Expand All @@ -70,9 +71,11 @@ const int SUBVARIANT_NB = 20; // Thats high quality code
#endif

const static string StartFENs[SUBVARIANT_NB] = {
#ifndef MODE_STRATEGO
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",

#ifdef MODE_OPEN_SPIEL
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .",
#endif

#ifdef ANTI
// "The king has no royal power and accordingly:
// it may be captured like any other piece
Expand Down Expand Up @@ -137,6 +140,7 @@ const static string StartFENs[SUBVARIANT_NB] = {
#ifdef MODE_STRATEGO
"MBCaaaaaaaKaaaaaaaaaaaaaaDaaaaaaEaDaaaLaaa__aa__aaaa__aa__aaPaaaWNaOXaQPaaaYaaaaaaaaaaaaaaaaaaaaaaaa r 0",
#endif

};

#endif // VARIANTS_H