ext/khetai/khetai.c in khetai-0.3.0 vs ext/khetai/khetai.c in khetai-0.3.2

- old
+ new

@@ -1,10 +1,17 @@ #include "khetai_lib.h" #include <ruby.h> #include <stdlib.h> #include <time.h> +static int convert_index(int i) { + int row = (i / 12) - 1; + int col = (i % 12) - 1; + + return (row * 10) + col; +} + VALUE move(VALUE self, VALUE board_array, VALUE _player, VALUE _max_depth, VALUE _max_time) { // verify parameters int player = NUM2INT(_player); if (player < 0 || player > 1) { rb_raise(rb_eArgError, "player must be 0 (silver) or 1 (red)"); @@ -88,11 +95,11 @@ depth++; } make_move(best_move); VALUE out = rb_ary_new2(3); - rb_ary_store(out, 0, INT2NUM(get_start(best_move))); - rb_ary_store(out, 1, INT2NUM(get_end(best_move))); + rb_ary_store(out, 0, INT2NUM(convert_index(get_start(best_move)))); + rb_ary_store(out, 1, INT2NUM(convert_index(get_end(best_move)))); rb_ary_store(out, 2, INT2NUM(get_rotation(best_move))); return out; }