分からない事
javascript
1const board_preference = {0: "+", 1: "○", 2: "●", 3: "■", 4: "+"}; 2let board = 3[[0,0,0,0,0,0,0,0], 4[0,0,0,0,0,0,0,0], 5[0,0,0,4,3,0,0,0], 6[0,0,4,1,2,3,0,0], 7[0,0,3,2,1,4,0,0], 8[0,0,0,3,4,0,0,0], 9[0,0,0,0,0,0,0,0], 10[0,0,0,0,0,0,0,0]]; 11const user_turn = (user_selection_vertical, user_selection_horizontal) => { 12 var user_x = user_selection_vertical; 13 var user_y = user_selection_horizontal; 14 if (board[user_x][user_y] == 3) { 15 board[user_selection_vertical][user_selection_horizontal] = 1; 16 } 17 let user_turn_flag = true; 18 let user_turn_count = 0; 19 while (user_turn_flag) { 20 user_turn_count++; 21 if (!user_x + user_turn_count == 0) { 22 if (board[user_x - user_turn_count][user_y] == 2&&board[user_x - (user_turn_count + 1)][user_y] == 1) { 23 changehost(user_x - user_turn_count,user_y,1); 24 } 25 } 26 if (!user_x + user_turn_count == 7) { 27 if (board[user_x + user_turn_count][user_y] == 2&&board[user_x +(user_turn_count + 1)][user_y] == 1) { 28 changehost(user_x - user_turn_count,user_y,1); 29 } 30 } 31 if (!user_y + user_turn_count == 0) { 32 if (board[user_x][user_y - user_turn_count] == 2&&board[user_x][user_y - (user_turn_count + 1)] == 1) { 33 changehost(user_x - user_turn_count,user_y,1); 34 } 35 } 36 if (!user_y + user_turn_count == 7) { 37 if (board[user_x][user_y + user_turn_count] == 2&&board[user_x][user_y + (user_turn_count + 1)] == 1) { 38 changehost(user_x - user_turn_count,user_y,1); 39 } 40 } 41 if (user_turn_count == 7) {user_turn_flag = false;} 42 } 43}
上記のコードにて41行目、39文字から
javascript
1 if (!user_x + user_turn_count == 7) { 2 if (board[user_x + user_turn_count][user_y] == 2&&board[user_x +(user_turn_count + 1)][user_y] == 1) { 3 changehost(user_x - user_turn_count,user_y,1); 4 } 5 }
多分上記のコードで
TypeError: Cannot read property '2' of undefined
と出たのですがどうすればよいでしょうか?
全コード
javascript
1const board_preference = {0: "+", 1: "○", 2: "●", 3: "■", 4: "+"}; 2let board = 3[[0,0,0,0,0,0,0,0], 4[0,0,0,0,0,0,0,0], 5[0,0,0,4,3,0,0,0], 6[0,0,4,1,2,3,0,0], 7[0,0,3,2,1,4,0,0], 8[0,0,0,3,4,0,0,0], 9[0,0,0,0,0,0,0,0], 10[0,0,0,0,0,0,0,0]]; 11//ban[index(縦)][index(横)] 12let board_evaluation = 13[[20,3,10,0,0,10,3,20], 14[3,3,0,0,0,0,3,3], 15[10,0,10,1,0,10,0,10], 16[0,0,1,0,0,0,0,0], 17[0,0,0,0,0,2,0,0], 18[10,0,10,0,1,10,0,10], 19[3,3,0,0,0,0,3,3], 20[20,3,10,0,0,10,3,20]]; 21 22const 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]];} 23/*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;} 24 25const user_turn = (user_selection_vertical, user_selection_horizontal) => { 26 var user_x = user_selection_vertical; 27 var user_y = user_selection_horizontal; 28 if (board[user_x][user_y] == 3) { 29 board[user_selection_vertical][user_selection_horizontal] = 1; 30 } 31 let user_turn_flag = true; 32 let user_turn_count = 0; 33 while (user_turn_flag) { 34 user_turn_count++; 35 if (!user_x + user_turn_count == 0) { 36 if (board[user_x - user_turn_count][user_y] == 2&&board[user_x - (user_turn_count + 1)][user_y] == 1) { 37 changehost(user_x - user_turn_count,user_y,1); 38 } 39 } 40 if (!user_x + user_turn_count == 7) { 41 if (board[user_x + user_turn_count][user_y] == 2&&board[user_x +(user_turn_count + 1)][user_y] == 1) { 42 changehost(user_x - user_turn_count,user_y,1); 43 } 44 } 45 if (!user_y + user_turn_count == 0) { 46 if (board[user_x][user_y - user_turn_count] == 2&&board[user_x][user_y - (user_turn_count + 1)] == 1) { 47 changehost(user_x - user_turn_count,user_y,1); 48 } 49 } 50 if (!user_y + user_turn_count == 7) { 51 if (board[user_x][user_y + user_turn_count] == 2&&board[user_x][user_y + (user_turn_count + 1)] == 1) { 52 changehost(user_x - user_turn_count,user_y,1); 53 } 54 } 55 if (user_turn_count == 7) {user_turn_flag = false;} 56 } 57} 58 59const changehost = (host_selection_vertical, host_selection_horizontal,Human) => { 60 let host_x = host_selection_vertical; 61 let host_y = host_selection_horizontal; 62 board[host_x][host_y] = Human; 63} 64user_turn(4,2); 65console.log(board_display());
回答1件
あなたの回答
tips
プレビュー