Commits

Anonymous committed 927a74d

Implemented nk_solve_verdict_matrix_get() . Still not tested very well.

  • Participants
  • Parent commits c7f0f2e

Comments (0)

Files changed (2)

nurikabe-solver/t/verdict-matrix-tests.py.t

 from TAP.Simple import *
 from ctypes import *
 
-plan(15)
+plan(16)
 
 NK_SOLVE_ERROR__SUCCESS = 0
 NK_SOLVE_ERROR__ALLOC_FAILED = 1
                 c_int(v)
                 )
 
+    def get(self, y, x):
+        value = c_int(-1)
+        ret_code = nk_solve.nk_solve_verdict_matrix_get(
+                self.matrix,
+                c_int(y), c_int(x),
+                byref(value)
+                )
+        return (ret_code,value.value)
 
 def test_create_and_free():
     m = Mat()
     m = Mat()
     # TEST
     eq_ok (
-            m.create(10, 5), 
-            NK_SOLVE_ERROR__SUCCESS, 
+            m.create(10, 5),
+            NK_SOLVE_ERROR__SUCCESS,
             "nk_solve_verdict_matrix_create correct error value"
             )
 
 
     # TEST
     eq_ok (
+            m.get(0,0),
+            (NK_SOLVE_ERROR__SUCCESS, NK_SOLVE_VERDICT__UNKNOWN),
+            "Get in (0,0) is unknown."
+        )
+
+    # TEST
+    eq_ok (
             m.free(),
             NK_SOLVE_ERROR__SUCCESS,
             "nk_solve_verdict_matrix_free was successful"

nurikabe-solver/verdict_mat.c

     return NK_SOLVE_ERROR__SUCCESS;
 }
 
+NK_SOLVE_ERROR_CODE
+nk_solve_verdict_matrix_get(
+    nk_solve_verdict_matrix_t * board,
+    gint y,
+    gint x,
+    nk_solve_verdict_t * value
+    )
+{
+    int pos, offset;
+    char * ptr;
+
+    if ( ! ((y >= 0) && (y < board->height)) )
+    {
+        return NK_SOLVE_ERROR__Y_OUT_OF_BOUNDS;
+    }
+    
+    if ( ! ((x >= 0) && (x < board->width)) )
+    {
+        return NK_SOLVE_ERROR__X_OUT_OF_BOUNDS;
+    }
+
+    pos = y * board->width + x;
+    ptr = &(board->buf[pos>>2]);
+    offset = ((pos&(4-1)) << 1);
+
+    *value = (*ptr >> offset) & (4-1);
+
+    return NK_SOLVE_ERROR__SUCCESS;
+}
+