aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-31 09:47:57 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-31 09:47:57 +0200
commit992de12cc081e7dde16c3c231f83bfa77c67825a (patch)
treeaf0b2d51b1a6cd92ae2cd6a32d581d752ddce8ea /python
parente2b154c40acaac4e7a7b3e379ada0404519c3750 (diff)
downloadnissy-core-992de12cc081e7dde16c3c231f83bfa77c67825a.tar.gz
nissy-core-992de12cc081e7dde16c3c231f83bfa77c67825a.zip
Added move sequence comparison function
Diffstat (limited to '')
-rw-r--r--python/nissy_module.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/python/nissy_module.c b/python/nissy_module.c
index 3e5ea08..a86b23f 100644
--- a/python/nissy_module.c
+++ b/python/nissy_module.c
@@ -345,6 +345,42 @@ countmoves(PyObject *self, PyObject *args)
345 return long_result(count); 345 return long_result(count);
346} 346}
347 347
348PyDoc_STRVAR(comparemoves_doc,
349"comparemoves(moves1, moves2)\n"
350"--\n\n"
351"Compare the two move sequences\n"
352"\n"
353"Parameters:\n"
354" - moves1: the first sequence of moves\n"
355" - moves2: the second sequence of moves\n"
356"\n"
357"Returns: a string describing how the two moves sequences compare. "
358"This can be one of:\n"
359"\"EQUAL\" - The two sequences are equal up to swapping parallel moves\n"
360"\"DIFFERENT\" - The two sequences are different\n"
361);
362PyObject *
363comparemoves(PyObject *self, PyObject *args)
364{
365 long long cmp;
366 const char *m1, *m2;
367
368 if (!PyArg_ParseTuple(args, "ss", &m1, &m2))
369 return NULL;
370
371 if ((cmp = nissy_comparemoves(m1, m2)) < 0)
372 return long_result(cmp);
373
374 switch (cmp) {
375 case NISSY_COMPARE_MOVES_EQUAL:
376 return string_result(cmp, "EQUAL");
377 case NISSY_COMPARE_MOVES_DIFFERENT:
378 return string_result(cmp, "DIFFERENT");
379 default:
380 return long_result(cmp);
381 }
382}
383
348static PyMethodDef nissy_methods[] = { 384static PyMethodDef nissy_methods[] = {
349 { "inverse", inverse, METH_VARARGS, inverse_doc }, 385 { "inverse", inverse, METH_VARARGS, inverse_doc },
350 { "applymoves", applymoves, METH_VARARGS, applymoves_doc }, 386 { "applymoves", applymoves, METH_VARARGS, applymoves_doc },
@@ -355,6 +391,7 @@ static PyMethodDef nissy_methods[] = {
355 { "checkdata", checkdata, METH_VARARGS, checkdata_doc }, 391 { "checkdata", checkdata, METH_VARARGS, checkdata_doc },
356 { "solve", solve, METH_VARARGS, solve_doc }, 392 { "solve", solve, METH_VARARGS, solve_doc },
357 { "countmoves", countmoves, METH_VARARGS, countmoves_doc }, 393 { "countmoves", countmoves, METH_VARARGS, countmoves_doc },
394 { "comparemoves", comparemoves, METH_VARARGS, comparemoves_doc },
358 { NULL, NULL, 0, NULL } 395 { NULL, NULL, 0, NULL }
359}; 396};
360 397

Generated with cgit - Back to sebastiano.tronto.net