diff --git a/typescript/func.js b/typescript/func.js index b95adc0..dcfb778 100644 --- a/typescript/func.js +++ b/typescript/func.js @@ -6,6 +6,7 @@ var totalRoll = 0; var quad = false; var prevBoard = []; var pubeval = false; +var turnCount = 1; var currentPlayer = 1; var toggled = false; const 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]; @@ -58,7 +59,7 @@ $(function () { div.append(checkers_div); $("#pins").append(div); convertToPins(init_board); - //prevBoard = convertToBoard(); + // prevBoard = convertToBoard(); // let initBotResult = getBotMove(init_board); // prevBoard = initBotResult.board; // convertToPins(prevBoard); @@ -130,6 +131,10 @@ function handleRoll() { } $("#roll").text("roll: " + roll.toString() + " total moves: " + totalRoll.toString()); } +function displayTurnCount() { + // $("#turnCount").text(turnCount.toString()); + console.log(turnCount); +} function toggleDemoOn() { prevBoard = convertToBoard(); if (!toggled) { @@ -164,6 +169,7 @@ function doDemoMove() { let isFinished = isGameDone(tmp); if (isFinished) { prevBoard = init_board; + turnCount = 1; } var doDemoMove; if ($("#doPubevalDemo").is(':checked')) { @@ -172,9 +178,12 @@ function doDemoMove() { else { doDemoMove = getNetworkMove; } + handleRoll(); let res = doDemoMove(prevBoard, currentPlayer); prevBoard = res.board; convertToPins(prevBoard); + turnCount = turnCount + 1; + displayTurnCount(); currentPlayer = currentPlayer * -1; } function handleMove(previousBoard, board, roll, totalRoll, quad) { @@ -235,7 +244,7 @@ function convertToPins(board) { } ; function getNetworkMove(board, player) { - let data = { 'board': board.toString(), 'player': player.toString() }; + let data = { 'board': board.toString(), 'player': player.toString(), 'roll': roll.toString() }; let result = { board: [] }; $.ajax({ type: "POST", @@ -252,7 +261,7 @@ function getNetworkMove(board, player) { } ; function getPubevalMove(board, player) { - let data = { 'board': board.toString(), 'player': player.toString() }; + let data = { 'board': board.toString(), 'player': player.toString(), 'roll': roll.toString() }; let result = { board: [] }; $.ajax({ type: "POST", @@ -292,14 +301,7 @@ function noMovesAvailable() { prevBoard = res.board; console.log(prevBoard); convertToPins(prevBoard); - var roll = [Math.floor(Math.random() * 6) + 1, Math.floor(Math.random() * 6) + 1]; - if (roll[0] == roll[1]) { - console.log("huehue"); - totalRoll = roll[0] * 4; - roll = [roll[0], roll[0], roll[0], roll[0]]; - quad = true; - } - $("#roll").text("roll: " + roll.toString() + " total moves: " + totalRoll.toString()); + handleRoll(); } function postRequest(previousBoard, board, roll, totalRoll, quad) { let result = { board: [], totalRoll: 0, roll: [] }; diff --git a/typescript/func.ts b/typescript/func.ts index 8a75abd..48d01d3 100644 --- a/typescript/func.ts +++ b/typescript/func.ts @@ -6,6 +6,7 @@ var totalRoll = 0; var quad = false; var prevBoard = [] var pubeval = false; +var turnCount = 1; var currentPlayer = 1; var toggled: boolean = false; const 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]; @@ -78,10 +79,10 @@ $(function () { convertToPins(init_board); - prevBoard = convertToBoard(); - let initBotResult = getBotMove(init_board); - prevBoard = initBotResult.board; - convertToPins(prevBoard); + // prevBoard = convertToBoard(); + // let initBotResult = getBotMove(init_board); + // prevBoard = initBotResult.board; + // convertToPins(prevBoard); prevBoard = convertToBoard(); @@ -120,6 +121,7 @@ $(function () { cloned_board[toIdx] *= -1 // Load the board into the pins convertToPins(cloned_board); + board = cloned_board; } } @@ -171,6 +173,12 @@ function handleRoll() { } +function displayTurnCount() { + // $("#turnCount").text(turnCount.toString()); + console.log(turnCount); +} + + function toggleDemoOn() { prevBoard = convertToBoard(); @@ -215,6 +223,7 @@ function doDemoMove() { let isFinished = isGameDone(tmp); if (isFinished) { prevBoard = init_board; + turnCount = 1; } var doDemoMove; @@ -224,10 +233,14 @@ function doDemoMove() { } else { doDemoMove = getNetworkMove; } + + handleRoll(); let res = doDemoMove(prevBoard, currentPlayer); prevBoard = res.board; convertToPins(prevBoard); + turnCount = turnCount + 1; + displayTurnCount(); currentPlayer = currentPlayer * -1; } @@ -303,7 +316,7 @@ interface botMove { function getNetworkMove(board, player): botMove { - let data = {'board' : board.toString(), 'player' : player.toString()} + let data = {'board' : board.toString(), 'player' : player.toString(), 'roll' : roll.toString()} let result : botMove = {board: []} $.ajax({ @@ -323,7 +336,7 @@ function getNetworkMove(board, player): botMove { function getPubevalMove(board, player): botMove { - let data = {'board' : board.toString(), 'player' : player.toString()} + let data = {'board' : board.toString(), 'player' : player.toString(), 'roll' : roll.toString()} let result : botMove = {board: []} $.ajax({ @@ -368,17 +381,8 @@ function noMovesAvailable() { prevBoard = res.board; console.log(prevBoard); convertToPins(prevBoard); - - var roll = [Math.floor(Math.random() * 6)+1, Math.floor(Math.random() * 6)+1] - if (roll[0] == roll[1]) { - console.log("huehue"); - totalRoll = roll[0] * 4; - roll = [roll[0], roll[0], roll[0], roll[0]] - quad = true; - } - - $( "#roll" ).text("roll: " + roll.toString() + " total moves: " + totalRoll.toString()); + handleRoll(); }