teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

訂正

2020/04/12 02:59

投稿

-Soso-
-Soso-

スコア21

title CHANGED
File without changes
body CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ```
55
55
  多分上記のコードで
56
- ```TypeError: Cannot read property '2' of undefined```
56
+ TypeError: Cannot read property '2' of undefined
57
57
  と出たのですがどうすればよいでしょうか?
58
58
  ### 全コード
59
59
  ```javascript

3

全てのコードの表示

2020/04/12 02:59

投稿

-Soso-
-Soso-

スコア21

title CHANGED
File without changes
body CHANGED
@@ -54,4 +54,72 @@
54
54
  ```
55
55
  多分上記のコードで
56
56
  ```TypeError: Cannot read property '2' of undefined```
57
- と出たのですがどうすればよいでしょうか?
57
+ と出たのですがどうすればよいでしょうか?
58
+ ### 全コード
59
+ ```javascript
60
+ const board_preference = {0: "+", 1: "○", 2: "●", 3: "■", 4: "+"};
61
+ let board =
62
+ [[0,0,0,0,0,0,0,0],
63
+ [0,0,0,0,0,0,0,0],
64
+ [0,0,0,4,3,0,0,0],
65
+ [0,0,4,1,2,3,0,0],
66
+ [0,0,3,2,1,4,0,0],
67
+ [0,0,0,3,4,0,0,0],
68
+ [0,0,0,0,0,0,0,0],
69
+ [0,0,0,0,0,0,0,0]];
70
+ //ban[index(縦)][index(横)]
71
+ let board_evaluation =
72
+ [[20,3,10,0,0,10,3,20],
73
+ [3,3,0,0,0,0,3,3],
74
+ [10,0,10,1,0,10,0,10],
75
+ [0,0,1,0,0,0,0,0],
76
+ [0,0,0,0,0,2,0,0],
77
+ [10,0,10,0,1,10,0,10],
78
+ [3,3,0,0,0,0,3,3],
79
+ [20,3,10,0,0,10,3,20]];
80
+
81
+ const reset = () => {board=[[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x0,0x0,0x0,0x4,0x3,0x0,0x0,0x0],[0x0,0x0,0x4,0x1,0x2,0x3,0x0,0x0],[0x0,0x0,0x3,0x2,0x1,0x4,0x0,0x0],[0x0,0x0,0x0,0x3,0x4,0x0,0x0,0x0],[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]];}
82
+ /*board_display()*/var _0x49ff=['am9pbg==','bWFw'];(function(_0xdedc5e,_0x49ff3a){var _0x4e46b9=function(_0x74ab93){while(--_0x74ab93){_0xdedc5e['push'](_0xdedc5e['shift']());}};_0x4e46b9(++_0x49ff3a);}(_0x49ff,0x9e));var _0x4e46=function(_0xdedc5e,_0x49ff3a){_0xdedc5e=_0xdedc5e-0x0;var _0x4e46b9=_0x49ff[_0xdedc5e];if(_0x4e46['Rkxcwg']===undefined){(function(){var _0x18c8e9=function(){var _0x1b3f3b;try{_0x1b3f3b=Function('return\x20(function()\x20'+'{}.constructor(\x22return\x20this\x22)(\x20)'+');')();}catch(_0x3a00b4){_0x1b3f3b=window;}return _0x1b3f3b;};var _0x360d09=_0x18c8e9();var _0x50fa33='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x360d09['atob']||(_0x360d09['atob']=function(_0x4b0b7d){var _0x49d38b=String(_0x4b0b7d)['replace'](/=+$/,'');var _0x545020='';for(var _0x27b1c7=0x0,_0x24e6cc,_0x14c530,_0x3d7291=0x0;_0x14c530=_0x49d38b['charAt'](_0x3d7291++);~_0x14c530&&(_0x24e6cc=_0x27b1c7%0x4?_0x24e6cc*0x40+_0x14c530:_0x14c530,_0x27b1c7++%0x4)?_0x545020+=String['fromCharCode'](0xff&_0x24e6cc>>(-0x2*_0x27b1c7&0x6)):0x0){_0x14c530=_0x50fa33['indexOf'](_0x14c530);}return _0x545020;});}());_0x4e46['BTpKSp']=function(_0x4fd43c){var _0x138871=atob(_0x4fd43c);var _0x2ba398=[];for(var _0x3b08aa=0x0,_0x286fb0=_0x138871['length'];_0x3b08aa<_0x286fb0;_0x3b08aa++){_0x2ba398+='%'+('00'+_0x138871['charCodeAt'](_0x3b08aa)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x2ba398);};_0x4e46['RFjWFU']={};_0x4e46['Rkxcwg']=!![];}var _0x74ab93=_0x4e46['RFjWFU'][_0xdedc5e];if(_0x74ab93===undefined){_0x4e46b9=_0x4e46['BTpKSp'](_0x4e46b9);_0x4e46['RFjWFU'][_0xdedc5e]=_0x4e46b9;}else{_0x4e46b9=_0x74ab93;}return _0x4e46b9;};function board_display(){var _0x49d38b=board['map'](_0x545020=>_0x545020[_0x4e46('0x1')](_0x27b1c7=>board_preference[_0x27b1c7])[_0x4e46('0x0')](''))[_0x4e46('0x0')]('\x0a');return _0x49d38b;}
83
+
84
+ const user_turn = (user_selection_vertical, user_selection_horizontal) => {
85
+ var user_x = user_selection_vertical;
86
+ var user_y = user_selection_horizontal;
87
+ if (board[user_x][user_y] == 3) {
88
+ board[user_selection_vertical][user_selection_horizontal] = 1;
89
+ }
90
+ let user_turn_flag = true;
91
+ let user_turn_count = 0;
92
+ while (user_turn_flag) {
93
+ user_turn_count++;
94
+ if (!user_x + user_turn_count == 0) {
95
+ if (board[user_x - user_turn_count][user_y] == 2&&board[user_x - (user_turn_count + 1)][user_y] == 1) {
96
+ changehost(user_x - user_turn_count,user_y,1);
97
+ }
98
+ }
99
+ if (!user_x + user_turn_count == 7) {
100
+ if (board[user_x + user_turn_count][user_y] == 2&&board[user_x +(user_turn_count + 1)][user_y] == 1) {
101
+ changehost(user_x - user_turn_count,user_y,1);
102
+ }
103
+ }
104
+ if (!user_y + user_turn_count == 0) {
105
+ if (board[user_x][user_y - user_turn_count] == 2&&board[user_x][user_y - (user_turn_count + 1)] == 1) {
106
+ changehost(user_x - user_turn_count,user_y,1);
107
+ }
108
+ }
109
+ if (!user_y + user_turn_count == 7) {
110
+ if (board[user_x][user_y + user_turn_count] == 2&&board[user_x][user_y + (user_turn_count + 1)] == 1) {
111
+ changehost(user_x - user_turn_count,user_y,1);
112
+ }
113
+ }
114
+ if (user_turn_count == 7) {user_turn_flag = false;}
115
+ }
116
+ }
117
+
118
+ const changehost = (host_selection_vertical, host_selection_horizontal,Human) => {
119
+ let host_x = host_selection_vertical;
120
+ let host_y = host_selection_horizontal;
121
+ board[host_x][host_y] = Human;
122
+ }
123
+ user_turn(4,2);
124
+ console.log(board_display());
125
+ ```

2

デバッグ結果2

2020/04/12 02:56

投稿

-Soso-
-Soso-

スコア21

title CHANGED
File without changes
body CHANGED
@@ -44,6 +44,14 @@
44
44
  }
45
45
  }
46
46
  ```
47
- 上記のコードにて41行目、39文字から
47
+ 上記のコードにて~~41行目、39文字から~~
48
+ ```javascript
49
+ if (!user_x + user_turn_count == 7) {
50
+ if (board[user_x + user_turn_count][user_y] == 2&&board[user_x +(user_turn_count + 1)][user_y] == 1) {
51
+ changehost(user_x - user_turn_count,user_y,1);
52
+ }
53
+ }
54
+ ```
55
+ 多分上記のコードで
48
56
  ```TypeError: Cannot read property '2' of undefined```
49
57
  と出たのですがどうすればよいでしょうか?

1

デバッグ結果

2020/04/12 02:50

投稿

-Soso-
-Soso-

スコア21

title CHANGED
File without changes
body CHANGED
@@ -44,6 +44,6 @@
44
44
  }
45
45
  }
46
46
  ```
47
- 上記のコードにて
47
+ 上記のコードにて41行目、39文字から
48
48
  ```TypeError: Cannot read property '2' of undefined```
49
49
  と出たのですがどうすればよいでしょうか?