diff --git a/func.js b/func.js index 8056b3b..d317070 100644 --- a/func.js +++ b/func.js @@ -2,18 +2,32 @@ var prev_board = [] $(function () { - var init_board = [0, 2, 0, 0, 0, 0, -5, 0, -3, 0, 1, 0, 4, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -2, 0]; + var init_board = [0, 2, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -2, 0]; // var init_board = [0,2,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] const red = "#E83D04" const white = "#E8E077" const brown = "#4C2E00" var prev_board = [] var color = white; - + + + var quad = false; + + // var roll = [Math.floor(Math.random() * 6)+1, Math.floor(Math.random() * 6)+1] + var roll = [1,3]; + var total_roll = roll[0] + roll[1]; + + if (roll[0] == roll[1]) { + total_roll = roll[0] * 4; + roll = [roll[0], roll[0], roll[0], roll[0]]; + quad = true; + } + + console.log("Initial roll:"); + console.log(roll); + + // Build pins - - - for (var i = 0; i < 26; i++) { if (i < 13 && 0 < i) { @@ -98,35 +112,51 @@ $(function () { } } - // console.log("lol"); - // console.log(prev_board[fromIdx]); - // console.log(prev_board[toIdx]); - board = convertToBoard(); console.log("board!!!!"); console.log(board); - prev_board = handleMove(prev_board, board); + var data_stuff = handleMove(prev_board, board, roll, total_roll); + + prev_board = data_stuff['board']; + roll = data_stuff['roll']; + total_roll = data_stuff['total_roll']; convertToPins(prev_board); - - // if (board != convertToBoard()) { - // prev_board = getBotMove(prev_board); - // convertToPins(prev_board); - // } - + + + if (total_roll == 0) { + if (board != convertToBoard()) { + prev_board = getBotMove(prev_board); + convertToPins(prev_board); + + roll = [Math.floor(Math.random() * 6)+1, Math.floor(Math.random() * 6)+1] + total_roll = roll[0] + roll[1] + + if (roll[0] == roll[1]) { + total_roll = roll[0] * 4; + roll = [roll[0], roll[0], roll[0], roll[0]] + quad = true; + } + } + } } }); }); -function handleMove(prev_board, board) { - var new_board = postRequest(prev_board, board); - test = []; +function handleMove(prev_board, board, roll, total_roll) { + var data = postRequest(prev_board, board, roll, total_roll); + var new_board = data['board']; + total_roll = data['total_roll']; + roll = data['roll']; + + var test = []; for (var i = 0; i<26; i++) { test.push(parseInt(new_board[i])); } - return test; + + return {'board': test, 'total_roll': total_roll, 'roll': roll}; }; @@ -223,10 +253,10 @@ function onPost(data) { }; -function postRequest(prev_board, board) { +function postRequest(prev_board, board, roll, total_roll) { console.log(prev_board); var result = ""; - var data = {'board' : board.toString(), 'prev_board': prev_board.toString()} + var data = {'board' : board.toString(), 'prev_board': prev_board.toString(), 'roll': roll.toString(), 'total_roll': total_roll.toString()} $.ajax({ type : "POST", async: false, @@ -237,5 +267,6 @@ function postRequest(prev_board, board) { } }); console.log(result); - return result.split(','); + var split_result = result.split("#"); + return {'board': split_result[0].split(","),'total_roll': split_result[1], 'roll': split_result[2].split(",")}; };