summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-09 19:52:18 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-09 19:52:18 +0900
commitb717e575eacfd446d1daedc4c3297b985a8f69d9 (patch)
treeb58bc5d990219c2395b906b7185db5db2fa8bbd2 /src/common
parent:v: (diff)
downloadsharkey-b717e575eacfd446d1daedc4c3297b985a8f69d9.tar.gz
sharkey-b717e575eacfd446d1daedc4c3297b985a8f69d9.tar.bz2
sharkey-b717e575eacfd446d1daedc4c3297b985a8f69d9.zip
Refactor: Remove the magick numbers
Diffstat (limited to 'src/common')
-rw-r--r--src/common/othello.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/common/othello.ts b/src/common/othello.ts
index 0f96d477ee..aa53dee465 100644
--- a/src/common/othello.ts
+++ b/src/common/othello.ts
@@ -1,3 +1,5 @@
+const BOARD_SIZE = 8;
+
export default class Othello {
public board: Array<Array<'black' | 'white'>>;
@@ -142,7 +144,7 @@ export default class Othello {
// 右上
iterate = createIterater();
- for (let c = 0, i = 1; i < Math.min(8 - targetx, targety); c++, i++) {
+ for (let c = 0, i = 1; i < Math.min(BOARD_SIZE - targetx, targety); c++, i++) {
if (iterate(targetx + i, targety - i)) {
res.push([1, c]);
break;
@@ -151,7 +153,7 @@ export default class Othello {
// 右
iterate = createIterater();
- for (let c = 0, x = targetx + 1; x < 8; c++, x++) {
+ for (let c = 0, x = targetx + 1; x < BOARD_SIZE; c++, x++) {
if (iterate(x, targety)) {
res.push([2, c]);
break;
@@ -160,7 +162,7 @@ export default class Othello {
// 右下
iterate = createIterater();
- for (let c = 0, i = 1; i < Math.min(8 - targetx, 8 - targety); c++, i++) {
+ for (let c = 0, i = 1; i < Math.min(BOARD_SIZE - targetx, BOARD_SIZE - targety); c++, i++) {
if (iterate(targetx + i, targety + i)) {
res.push([3, c]);
break;
@@ -169,7 +171,7 @@ export default class Othello {
// 下
iterate = createIterater();
- for (let c = 0, y = targety + 1; y < 8; c++, y++) {
+ for (let c = 0, y = targety + 1; y < BOARD_SIZE; c++, y++) {
if (iterate(targetx, y)) {
res.push([4, c]);
break;
@@ -178,7 +180,7 @@ export default class Othello {
// 左下
iterate = createIterater();
- for (let c = 0, i = 1; i < Math.min(targetx, 8 - targety); c++, i++) {
+ for (let c = 0, i = 1; i < Math.min(targetx, BOARD_SIZE - targety); c++, i++) {
if (iterate(targetx - i, targety + i)) {
res.push([5, c]);
break;
@@ -238,11 +240,11 @@ export function ai(color: string, othello: Othello) {
// 左上
(p[0] == 0 && p[1] == 0) ||
// 右上
- (p[0] == 7 && p[1] == 0) ||
+ (p[0] == (BOARD_SIZE - 1) && p[1] == 0) ||
// 右下
- (p[0] == 7 && p[1] == 7) ||
+ (p[0] == (BOARD_SIZE - 1) && p[1] == (BOARD_SIZE - 1)) ||
// 左下
- (p[0] == 0 && p[1] == 7)
+ (p[0] == 0 && p[1] == (BOARD_SIZE - 1))
);
if (corners.length > 0) { // どこかしらの角に打てる場合