Support parsing variant config string in pyffish
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 3 Oct 2020 20:47:23 +0000 (22:47 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 3 Oct 2020 20:47:23 +0000 (22:47 +0200)
src/pyffish.cpp
test.py

index feae8ab..6e33557 100644 (file)
@@ -4,6 +4,7 @@
 */
 
 #include <Python.h>
+#include <sstream>
 
 #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<false>(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 (file)
--- 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 = {