回答編集履歴
1
不要な関数定義が含まれていました
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
//4種類の数値(剣」「盾」「コイン」「ポーション」に置き換えてください)をつかった行列データを定義
|
14
14
|
|
15
|
-
//今回は4,5行目
|
15
|
+
//今回は4,5行目あたりに2の当たりが仕込まれています
|
16
16
|
|
17
17
|
const mtx56 = [
|
18
18
|
|
@@ -29,16 +29,6 @@
|
|
29
29
|
[ 1, 1, 2, 3, 4 ],
|
30
30
|
|
31
31
|
];
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
/** 指定のindexの値を取得 */
|
36
|
-
|
37
|
-
function get1(arr, x){
|
38
|
-
|
39
|
-
return arr ? arr[x] : undefined;
|
40
|
-
|
41
|
-
}
|
42
32
|
|
43
33
|
|
44
34
|
|
@@ -74,17 +64,17 @@
|
|
74
64
|
|
75
65
|
const values = [
|
76
66
|
|
77
|
-
get2(mtx56,
|
67
|
+
get2(mtx56, around.top[0] , around.top[1] ),
|
78
68
|
|
79
|
-
get2(mtx56,
|
69
|
+
get2(mtx56, around.right[0] , around.right[1] ),
|
80
70
|
|
81
|
-
get2(mtx56,
|
71
|
+
get2(mtx56, around.bottom[0] , around.bottom[1] ),
|
82
72
|
|
83
|
-
get2(mtx56,
|
73
|
+
get2(mtx56, around.left[0] , around.left[1] ),
|
84
74
|
|
85
75
|
];
|
86
76
|
|
87
|
-
//チェック中
|
77
|
+
//チェック中値と同じ値だけ抽出し、2件以上ならばtrue
|
88
78
|
|
89
79
|
return values.filter( val => val === cell ).length >= 2;
|
90
80
|
|
@@ -94,15 +84,11 @@
|
|
94
84
|
|
95
85
|
console.time( 'check' );
|
96
86
|
|
97
|
-
//メイン処理開始
|
87
|
+
//メイン処理開始( 実装時は関数化 )
|
98
88
|
|
99
89
|
const isSafe = mtx56.some((row, i) =>{
|
100
90
|
|
101
|
-
return row.some( (cell, j) =>
|
91
|
+
return row.some( (cell, j) => check(cell, i, j) )
|
102
|
-
|
103
|
-
return check(cell, i, j)
|
104
|
-
|
105
|
-
})
|
106
92
|
|
107
93
|
});
|
108
94
|
|