Created
December 19, 2023 14:16
-
-
Save ale64bit/f12a475815880e4c32269ca2e786e01c to your computer and use it in GitHub Desktop.
Using the foxwq score estimator in a standalone Windows program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <iostream> | |
#include <vector> | |
#include <tuple> | |
#include <algorithm> | |
using namespace std; | |
enum Color : int { | |
kBlack = 1, | |
kWhite = 2, | |
}; | |
// The interface for the functions we need | |
struct GoStar5M { | |
bool (*FirstInitial)(const char*) = nullptr; | |
bool (*NewEvent)(int) = nullptr; | |
bool (*SetMove)(int, Color, int *, int *) = nullptr; | |
bool (*CalcTerritory)(int*) = nullptr; | |
}; | |
GoStar5M LoadGoStar5M() { | |
HINSTANCE proc_id = LoadLibraryA("C:\\Program Files (x86)\\foxwq\\foxwq\\GoStar5M.dll"); | |
if (!proc_id) { | |
cerr << "failed to load gostar dll: " << GetLastError() << endl; | |
exit(1); | |
} | |
return { | |
(bool (*)(const char *))GetProcAddress(proc_id, "FirstInitial"), | |
(bool (*)(int))GetProcAddress(proc_id, "NewEvent"), | |
(bool (*)(int, Color, int *, int *))GetProcAddress(proc_id, "SetMove"), | |
(bool (*)(int *))GetProcAddress(proc_id, "CalcTerritory"), | |
}; | |
} | |
int main() { | |
cout << "loading gostar5m..." << endl; | |
GoStar5M gostar5m = LoadGoStar5M(); | |
cout << "initializing gostar5m..." << endl; | |
if (!gostar5m.FirstInitial("YeHuWeiQi")) { | |
cerr << "failed to init gostar5m" << endl; | |
return 1; | |
} | |
// This sets the board size | |
cout << "new event: 19" << endl; | |
if (!gostar5m.NewEvent(19)) { | |
cerr << "failed to set new event" << endl; | |
return 1; | |
} | |
{ | |
vector<tuple<int, int, Color>> moves = { | |
{4,4,kBlack}, | |
{4,16,kBlack}, | |
{16,4,kWhite}, | |
{16,16,kWhite}, | |
}; | |
// no idea what these are for yet... | |
vector<int> arg3(4 * 361, 0); | |
vector<int> arg4(4 * 361, 0); | |
for (const auto& [r, c, color] : moves) { | |
int encoded_move = (r << 8) ^ c; | |
cout << "setting move (" << r << ", " << c << ")" << endl; | |
if (!gostar5m.SetMove(encoded_move, color, arg3.data(), arg4.data())) { | |
cerr << "failed to set move (" << r << ", " << c << ")"; | |
return 1; | |
} | |
} | |
} | |
{ | |
int territory[19][19]; | |
cout << "calculating territory..." << endl; | |
if (!gostar5m.CalcTerritory(&territory[0][0])) { | |
cerr << "failed to calculate territory" << endl; | |
return 1; | |
} | |
for (int i = 0; i < 19; ++i) { | |
for (int j = 0; j < 19; ++j) { | |
cout << territory[i][j] << ' '; | |
} | |
cout << endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment