From: Fabian Fichter Date: Sat, 3 Oct 2020 20:47:23 +0000 (+0200) Subject: Support parsing variant config string in pyffish X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=22592f7e46b85e060170e6ae51301857c050d911;p=fairystockfish.git Support parsing variant config string in pyffish --- diff --git a/src/pyffish.cpp b/src/pyffish.cpp index feae8ab..6e33557 100644 --- a/src/pyffish.cpp +++ b/src/pyffish.cpp @@ -4,6 +4,7 @@ */ #include +#include #include "misc.h" #include "types.h" @@ -73,6 +74,17 @@ extern "C" PyObject* pyffish_setOption(PyObject* self, PyObject *args) { Py_RETURN_NONE; } +// INPUT variant config +extern "C" PyObject* pyffish_loadVariantConfig(PyObject* self, PyObject *args) { + const char *config; + if (!PyArg_ParseTuple(args, "s", &config)) + return NULL; + std::stringstream ss(config); + variants.parse_istream(ss); + Options["UCI_Variant"].set_combo(variants.get_keys()); + Py_RETURN_NONE; +} + // INPUT variant extern "C" PyObject* pyffish_startFen(PyObject* self, PyObject *args) { const char *variant; @@ -293,6 +305,7 @@ static PyMethodDef PyFFishMethods[] = { {"version", (PyCFunction)pyffish_version, METH_NOARGS, "Get package version."}, {"info", (PyCFunction)pyffish_info, METH_NOARGS, "Get Stockfish version info."}, {"set_option", (PyCFunction)pyffish_setOption, METH_VARARGS, "Set UCI option."}, + {"load_variant_config", (PyCFunction)pyffish_loadVariantConfig, METH_VARARGS, "Load variant configuration."}, {"start_fen", (PyCFunction)pyffish_startFen, METH_VARARGS, "Get starting position FEN."}, {"two_boards", (PyCFunction)pyffish_twoBoards, METH_VARARGS, "Checks whether the variant is played on two boards."}, {"get_san", (PyCFunction)pyffish_getSAN, METH_VARARGS, "Get SAN move from given FEN and UCI move."}, diff --git a/test.py b/test.py index 93f5d7a..0f93af6 100644 --- a/test.py +++ b/test.py @@ -61,8 +61,7 @@ whiteFlag = *8 blackFlag = *1 """ -print(ini_text, file=open("variants.ini", "w")) -sf.set_option("VariantPath", "variants.ini") +sf.load_variant_config(ini_text) variant_positions = {