Update ChessEngine.js

This commit is contained in:
Brad Stein 2018-08-30 00:34:17 -05:00 committed by GitHub
parent 2d4f4f9544
commit be01054d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,12 +8,12 @@ class ChessBot{
this.color = color; this.color = color;
} }
makeMove(game, board, source, target){ makeMove(game, board){
let nextMove = undefined; let nextMove = undefined;
if (this.difficulty === 'Random'){ if (this.difficulty === 'Random'){
nextMove = this.determineSimplestBotMove(game, source, target); nextMove = this.determineSimplestBotMove(game);
} else if (this.difficulty === 'Easy') { } else if (this.difficulty === 'Easy') {
nextMove = this.determineNextBestBotMoveOneMoveDeep(game, source, target); nextMove = this.determineNextBestBotMoveOneMoveDeep(game);
} else if (this.difficulty === 'Medium'){ } else if (this.difficulty === 'Medium'){
let depth = Math.floor(Math.random() * 1 + 2); let depth = Math.floor(Math.random() * 1 + 2);
console.clear(); console.clear();
@ -29,7 +29,7 @@ class ChessBot{
} }
} }
determineSimplestBotMove(game, source, target){ determineSimplestBotMove(game){
let possibleMoves = game.moves(); let possibleMoves = game.moves();
if (possibleMoves.length === 0) return; if (possibleMoves.length === 0) return;
@ -74,7 +74,7 @@ class ChessBot{
evaluateBoardForBlack(game){return -this.evaluateBoardForWhite(game);} evaluateBoardForBlack(game){return -this.evaluateBoardForWhite(game);}
determineNextBestBotMoveOneMoveDeep(game, source, target) { determineNextBestBotMoveOneMoveDeep(game) {
let bestMove = null; let bestMove = null;
let bestValue = -9999; let bestValue = -9999;
let boardValue = 0; let boardValue = 0;
@ -100,7 +100,7 @@ class ChessBot{
} }
if (bestValue === 0) { if (bestValue === 0) {
return this.determineSimplestBotMove(game, source, target); return this.determineSimplestBotMove(game);
} else { } else {
return bestMove; return bestMove;
} }
@ -122,7 +122,7 @@ class ChessBot{
} }
if (bestValue === 0) { if (bestValue === 0) {
return this.determineSimplestBotMove(game, source, target); return this.determineSimplestBotMove(game);
} else { } else {
return bestMove; return bestMove;
} }
@ -179,7 +179,7 @@ function setupChess(game, board, bot){
if (move === null) return 'snapback'; if (move === null) return 'snapback';
window.setTimeout(bot.makeMove(game, board, source, target), 250); window.setTimeout(bot.makeMove(game, board), 250);
}; };
let onSnapEnd = function() { let onSnapEnd = function() {