reversi 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb57c511c13a037077ba6d8f0ab1caa8cd8cc577
4
- data.tar.gz: ba9e86d039af5cf0b84131abc34b840391a870cb
3
+ metadata.gz: 097177f5c48836f3fd8a77fed3861784aac94da5
4
+ data.tar.gz: 7d9d9f9558e2c244a90c714b85b0a92193ded4b1
5
5
  SHA512:
6
- metadata.gz: c8750708addcd46a68728174747d20dd86190b121bcb49860e9a157aaf7c70e9403c1723f1901ff45e90fa020c0b9f42b0cf2db8f23bdccf043a41daf01cb061
7
- data.tar.gz: c5173b9bead22a20bf952fc0f79c7e15b54b9572821d4bd3a331bebc5d52d33c3b01248ae06a6e77f348249daccfcf81bcfc2118ac36a7600f3e204e993f4d14
6
+ metadata.gz: a3bc92b431d249ec5c8ed2f533f6aec338de44a5393abb2e8f4595bf1437554b96df26086819556664fed75d3fabcd845141b9edd7282c025e313010d6a583ff
7
+ data.tar.gz: d82e22537236e447c7fa416428db7d1dd6a3b3aaed52c35eb47c3c1e5b03df7a2bf658832018c5741b99f960905fdf3d11cc1735920f9a741e8226626d381dd0
@@ -3,14 +3,14 @@
3
3
  /*
4
4
  * Convert coordinate data to a bitboard.
5
5
  */
