fixed some stuff with board after being on the bar
This commit is contained in:
parent
87cfc2b8a9
commit
f53382cc4b
|
@ -6,6 +6,7 @@ var totalRoll = 0;
|
||||||
var quad = false;
|
var quad = false;
|
||||||
var prevBoard = [];
|
var prevBoard = [];
|
||||||
var pubeval = false;
|
var pubeval = false;
|
||||||
|
var turnCount = 1;
|
||||||
var currentPlayer = 1;
|
var currentPlayer = 1;
|
||||||
var toggled = false;
|
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];
|
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);
|
div.append(checkers_div);
|
||||||
$("#pins").append(div);
|
$("#pins").append(div);
|
||||||
convertToPins(init_board);
|
convertToPins(init_board);
|
||||||
//prevBoard = convertToBoard();
|
// prevBoard = convertToBoard();
|
||||||
// let initBotResult = getBotMove(init_board);
|
// let initBotResult = getBotMove(init_board);
|
||||||
// prevBoard = initBotResult.board;
|
// prevBoard = initBotResult.board;
|
||||||
// convertToPins(prevBoard);
|
// convertToPins(prevBoard);
|
||||||
|
@ -130,6 +131,10 @@ function handleRoll() {
|
||||||
}
|
}
|
||||||
$("#roll").text("roll: " + roll.toString() + " total moves: " + totalRoll.toString());
|
$("#roll").text("roll: " + roll.toString() + " total moves: " + totalRoll.toString());
|
||||||
}
|
}
|
||||||
|
function displayTurnCount() {
|
||||||
|
// $("#turnCount").text(turnCount.toString());
|
||||||
|
console.log(turnCount);
|
||||||
|
}
|
||||||
function toggleDemoOn() {
|
function toggleDemoOn() {
|
||||||
prevBoard = convertToBoard();
|
prevBoard = convertToBoard();
|
||||||
if (!toggled) {
|
if (!toggled) {
|
||||||
|
@ -164,6 +169,7 @@ function doDemoMove() {
|
||||||
let isFinished = isGameDone(tmp);
|
let isFinished = isGameDone(tmp);
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
prevBoard = init_board;
|
prevBoard = init_board;
|
||||||
|
turnCount = 1;
|
||||||
}
|
}
|
||||||
var doDemoMove;
|
var doDemoMove;
|
||||||
if ($("#doPubevalDemo").is(':checked')) {
|
if ($("#doPubevalDemo").is(':checked')) {
|
||||||
|
@ -172,9 +178,12 @@ function doDemoMove() {
|
||||||
else {
|
else {
|
||||||
doDemoMove = getNetworkMove;
|
doDemoMove = getNetworkMove;
|
||||||
}
|
}
|
||||||
|
handleRoll();
|
||||||
let res = doDemoMove(prevBoard, currentPlayer);
|
let res = doDemoMove(prevBoard, currentPlayer);
|
||||||
prevBoard = res.board;
|
prevBoard = res.board;
|
||||||
convertToPins(prevBoard);
|
convertToPins(prevBoard);
|
||||||
|
turnCount = turnCount + 1;
|
||||||
|
displayTurnCount();
|
||||||
currentPlayer = currentPlayer * -1;
|
currentPlayer = currentPlayer * -1;
|
||||||
}
|
}
|
||||||
function handleMove(previousBoard, board, roll, totalRoll, quad) {
|
function handleMove(previousBoard, board, roll, totalRoll, quad) {
|
||||||
|
@ -235,7 +244,7 @@ function convertToPins(board) {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
function getNetworkMove(board, player) {
|
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: [] };
|
let result = { board: [] };
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -252,7 +261,7 @@ function getNetworkMove(board, player) {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
function getPubevalMove(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: [] };
|
let result = { board: [] };
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -292,14 +301,7 @@ function noMovesAvailable() {
|
||||||
prevBoard = res.board;
|
prevBoard = res.board;
|
||||||
console.log(prevBoard);
|
console.log(prevBoard);
|
||||||
convertToPins(prevBoard);
|
convertToPins(prevBoard);
|
||||||
var roll = [Math.floor(Math.random() * 6) + 1, Math.floor(Math.random() * 6) + 1];
|
handleRoll();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
function postRequest(previousBoard, board, roll, totalRoll, quad) {
|
function postRequest(previousBoard, board, roll, totalRoll, quad) {
|
||||||
let result = { board: [], totalRoll: 0, roll: [] };
|
let result = { board: [], totalRoll: 0, roll: [] };
|
||||||
|
|
|
@ -6,6 +6,7 @@ var totalRoll = 0;
|
||||||
var quad = false;
|
var quad = false;
|
||||||
var prevBoard = []
|
var prevBoard = []
|
||||||
var pubeval = false;
|
var pubeval = false;
|
||||||
|
var turnCount = 1;
|
||||||
var currentPlayer = 1;
|
var currentPlayer = 1;
|
||||||
var toggled: boolean = false;
|
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];
|
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);
|
convertToPins(init_board);
|
||||||
prevBoard = convertToBoard();
|
// prevBoard = convertToBoard();
|
||||||
let initBotResult = getBotMove(init_board);
|
// let initBotResult = getBotMove(init_board);
|
||||||
prevBoard = initBotResult.board;
|
// prevBoard = initBotResult.board;
|
||||||
convertToPins(prevBoard);
|
// convertToPins(prevBoard);
|
||||||
|
|
||||||
prevBoard = convertToBoard();
|
prevBoard = convertToBoard();
|
||||||
|
|
||||||
|
@ -120,6 +121,7 @@ $(function () {
|
||||||
cloned_board[toIdx] *= -1
|
cloned_board[toIdx] *= -1
|
||||||
// Load the board into the pins
|
// Load the board into the pins
|
||||||
convertToPins(cloned_board);
|
convertToPins(cloned_board);
|
||||||
|
board = cloned_board;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +173,12 @@ function handleRoll() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function displayTurnCount() {
|
||||||
|
// $("#turnCount").text(turnCount.toString());
|
||||||
|
console.log(turnCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function toggleDemoOn() {
|
function toggleDemoOn() {
|
||||||
prevBoard = convertToBoard();
|
prevBoard = convertToBoard();
|
||||||
|
|
||||||
|
@ -215,6 +223,7 @@ function doDemoMove() {
|
||||||
let isFinished = isGameDone(tmp);
|
let isFinished = isGameDone(tmp);
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
prevBoard = init_board;
|
prevBoard = init_board;
|
||||||
|
turnCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var doDemoMove;
|
var doDemoMove;
|
||||||
|
@ -224,10 +233,14 @@ function doDemoMove() {
|
||||||
} else {
|
} else {
|
||||||
doDemoMove = getNetworkMove;
|
doDemoMove = getNetworkMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleRoll();
|
||||||
|
|
||||||
let res = doDemoMove(prevBoard, currentPlayer);
|
let res = doDemoMove(prevBoard, currentPlayer);
|
||||||
prevBoard = res.board;
|
prevBoard = res.board;
|
||||||
convertToPins(prevBoard);
|
convertToPins(prevBoard);
|
||||||
|
turnCount = turnCount + 1;
|
||||||
|
displayTurnCount();
|
||||||
currentPlayer = currentPlayer * -1;
|
currentPlayer = currentPlayer * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +316,7 @@ interface botMove {
|
||||||
|
|
||||||
function getNetworkMove(board, player): 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: []}
|
let result : botMove = {board: []}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -323,7 +336,7 @@ function getNetworkMove(board, player): botMove {
|
||||||
|
|
||||||
function getPubevalMove(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: []}
|
let result : botMove = {board: []}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -368,17 +381,8 @@ function noMovesAvailable() {
|
||||||
prevBoard = res.board;
|
prevBoard = res.board;
|
||||||
console.log(prevBoard);
|
console.log(prevBoard);
|
||||||
convertToPins(prevBoard);
|
convertToPins(prevBoard);
|
||||||
|
|
||||||
var roll = [Math.floor(Math.random() * 6)+1, Math.floor(Math.random() * 6)+1]
|
|
||||||
|
|
||||||
if (roll[0] == roll[1]) {
|
handleRoll();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user