twisty_puzzles 0.0.5 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/ext/twisty_puzzles/native/cube_algorithm.c +10 -18
  4. data/ext/twisty_puzzles/native/cube_average.c +2 -2
  5. data/ext/twisty_puzzles/native/cube_coordinate.c +16 -15
  6. data/ext/twisty_puzzles/native/cube_coordinate.h +7 -7
  7. data/ext/twisty_puzzles/native/cube_state.c +23 -33
  8. data/ext/twisty_puzzles/native/cube_state.h +2 -2
  9. data/ext/twisty_puzzles/native/face_symbols.h +2 -2
  10. data/ext/twisty_puzzles/native/skewb_algorithm.c +3 -12
  11. data/ext/twisty_puzzles/native/skewb_coordinate.c +0 -11
  12. data/ext/twisty_puzzles/native/skewb_layer_fingerprint.c +3 -2
  13. data/ext/twisty_puzzles/native/skewb_state.c +0 -2
  14. data/ext/twisty_puzzles/native/utils.c +7 -1
  15. data/ext/twisty_puzzles/native/utils.h +2 -3
  16. data/lib/twisty_puzzles/abstract_move.rb +5 -2
  17. data/lib/twisty_puzzles/abstract_move_parser.rb +3 -3
  18. data/lib/twisty_puzzles/algorithm.rb +1 -1
  19. data/lib/twisty_puzzles/algorithm_transformation.rb +27 -19
  20. data/lib/twisty_puzzles/axis_face_and_direction_move.rb +4 -1
  21. data/lib/twisty_puzzles/cancellation_helper.rb +1 -1
  22. data/lib/twisty_puzzles/color_scheme.rb +8 -6
  23. data/lib/twisty_puzzles/commutator.rb +7 -0
  24. data/lib/twisty_puzzles/compiled_algorithm.rb +4 -4
  25. data/lib/twisty_puzzles/coordinate.rb +4 -6
  26. data/lib/twisty_puzzles/cube.rb +19 -23
  27. data/lib/twisty_puzzles/cube_move.rb +0 -4
  28. data/lib/twisty_puzzles/cube_move_parser.rb +23 -23
  29. data/lib/twisty_puzzles/cube_print_helper.rb +4 -3
  30. data/lib/twisty_puzzles/cube_state.rb +10 -0
  31. data/lib/twisty_puzzles/parser.rb +3 -3
  32. data/lib/twisty_puzzles/rotation.rb +8 -4
  33. data/lib/twisty_puzzles/skewb_move.rb +1 -0
  34. data/lib/twisty_puzzles/skewb_move_parser.rb +1 -0
  35. data/lib/twisty_puzzles/skewb_notation.rb +7 -1
  36. data/lib/twisty_puzzles/skewb_state.rb +6 -4
  37. data/lib/twisty_puzzles/version.rb +1 -1
  38. metadata +11 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6328e75fef53854e6be5c5f5cbe3eb27e775b2b97397731ee6547291126fa94
4
- data.tar.gz: fc78c670139d170a18aa1f89854520ba00596ba4078b65dc4572a3c6d4ee4b9e
3
+ metadata.gz: 7616a5e5bd64a5beb6ea98bed6a6f6bc2dc5ae145491db533e4693cd10d0ff6d
4
+ data.tar.gz: 8bc2cd597844fb86f9168c8e368c6bbb01cc34a82598ebef7f5dcb77c1e3713c
5
5
  SHA512:
6
- metadata.gz: 31ac0e826d8011114db4edcd88a87c52d47dc7ca925c51533c4262869e361608ed935f907342cb8d41145086086798bd837aaf1ae4e7bc509282f070f4c03d86
7
- data.tar.gz: 1cb3ed5deb0a2bcdfd5e3ae469c4ad8e701504da2ab222eff4fa24c8f2b10413a8f96ee356b91c514846f8c416744e4f7ae90a8d6135ff9cf8fd4e1b6cdbcff5
6
+ metadata.gz: 42c3be051514680426bed25b66ca09b8c420f1423a778db10512c37663c42128136acf6f4e72847bed68d4111e8563ef5eb1cd427883bf2802e072853f1900b0
7
+ data.tar.gz: d26d1c98f90f7bbd15474ac45f200a483983daadfae40016e5f9d2f0ca44b20a652e480f8bbfc13d939f904140358a1acc741fcbbb09306f35b51a298f3a9cf1
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ ![Ruby](https://github.com/Lykos/twisty_puzzles/workflows/Ruby/badge.svg)
2
+ ![Rubocop](https://github.com/Lykos/twisty_puzzles/workflows/Rubocop/badge.svg)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Gem Version](https://badge.fury.io/rb/twisty_puzzles.svg)](https://badge.fury.io/rb/twisty_puzzles)
5
+
1
6
  # Twisty Puzzles
2
7
  Gem for my cube_trainer rails app. Some things are better left in a separate gem with no rails, e.g. native extensions. The main purpose is to support my Rails app, but if it's useful for someone else, feel free to use it at your own risk.
3
8
 
@@ -25,7 +30,7 @@ TODO: Write usage instructions here
25
30
 
26
31
  After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bundle exec bin/console` for an interactive prompt that will allow you to experiment.
27
32
 
28
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/twisty_puzzles/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
34
 
30
35
  ## Contributing
31
36
 
@@ -18,12 +18,12 @@ typedef struct {
18
18
  CubeMoveType type;
19
19
  face_index_t axis_face_index;
20
20
  direction_t direction;
21
- size_t slice_index;
21
+ long slice_index;
22
22
  } CubeMove;
23
23
 
24
24
  typedef struct {
25
25
  size_t size;
26
- size_t cube_size;
26
+ long cube_size;
27
27
  CubeMove* moves;
28
28
  } CubeAlgorithmData;
29
29
 
@@ -45,15 +45,6 @@ const rb_data_type_t CubeAlgorithmData_type = {
45
45
  RUBY_TYPED_FREE_IMMEDIATELY
46
46
  };
47
47
 
48
- static void check_moves(const CubeAlgorithmData* const data, const char* const name) {
49
- for (size_t i = 0; i < data->size; ++i) {
50
- const CubeMoveType type = data->moves[i].type;
51
- if (type != SLICE && type != FACE) {
52
- rb_raise(rb_eRuntimeError, "invalid move type %d in %s", type, name);
53
- }
54
- }
55
- }
56
-
57
48
  static CubeMove* malloc_moves(const size_t n) {
58
49
  CubeMove* const moves = malloc(n * sizeof(CubeMove));
59
50
  if (moves == NULL) {
@@ -96,7 +87,7 @@ static CubeMoveType extract_move_type(const VALUE move_symbol) {
96
87
  }
97
88
  }
98
89
 
99
- static size_t components_for_move_type(const CubeMoveType type) {
90
+ static long components_for_move_type(const CubeMoveType type) {
100
91
  switch (type) {
101
92
  case SLICE:
102
93
  return 4;
@@ -112,24 +103,25 @@ static VALUE CubeAlgorithm_initialize(const VALUE self, const VALUE cube_size, c
112
103
  CubeAlgorithmData* data;
113
104
  GetCubeAlgorithmData(self, data);
114
105
  data->size = RARRAY_LEN(moves);
115
- data->cube_size = NUM2INT(cube_size);
106
+ data->cube_size = FIX2INT(cube_size);
107
+ check_cube_size(data->cube_size);
116
108
  data->moves = malloc_moves(data->size);
117
- for (size_t i = 0; i < RARRAY_LEN(moves); ++i) {
109
+ for (long i = 0; i < RARRAY_LEN(moves); ++i) {
118
110
  const VALUE move = rb_ary_entry(moves, i);
119
111
  if (RARRAY_LEN(move) < 1) {
120
112
  rb_raise(rb_eArgError, "Moves cannot be empty.");
121
113
  }
122
114
  const CubeMoveType type = extract_move_type(rb_ary_entry(move, 0));
123
- const size_t num_components = components_for_move_type(type);
115
+ const long num_components = components_for_move_type(type);
124
116
  if (RARRAY_LEN(move) != num_components) {
125
117
  rb_raise(rb_eArgError, "Moves with the given type need to have %ld elements. Got %ld.", num_components, RARRAY_LEN(move));
126
118
  }
127
119
  data->moves[i].type = type;
128
120
  data->moves[i].axis_face_index = face_index(rb_ary_entry(move, 1));
129
- data->moves[i].direction = NUM2INT(rb_ary_entry(move, 2));
121
+ data->moves[i].direction = FIX2INT(rb_ary_entry(move, 2));
130
122
  if (type == SLICE) {
131
- const size_t slice_index = NUM2INT(rb_ary_entry(move, 3));
132
- if (slice_index >= data->cube_size) {
123
+ const long slice_index = FIX2INT(rb_ary_entry(move, 3));
124
+ if (slice_index < 0 || slice_index >= data->cube_size) {
133
125
  rb_raise(rb_eArgError, "Invalid slice index %ld for cube size %ld.", slice_index, data->cube_size);
134
126
  }
135
127
  data->moves[i].slice_index = slice_index;
@@ -59,7 +59,7 @@ static VALUE CubeAverage_alloc(const VALUE klass) {
59
59
 
60
60
  static VALUE CubeAverage_initialize(const VALUE self, const VALUE capacity, const VALUE initial_average) {
61
61
  Check_Type(capacity, T_FIXNUM);
62
- const size_t n = FIX2INT(capacity);
62
+ const long n = FIX2INT(capacity);
63
63
  if (n < 3) {
64
64
  rb_raise(rb_eArgError, "The number of elements for a cube average has to be at least 3. Got %ld.", n);
65
65
  }
@@ -147,7 +147,7 @@ static VALUE CubeAverage_push_all(const VALUE self, const VALUE new_values) {
147
147
  const size_t insert_index = data->insert_index;
148
148
  const size_t capacity = data->capacity;
149
149
  const size_t start = num_values > capacity ? num_values - capacity : 0;
150
- for (size_t i = start; i < RARRAY_LEN(new_values); ++i) {
150
+ for (long i = start; i < RARRAY_LEN(new_values); ++i) {
151
151
  const VALUE new_value = rb_ary_entry(new_values, i);
152
152
  data->values[(insert_index + i) % capacity] = NUM2DBL(new_value);
153
153
  }
@@ -5,7 +5,7 @@
5
5
  static VALUE CubeCoordinateClass = Qnil;
6
6
 
7
7
  typedef struct {
8
- size_t cube_size;
8
+ long cube_size;
9
9
  face_index_t on_face_index;
10
10
  Point point;
11
11
  } CubeCoordinateData;
@@ -26,15 +26,15 @@ const rb_data_type_t CubeCoordinateData_type = {
26
26
  TypedData_Get_Struct((obj), CubeCoordinateData, &CubeCoordinateData_type, (data)); \
27
27
  } while (0)
28
28
 
29
- size_t num_stickers(const size_t cube_size) {
29
+ size_t num_stickers(const long cube_size) {
30
30
  return cube_faces * cube_size * cube_size;
31
31
  }
32
32
 
33
- size_t sticker_index(const size_t cube_size, const face_index_t on_face_index, const Point point) {
33
+ size_t sticker_index(const long cube_size, const face_index_t on_face_index, const Point point) {
34
34
  return on_face_index * cube_size * cube_size + point.y * cube_size + point.x;
35
35
  }
36
36
 
37
- size_t CubeCoordinate_sticker_index(const VALUE self, const size_t cube_size) {
37
+ size_t CubeCoordinate_sticker_index(const VALUE self, const long cube_size) {
38
38
  CubeCoordinateData* data;
39
39
  GetCubeCoordinateData(self, data);
40
40
  if (data->cube_size != cube_size) {
@@ -53,11 +53,11 @@ static VALUE CubeCoordinate_alloc(const VALUE klass) {
53
53
  return object;
54
54
  }
55
55
 
56
- static size_t inverted_index(const size_t cube_size, const size_t index) {
56
+ static long inverted_index(const long cube_size, const long index) {
57
57
  return cube_size - 1 - index;
58
58
  }
59
59
 
60
- size_t transform_index(const face_index_t index_base_face_index, const size_t cube_size, const size_t index) {
60
+ long transform_index(const face_index_t index_base_face_index, const long cube_size, const long index) {
61
61
  if (index_base_face_index == axis_index(index_base_face_index)) {
62
62
  return index;
63
63
  } else {
@@ -86,11 +86,11 @@ void check_base_face_indices(const face_index_t on_face_index,
86
86
  Point point_on_face(const face_index_t face_index,
87
87
  const face_index_t x_base_face_index,
88
88
  const face_index_t y_base_face_index,
89
- const size_t cube_size,
90
- const size_t untransformed_x,
91
- const size_t untransformed_y) {
92
- const size_t transformed_x = transform_index(x_base_face_index, cube_size, untransformed_x);
93
- const size_t transformed_y = transform_index(y_base_face_index, cube_size, untransformed_y);
89
+ const long cube_size,
90
+ const long untransformed_x,
91
+ const long untransformed_y) {
92
+ const long transformed_x = transform_index(x_base_face_index, cube_size, untransformed_x);
93
+ const long transformed_y = transform_index(y_base_face_index, cube_size, untransformed_y);
94
94
  Point point;
95
95
  if (switch_axes(x_base_face_index, y_base_face_index)) {
96
96
  point.x = transformed_y;
@@ -102,7 +102,7 @@ Point point_on_face(const face_index_t face_index,
102
102
  return point;
103
103
  }
104
104
 
105
- static void check_cube_index(const size_t cube_size, const size_t index) {
105
+ static void check_cube_index(const long cube_size, const long index) {
106
106
  if (index < 0 || index >= cube_size) {
107
107
  rb_raise(rb_eArgError, "Invalid value %ld for x with cube size %ld.", index, cube_size);
108
108
  }
@@ -121,14 +121,15 @@ static VALUE CubeCoordinate_initialize(const VALUE self,
121
121
  Check_Type(y_base_face_symbol, T_SYMBOL);
122
122
  Check_Type(x_num, T_FIXNUM);
123
123
  Check_Type(y_num, T_FIXNUM);
124
- const size_t n = FIX2INT(cube_size);
124
+ const long n = FIX2INT(cube_size);
125
+ check_cube_size(n);
125
126
  const face_index_t on_face_index = face_index(face_symbol);
126
127
  const face_index_t x_base_face_index = face_index(x_base_face_symbol);
127
128
  const face_index_t y_base_face_index = face_index(y_base_face_symbol);
128
129
  check_base_face_indices(on_face_index, x_base_face_index, y_base_face_index);
129
- const size_t untransformed_x = FIX2INT(x_num);
130
+ const long untransformed_x = FIX2INT(x_num);
130
131
  check_cube_index(n, untransformed_x);
131
- const size_t untransformed_y = FIX2INT(y_num);
132
+ const long untransformed_y = FIX2INT(y_num);
132
133
  check_cube_index(n, untransformed_y);
133
134
  const Point point = point_on_face(on_face_index, x_base_face_index, y_base_face_index, n, untransformed_x, untransformed_y);
134
135
  CubeCoordinateData* data;
@@ -5,16 +5,16 @@
5
5
  #include "face_symbols.h"
6
6
  #include "utils.h"
7
7
 
8
- size_t num_stickers(size_t cube_size);
8
+ size_t num_stickers(long cube_size);
9
9
 
10
10
  typedef struct {
11
11
  size_t x;
12
12
  size_t y;
13
13
  } Point;
14
14
 
15
- size_t sticker_index(size_t cube_size, face_index_t on_face_index, Point point);
15
+ size_t sticker_index(long cube_size, face_index_t on_face_index, Point point);
16
16
 
17
- size_t transform_index(face_index_t index_base_face_index, size_t cube_size, size_t index);
17
+ long transform_index(face_index_t index_base_face_index, long cube_size, long index);
18
18
 
19
19
  bool switch_axes(face_index_t x_base_face_index, face_index_t y_base_face_index);
20
20
 
@@ -25,10 +25,10 @@ void check_base_face_indices(face_index_t on_face_index,
25
25
  Point point_on_face(face_index_t on_face_index,
26
26
  face_index_t x_base_face_index,
27
27
  face_index_t y_base_face_index,
28
- size_t cube_size,
29
- size_t untransformed_x,
30
- size_t untransformed_y);
28
+ long cube_size,
29
+ long untransformed_x,
30
+ long untransformed_y);
31
31
 
32
- size_t CubeCoordinate_sticker_index(VALUE self, size_t cube_size);
32
+ size_t CubeCoordinate_sticker_index(VALUE self, long cube_size);
33
33
 
34
34
  void init_cube_coordinate_class_under(VALUE module);
@@ -12,7 +12,7 @@ static VALUE CubeStateClass = Qnil;
12
12
 
13
13
  static void CubeStateData_mark(void* const ptr) {
14
14
  const CubeStateData* data = ptr;
15
- const size_t n = data->cube_size;
15
+ const long n = data->cube_size;
16
16
  for (size_t i = 0; i < num_stickers(n); ++i) {
17
17
  rb_gc_mark(data->stickers[i]);
18
18
  }
@@ -52,19 +52,10 @@ static VALUE CubeState_alloc(const VALUE klass) {
52
52
  return object;
53
53
  }
54
54
 
55
- static size_t extract_index_base_face_index(const VALUE face_hash, const VALUE key) {
56
- const VALUE index_base_face_symbol = rb_hash_aref(face_hash, key);
57
- if (index_base_face_symbol == Qnil) {
58
- rb_raise(rb_eTypeError, "Cube faces must have keys called :{x,y}_base_face_symbol that describes which face an x or y value of 0 is close to.");
59
- }
60
- Check_Type(index_base_face_symbol, T_SYMBOL);
61
- return face_index(index_base_face_symbol);
62
- }
63
-
64
55
  static int CubeState_replace_face(const VALUE key, const VALUE value, const VALUE self) {
65
56
  const CubeStateData* data;
66
57
  GetInitializedCubeStateData(self, data);
67
- const size_t n = data->cube_size;
58
+ const long n = data->cube_size;
68
59
  Check_Type(value, T_HASH);
69
60
  if (RHASH_SIZE(value) != 3) {
70
61
  rb_raise(rb_eTypeError, "Cube faces must have 3 entries, got %ld.", RHASH_SIZE(value));
@@ -75,19 +66,17 @@ static int CubeState_replace_face(const VALUE key, const VALUE value, const VALU
75
66
  if (stickers == Qnil) {
76
67
  rb_raise(rb_eTypeError, "Cube faces must have a key called :stickers that contains the stickers on that face.");
77
68
  }
78
- const face_index_t x_base_face_index = extract_index_base_face_index(value, ID2SYM(x_base_face_symbol_id));
79
- const face_index_t y_base_face_index = extract_index_base_face_index(value, ID2SYM(y_base_face_symbol_id));
80
69
  Check_Type(stickers, T_ARRAY);
81
70
  if (RARRAY_LEN(stickers) != n) {
82
71
  rb_raise(rb_eArgError, "All faces of a %ldx%ld cube must have %ld rows. Got %ld rows.", n, n, n, RARRAY_LEN(stickers));
83
72
  }
84
- for (size_t y = 0; y < n; ++y) {
73
+ for (long y = 0; y < n; ++y) {
85
74
  const VALUE row = rb_ary_entry(stickers, y);
86
75
  Check_Type(row, T_ARRAY);
87
76
  if (RARRAY_LEN(row) != n) {
88
77
  rb_raise(rb_eArgError, "All rows of a %ldx%ld cube must have %ld cells. Got %ld cells.", n, n, n, RARRAY_LEN(row));
89
78
  }
90
- for (size_t x = 0; x < n; ++x) {
79
+ for (long x = 0; x < n; ++x) {
91
80
  const VALUE cell = rb_ary_entry(row, x);
92
81
  Point point = {x, y};
93
82
  data->stickers[sticker_index(n, on_face_index, point)] = cell;
@@ -99,7 +88,8 @@ static int CubeState_replace_face(const VALUE key, const VALUE value, const VALU
99
88
  static VALUE CubeState_initialize(const VALUE self, const VALUE cube_size, const VALUE stickers) {
100
89
  Check_Type(cube_size, T_FIXNUM);
101
90
  Check_Type(stickers, T_HASH);
102
- const size_t n = FIX2INT(cube_size);
91
+ const long n = FIX2INT(cube_size);
92
+ check_cube_size(n);
103
93
  CubeStateData* data;
104
94
  GetCubeStateData(self, data);
105
95
  data->cube_size = n;
@@ -127,11 +117,11 @@ static VALUE CubeState_sticker_array(const VALUE self,
127
117
  check_base_face_indices(on_face_index, x_base_face_index, y_base_face_index);
128
118
  const CubeStateData* data;
129
119
  GetInitializedCubeStateData(self, data);
130
- const size_t n = data->cube_size;
120
+ const long n = data->cube_size;
131
121
  const VALUE face = rb_ary_new2(n);
132
- for (size_t y = 0; y < n; ++y) {
122
+ for (long y = 0; y < n; ++y) {
133
123
  const VALUE row = rb_ary_new2(n);
134
- for (size_t x = 0; x < n; ++x) {
124
+ for (long x = 0; x < n; ++x) {
135
125
  const Point point = point_on_face(on_face_index, x_base_face_index, y_base_face_index, n, x, y);
136
126
  const VALUE cell = data->stickers[sticker_index(n, on_face_index, point)];
137
127
  rb_ary_store(row, x, cell);
@@ -159,7 +149,7 @@ static VALUE CubeState_hash(const VALUE self) {
159
149
 
160
150
  st_index_t hash = rb_hash_start(data->cube_size);
161
151
  hash = rb_hash_uint(hash, (st_index_t)CubeState_hash);
162
- const size_t n = data->cube_size;
152
+ const long n = data->cube_size;
163
153
  for (size_t i = 0; i < num_stickers(n); i++) {
164
154
  const VALUE sub_hash = rb_hash(data->stickers[i]);
165
155
  hash = rb_hash_uint(hash, NUM2LONG(sub_hash));
@@ -181,7 +171,7 @@ static VALUE CubeState_eql(const VALUE self, const VALUE other) {
181
171
  if (self_data->cube_size != other_data->cube_size) {
182
172
  return Qfalse;
183
173
  }
184
- const size_t n = self_data->cube_size;
174
+ const long n = self_data->cube_size;
185
175
  for (size_t i = 0; i < num_stickers(n); ++i) {
186
176
  if (!color_eq(self_data->stickers[i], other_data->stickers[i])) {
187
177
  return Qfalse;
@@ -193,7 +183,7 @@ static VALUE CubeState_eql(const VALUE self, const VALUE other) {
193
183
  static VALUE CubeState_dup(const VALUE self) {
194
184
  const CubeStateData* data;
195
185
  GetInitializedCubeStateData(self, data);
196
- const size_t n = data->cube_size;
186
+ const long n = data->cube_size;
197
187
  CubeStateData* dupped_data;
198
188
  const VALUE dupped = TypedData_Make_Struct(rb_obj_class(self), CubeStateData, &CubeStateData_type, dupped_data);
199
189
  dupped_data->cube_size = n;
@@ -208,19 +198,19 @@ static VALUE CubeState_cube_size(const VALUE self) {
208
198
  return ST2FIX(data->cube_size);
209
199
  }
210
200
 
211
- void rotate_slice_for_cube(const face_index_t turned_face_index, const size_t slice_index, direction_t direction, const CubeStateData* const data) {
201
+ void rotate_slice_for_cube(const face_index_t turned_face_index, const long slice_index, direction_t direction, const CubeStateData* const data) {
212
202
  direction = CROP_MOD(direction, 4);
213
203
  if (direction == 0) {
214
204
  return;
215
205
  }
216
- const size_t n = data->cube_size;
217
- for (size_t i = 0; i < n; ++i) {
206
+ const long n = data->cube_size;
207
+ for (long x = 0; x < n; ++x) {
218
208
  Sticker4Cycle cycle;
219
- for (size_t j = 0; j < neighbor_faces; ++j) {
220
- const face_index_t on_face_index = neighbor_face_index(turned_face_index, j);
221
- const face_index_t next_face_index = neighbor_face_index(turned_face_index, j + 1);
222
- const Point point = point_on_face(on_face_index, turned_face_index, next_face_index, n, slice_index, i);
223
- cycle.indices[j] = sticker_index(n, on_face_index, point);
209
+ for (size_t i = 0; i < neighbor_faces; ++i) {
210
+ const face_index_t on_face_index = neighbor_face_index(turned_face_index, i);
211
+ const face_index_t next_face_index = neighbor_face_index(turned_face_index, i + 1);
212
+ const Point point = point_on_face(on_face_index, turned_face_index, next_face_index, n, slice_index, x);
213
+ cycle.indices[i] = sticker_index(n, on_face_index, point);
224
214
  }
225
215
  apply_sticker_4cycle(data->stickers, cycle, direction);
226
216
  }
@@ -231,9 +221,9 @@ void rotate_face_for_cube(const face_index_t turned_face_index, direction_t dire
231
221
  if (direction == 0) {
232
222
  return;
233
223
  }
234
- const size_t n = data->cube_size;
235
- for (size_t y = 0; y < n / 2; ++y) {
236
- for (size_t x = 0; x < (n + 1) / 2; ++x) {
224
+ const long n = data->cube_size;
225
+ for (long y = 0; y < n / 2; ++y) {
226
+ for (long x = 0; x < (n + 1) / 2; ++x) {
237
227
  Sticker4Cycle cycle;
238
228
  for (size_t j = 0; j < neighbor_faces; ++j) {
239
229
  const face_index_t x_face_index = neighbor_face_index(turned_face_index, j);
@@ -5,7 +5,7 @@
5
5
  #include "face_symbols.h"
6
6
 
7
7
  typedef struct {
8
- size_t cube_size;
8
+ long cube_size;
9
9
  VALUE* stickers;
10
10
  } CubeStateData;
11
11
 
@@ -24,7 +24,7 @@ extern const rb_data_type_t CubeStateData_type;
24
24
  } \
25
25
  } while(0)
26
26
 
27
- void rotate_slice_for_cube(face_index_t turned_face_index, size_t slice_index, direction_t direction, const CubeStateData* data);
27
+ void rotate_slice_for_cube(face_index_t turned_face_index, long slice_index, direction_t direction, const CubeStateData* data);
28
28
 
29
29
  void rotate_face_for_cube(face_index_t turned_face_index, direction_t direction, const CubeStateData* data);
30
30
 
@@ -4,8 +4,8 @@
4
4
 
5
5
  #include "utils.h"
6
6
 
7
- typedef char face_index_t;
8
- typedef char axis_index_t;
7
+ typedef unsigned char face_index_t;
8
+ typedef unsigned char axis_index_t;
9
9
 
10
10
  #define cube_faces 6
11
11
  #define neighbor_faces 4
@@ -50,15 +50,6 @@ const rb_data_type_t SkewbAlgorithmData_type = {
50
50
  RUBY_TYPED_FREE_IMMEDIATELY
51
51
  };
52
52
 
53
- static void check_moves(const SkewbAlgorithmData* const data, const char* const name) {
54
- for (size_t i = 0; i < data->size; ++i) {
55
- const SkewbMoveType type = data->moves[i].type;
56
- if (type != MOVE && type != ROTATION) {
57
- rb_raise(rb_eRuntimeError, "invalid move type %d in %s", type, name);
58
- }
59
- }
60
- }
61
-
62
53
  static SkewbMove* malloc_moves(const size_t n) {
63
54
  SkewbMove* const moves = malloc(n * sizeof(SkewbMove));
64
55
  if (moves == NULL) {
@@ -122,7 +113,7 @@ static VALUE SkewbAlgorithm_initialize(const VALUE self, const VALUE moves) {
122
113
  data->size = RARRAY_LEN(moves);
123
114
  data->initialized = TRUE;
124
115
  data->moves = malloc_moves(data->size);
125
- for (size_t i = 0; i < RARRAY_LEN(moves); ++i) {
116
+ for (long i = 0; i < RARRAY_LEN(moves); ++i) {
126
117
  const VALUE move = rb_ary_entry(moves, i);
127
118
  if (RARRAY_LEN(move) != 3) {
128
119
  rb_raise(rb_eArgError, "Moves must have 3 elements. Got %ld.", RARRAY_LEN(moves));
@@ -171,8 +162,8 @@ static face_index_t axis_face_on_corner(const Corner corner, const face_index_t
171
162
 
172
163
  bool corners_eq(Corner left, Corner right) {
173
164
  return left.face_indices[0] == right.face_indices[0] &&
174
- (left.face_indices[1] == right.face_indices[1] && left.face_indices[2] == right.face_indices[2] ||
175
- left.face_indices[1] == right.face_indices[2] && left.face_indices[2] == right.face_indices[1]);
165
+ ((left.face_indices[1] == right.face_indices[1] && left.face_indices[2] == right.face_indices[2]) ||
166
+ (left.face_indices[1] == right.face_indices[2] && left.face_indices[2] == right.face_indices[1]));
176
167
  }
177
168
 
178
169
  size_t equivalent_corner_index(const FaceCorners corners, const Corner corner) {