6
- unsigned long XY2BB(int x, int y) {
7
- return (unsigned long)1 << ((8-x) + (8-y) * 8);
6
+ uint64_t XY2BB(int x, int y) {
7
+ return (uint64_t)1 << ((8-x) + (8-y) * 8);
8
8
  }
9
9
 
10
10
  /*
11
11
  * Convert a bitboard to coordinate data.
12
12
  */
13
- VALUE BB2XY(unsigned long bb) {
13
+ VALUE BB2XY(uint64_t bb) {
14
14
  VALUE xy = rb_ary_new();
15
15
 
16
16
  switch(bb) {
@@ -92,7 +92,7 @@ VALUE BB2XY(unsigned long bb) {
92
92
  /*
93
93
  * Rotate a bitboard by 90 degrees to the right.
94
94
  */
95
- unsigned long rotate_r90(unsigned long bb) {
95
+ uint64_t rotate_r90(uint64_t bb) {
96
96
  bb = ((bb << 8) & 0xAA00AA00AA00AA00) |
97
97
  ((bb >> 8) & 0x0055005500550055) |
98
98
  ((bb << 1) & 0x00AA00AA00AA00AA) |
@@ -111,7 +111,7 @@ unsigned long rotate_r90(unsigned long bb) {
111
111
  /*
112
112
  * Rotate a bitboard by 90 degrees to the left.
113
113
  */
114
- unsigned long rotate_l90(unsigned long bb) {
114
+ uint64_t rotate_l90(uint64_t bb) {
115
115
  bb = ((bb << 1) & 0xAA00AA00AA00AA00) |
116
116
  ((bb >> 1) & 0x0055005500550055) |
117
117
  ((bb >> 8) & 0x00AA00AA00AA00AA) |
@@ -130,7 +130,7 @@ unsigned long rotate_l90(unsigned long bb) {
130
130
  /*
131
131
  * Rotate a bitboard by 45 degrees to the right.
132
132
  */
133
- unsigned long rotate_r45(unsigned long bb) {
133
+ uint64_t rotate_r45(uint64_t bb) {
134
134
  bb = (bb & 0x0101010101010101) |
135
135
  (((bb << 8) | (bb >> 56)) & 0x0202020202020202) |
136
136
  (((bb << 16) | (bb >> 48)) & 0x0404040404040404) |
@@ -145,7 +145,7 @@ unsigned long rotate_r45(unsigned long bb) {
145
145
  /*
146
146
  * Rotate a bitboard by 45 degrees to the left.
147
147
  */
148
- unsigned long rotate_l45(unsigned long bb) {
148
+ uint64_t rotate_l45(uint64_t bb) {
149
149
  bb = (bb & 0x0101010101010101) |
150
150
  (((bb >> 8) | (bb << 56)) & 0x0202020202020202) |
151
151
  (((bb >> 16) | (bb << 48)) & 0x0404040404040404) |
@@ -157,31 +157,31 @@ unsigned long rotate_l45(unsigned long bb) {
157
157
  return bb;
158
158
  }
159
159
 
160
- unsigned long horizontal_pat(unsigned long my, unsigned long op, unsigned long p) {
160
+ uint64_t horizontal_pat(uint64_t my, uint64_t op, uint64_t p) {
161
161
  op &= 0x7E7E7E7E7E7E7E7E;
162
162
  return right_pat(my, op, p) | left_pat(my, op, p);
163
163
  }
164
164
 
165
- unsigned long vertical_pat(unsigned long my, unsigned long op, unsigned long p) {
165
+ uint64_t vertical_pat(uint64_t my, uint64_t op, uint64_t p) {
166
166
  my = rotate_r90(my);
167
167
  op = rotate_r90(op & 0x00FFFFFFFFFFFF00);
168
168
  p = rotate_r90(p);
169
169
  return rotate_l90(right_pat(my, op, p) | left_pat(my, op, p));
170
170
  }
171
171
 
172
- unsigned long diagonal_pat(unsigned long my, unsigned long op, unsigned long p) {
173
- unsigned long my_r45 = rotate_r45(my);
174
- unsigned long op_r45 = rotate_r45(op & 0x007E7E7E7E7E7E00);
175
- unsigned long p_r45 = rotate_r45(p);
176
- unsigned long my_l45 = rotate_l45(my);
177
- unsigned long op_l45 = rotate_l45(op & 0x00FF7E7E7E7E7E00);
178
- unsigned long p_l45 = rotate_l45(p);
172
+ uint64_t diagonal_pat(uint64_t my, uint64_t op, uint64_t p) {
173
+ uint64_t my_r45 = rotate_r45(my);
174
+ uint64_t op_r45 = rotate_r45(op & 0x007E7E7E7E7E7E00);
175
+ uint64_t p_r45 = rotate_r45(p);
176
+ uint64_t my_l45 = rotate_l45(my);
177
+ uint64_t op_l45 = rotate_l45(op & 0x00FF7E7E7E7E7E00);
178
+ uint64_t p_l45 = rotate_l45(p);
179
179
  return rotate_l45(right_pat(my_r45, op_r45, p_r45) | left_pat(my_r45, op_r45, p_r45)) |
180
180
  rotate_r45(right_pat(my_l45, op_l45, p_l45) | left_pat(my_l45, op_l45, p_l45));
181
181
  }
182
182
 
183
- unsigned long right_pat(unsigned long my, unsigned long op, unsigned long p) {
184
- unsigned long rev = (p >> 1) & op;
183
+ uint64_t right_pat(uint64_t my, uint64_t op, uint64_t p) {
184
+ uint64_t rev = (p >> 1) & op;
185
185
  rev |= (rev >> 1) & op;
186
186
  rev |= (rev >> 1) & op;
187
187
  rev |= (rev >> 1) & op;
@@ -190,8 +190,8 @@ unsigned long right_pat(unsigned long my, unsigned long op, unsigned long p) {
190
190
  return ((rev >> 1) & my) == 0 ? 0 : rev;
191
191
  }
192
192
 
193
- unsigned long left_pat(unsigned long my, unsigned long op, unsigned long p) {
194
- unsigned long rev = (p << 1) & op;
193
+ uint64_t left_pat(uint64_t my, uint64_t op, uint64_t p) {
194
+ uint64_t rev = (p << 1) & op;
195
195
  rev |= (rev << 1) & op;
196
196
  rev |= (rev << 1) & op;
197
197
  rev |= (rev << 1) & op;
@@ -200,31 +200,31 @@ unsigned long left_pat(unsigned long my, unsigned long op, unsigned long p) {
200
200
  return ((rev << 1) & my) == 0 ? 0 : rev;
201
201
  }
202
202
 
203
- unsigned long horizontal_pos(unsigned long my, unsigned long op, unsigned long blank) {
203
+ uint64_t horizontal_pos(uint64_t my, uint64_t op, uint64_t blank) {
204
204
  op &= 0x7E7E7E7E7E7E7E7E;
205
205
  return right_pos(my, op, blank) | left_pos(my, op, blank);
206
206
  }
207
207
 
208
- unsigned long vertical_pos(unsigned long my, unsigned long op, unsigned long blank) {
208
+ uint64_t vertical_pos(uint64_t my, uint64_t op, uint64_t blank) {
209
209
  my = rotate_r90(my);
210
210
  op = rotate_r90(op & 0x00FFFFFFFFFFFF00);
211
211
  blank = rotate_r90(blank);
212
212
  return rotate_l90(right_pos(my, op, blank) | left_pos(my, op, blank));
213
213
  }
214
214
 
215
- unsigned long diagonal_pos(unsigned long my, unsigned long op, unsigned long blank) {
216
- unsigned long my_r45 = rotate_r45(my);
217
- unsigned long op_r45 = rotate_r45(op & 0x007E7E7E7E7E7E00);
218
- unsigned long blank_r45 = rotate_r45(blank);
219
- unsigned long my_l45 = rotate_l45(my);
220
- unsigned long op_l45 = rotate_l45(op & 0x007E7E7E7E7E7E00);
221
- unsigned long blank_l45 = rotate_l45(blank);
215
+ uint64_t diagonal_pos(uint64_t my, uint64_t op, uint64_t blank) {
216
+ uint64_t my_r45 = rotate_r45(my);
217
+ uint64_t op_r45 = rotate_r45(op & 0x007E7E7E7E7E7E00);
218
+ uint64_t blank_r45 = rotate_r45(blank);
219
+ uint64_t my_l45 = rotate_l45(my);
220
+ uint64_t op_l45 = rotate_l45(op & 0x007E7E7E7E7E7E00);
221
+ uint64_t blank_l45 = rotate_l45(blank);
222
222
  return rotate_l45(right_pos(my_r45, op_r45, blank_r45) | left_pos(my_r45, op_r45, blank_r45)) |
223
223
  rotate_r45(right_pos(my_l45, op_l45, blank_l45) | left_pos(my_l45, op_l45, blank_l45));
224
224
  }
225
225
 
226
- unsigned long right_pos(unsigned long my, unsigned long op, unsigned long blank) {
227
- unsigned long rev = (my << 1) & op;
226
+ uint64_t right_pos(uint64_t my, uint64_t op, uint64_t blank) {
227
+ uint64_t rev = (my << 1) & op;
228
228
  rev |= (rev << 1) & op;
229
229
  rev |= (rev << 1) & op;
230
230
  rev |= (rev << 1) & op;
@@ -233,8 +233,8 @@ unsigned long right_pos(unsigned long my, unsigned long op, unsigned long blank)
233
233
  return (rev << 1) & blank;
234
234
  }
235
235
 
236
- unsigned long left_pos(unsigned long my, unsigned long op, unsigned long blank) {
237
- unsigned long rev = (my >> 1) & op;
236
+ uint64_t left_pos(uint64_t my, uint64_t op, uint64_t blank) {
237
+ uint64_t rev = (my >> 1) & op;
238
238
  rev |= (rev >> 1) & op;
239
239
  rev |= (rev >> 1) & op;
240
240
  rev |= (rev >> 1) & op;
@@ -3,24 +3,24 @@
3
3
 
4
4
  #include "reversi.h"
5
5
 
6
- unsigned long XY2BB(int x, int y);
7
- VALUE BB2XY(unsigned long bb);
6
+ uint64_t XY2BB(int x, int y);
7
+ VALUE BB2XY(uint64_t bb);
8
8
 
9
- unsigned long rotate_r90(unsigned long bb);
10
- unsigned long rotate_l90(unsigned long bb);
11
- unsigned long rotate_r45(unsigned long bb);
12
- unsigned long rotate_l45(unsigned long bb);
9
+ uint64_t rotate_r90(uint64_t bb);
10
+ uint64_t rotate_l90(uint64_t bb);
11
+ uint64_t rotate_r45(uint64_t bb);
12
+ uint64_t rotate_l45(uint64_t bb);
13
13
 
14
- unsigned long horizontal_pat(unsigned long my, unsigned long op, unsigned long p);
15
- unsigned long vertical_pat(unsigned long my, unsigned long op, unsigned long p);
16
- unsigned long diagonal_pat(unsigned long my, unsigned long op, unsigned long p);
17
- unsigned long right_pat(unsigned long my, unsigned long op, unsigned long p);
18
- unsigned long left_pat(unsigned long my, unsigned long op, unsigned long p);
14
+ uint64_t horizontal_pat(uint64_t my, uint64_t op, uint64_t p);
15
+ uint64_t vertical_pat(uint64_t my, uint64_t op, uint64_t p);
16
+ uint64_t diagonal_pat(uint64_t my, uint64_t op, uint64_t p);
17
+ uint64_t right_pat(uint64_t my, uint64_t op, uint64_t p);
18
+ uint64_t left_pat(uint64_t my, uint64_t op, uint64_t p);
19
19
 
20
- unsigned long horizontal_pos(unsigned long my, unsigned long op, unsigned long blank);
21
- unsigned long vertical_pos(unsigned long my, unsigned long op, unsigned long blank);
22
- unsigned long diagonal_pos(unsigned long my, unsigned long op, unsigned long blank);
23
- unsigned long right_pos(unsigned long my, unsigned long op, unsigned long blank);
24
- unsigned long left_pos(unsigned long my, unsigned long op, unsigned long blank);
20
+ uint64_t horizontal_pos(uint64_t my, uint64_t op, uint64_t blank);
21
+ uint64_t vertical_pos(uint64_t my, uint64_t op, uint64_t blank);
22
+ uint64_t diagonal_pos(uint64_t my, uint64_t op, uint64_t blank);
23
+ uint64_t right_pos(uint64_t my, uint64_t op, uint64_t blank);
24
+ uint64_t left_pos(uint64_t my, uint64_t op, uint64_t blank);
25
25
 
26
26
  #endif
data/ext/reversi/board.c CHANGED
@@ -72,7 +72,7 @@ VALUE status(VALUE self) {
72
72
  VALUE white_ary = rb_ary_new();
73
73
  VALUE none_ary = rb_ary_new();
74
74
  VALUE status = rb_hash_new();
75
- unsigned long black = 0, white = 0, blank = 0, p = 0;
75
+ uint64_t black = 0, white = 0, blank = 0, p = 0;
76
76
  struct bit_board *ptr;
77
77
  Data_Get_Struct(self, struct bit_board, ptr);
78
78
 
@@ -111,8 +111,8 @@ VALUE status(VALUE self) {
111
111
  * @return [Integer] the openness
112
112
  */
113
113
  VALUE openness(VALUE self, VALUE rb_x, VALUE rb_y) {
114
- unsigned long p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
115
- unsigned long blank = 0, bb = 0;
114
+ uint64_t p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
115
+ uint64_t blank = 0, bb = 0;
116
116
  struct bit_board *ptr;
117
117
  Data_Get_Struct(self, struct bit_board, ptr);
118
118
 
@@ -141,7 +141,7 @@ VALUE openness(VALUE self, VALUE rb_x, VALUE rb_y) {
141
141
  * @return [Symbol] the color or `:none`
142
142
  */
143
143
  VALUE at(VALUE self, VALUE rb_x, VALUE rb_y) {
144
- unsigned long p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
144
+ uint64_t p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
145
145
  struct bit_board *ptr;
146
146
  Data_Get_Struct(self, struct bit_board, ptr);
147
147
 
@@ -157,7 +157,7 @@ VALUE at(VALUE self, VALUE rb_x, VALUE rb_y) {
157
157
  * @return [Integer] the sum of the counted disks
158
158
  */
159
159
  VALUE count_disks(VALUE self, VALUE color) {
160
- unsigned long bb = 0;
160
+ uint64_t bb = 0;
161
161
  struct bit_board *ptr;
162
162
  Data_Get_Struct(self, struct bit_board, ptr);
163
163
 
@@ -182,7 +182,7 @@ VALUE count_disks(VALUE self, VALUE color) {
182
182
  * @return [Array<Array<Integer, Integer>>]
183
183
  */
184
184
  VALUE next_moves(VALUE self, VALUE color) {
185
- unsigned long my = 0, op = 0, blank = 0, p = 0, pos = 0;
185
+ uint64_t my = 0, op = 0, blank = 0, p = 0, pos = 0;
186
186
  VALUE moves = rb_ary_new();
187
187
  struct bit_board *ptr;
188
188
  Data_Get_Struct(self, struct bit_board, ptr);
@@ -212,7 +212,7 @@ VALUE next_moves(VALUE self, VALUE color) {
212
212
  * @param color [Integer]
213
213
  */
214
214
  VALUE put_disk(VALUE self, VALUE rb_x, VALUE rb_y, VALUE color) {
215
- unsigned long p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
215
+ uint64_t p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
216
216
  struct bit_board *ptr;
217
217
  Data_Get_Struct(self, struct bit_board, ptr);
218
218
 
@@ -234,8 +234,8 @@ VALUE put_disk(VALUE self, VALUE rb_x, VALUE rb_y, VALUE color) {
234
234
  * @param color [Integer]
235
235
  */
236
236
  VALUE flip_disks(VALUE self, VALUE rb_x, VALUE rb_y, VALUE color) {
237
- unsigned long p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
238
- unsigned long my = 0, op = 0, rev = 0;
237
+ uint64_t p = XY2BB(FIX2INT(rb_x), FIX2INT(rb_y));
238
+ uint64_t my = 0, op = 0, rev = 0;
239
239
  struct bit_board *ptr;
240
240
  Data_Get_Struct(self, struct bit_board, ptr);
241
241
 
data/ext/reversi/board.h CHANGED
@@ -4,8 +4,8 @@
4
4
  #include "reversi.h"
5
5
 
6
6
  struct bit_board {
7
- unsigned long black;
8
- unsigned long white;
7
+ uint64_t black;
8
+ uint64_t white;
9
9
  };
10
10
 
11
11
  VALUE bit_board_alloc(VALUE class);
@@ -5,6 +5,7 @@
5
5
  #include <stdlib.h>
6
6
  #include <memory.h>
7
7
  #include <stdio.h>
8
+ #include <stdint.h>
8
9
 
9
10
  #include "board.h"
10
11
  #include "bit_board_functions.h"
@@ -1,3 +1,3 @@
1
1
  module Reversi
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reversi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - seinosuke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler