2017-04-04 23:55:50 +02:00
|
|
|
var Jocly = require("../../dist/node");
|
2017-03-29 17:30:37 +02:00
|
|
|
|
|
|
|
var moveCount = 0;
|
|
|
|
|
2017-04-04 23:55:50 +02:00
|
|
|
function RunMatch(match) {
|
|
|
|
function NextMove() {
|
|
|
|
var move;
|
|
|
|
match.machineSearch()
|
|
|
|
.then( (result) => {
|
|
|
|
move = result.move;
|
|
|
|
return match.getMoveString(move);
|
|
|
|
})
|
|
|
|
.then( (moveStr) => {
|
|
|
|
console.info(
|
|
|
|
((!(moveCount%2) && ((moveCount>>1)+1)+". ") || "")
|
|
|
|
+(moveCount%2 && " " || "")+" "+moveStr
|
|
|
|
);
|
|
|
|
moveCount++;
|
|
|
|
})
|
|
|
|
.then( () => {
|
|
|
|
return match.applyMove(move);
|
|
|
|
})
|
|
|
|
.then( (result) => {
|
|
|
|
if(result.finished) {
|
|
|
|
if(result.winner==Jocly.PLAYER_A)
|
|
|
|
console.info("Player A wins");
|
|
|
|
else if(result.winner==Jocly.PLAYER_B)
|
|
|
|
console.info("Player B wins");
|
|
|
|
else if(result.winner==Jocly.DRAW)
|
|
|
|
console.info("Draw");
|
|
|
|
} else
|
|
|
|
NextMove();
|
|
|
|
})
|
|
|
|
.catch( (e) => {
|
|
|
|
console.info("Error",e);
|
|
|
|
})
|
2017-03-29 17:30:37 +02:00
|
|
|
|
|
|
|
}
|
2017-04-04 23:55:50 +02:00
|
|
|
NextMove();
|
2017-03-29 17:30:37 +02:00
|
|
|
}
|
|
|
|
|
2017-04-04 23:55:50 +02:00
|
|
|
|
|
|
|
Jocly.createMatch("classic-chess")
|
|
|
|
.then((match)=>{
|
|
|
|
RunMatch(match);
|
2017-03-29 17:30:37 +02:00
|
|
|
})
|
|
|
|
.catch((e)=>{
|
2017-04-04 23:55:50 +02:00
|
|
|
console.info("Error creating match",e);
|
|
|
|
});
|
2017-03-29 17:30:37 +02:00
|
|
|
|