Skip to content

Commit

Permalink
Removed distinction between Search and MateSearch. Eliminated jquery …
Browse files Browse the repository at this point in the history
…fossil.
  • Loading branch information
cosinekitty committed Jun 30, 2016
1 parent feb577a commit b580d15
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3,237 deletions.
3,174 changes: 0 additions & 3,174 deletions demo/jquery.d.ts

This file was deleted.

3 changes: 1 addition & 2 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
],
"files": [
"../src/flywheel.ts",
"./fwui.ts",
"./jquery.d.ts"
"./fwui.ts"
],
"atom": {
"rewriteTsconfig": true
Expand Down
35 changes: 5 additions & 30 deletions src/flywheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ var Flywheel;
for (var limit = 1; searching; ++limit) {
try {
var nextBestPath = new BestPath();
nextBestPath.score = this.InternalMateSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
nextBestPath.score = this.InternalSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
bestPath = nextBestPath; // search was not yet aborted via exception, so update best path
if (bestPath.score >= Score.ForcedWin) {
break;
Expand All @@ -2025,32 +2025,7 @@ var Flywheel;
bestPath.nodes = this.nodesVisitedCounter;
return bestPath;
};
Thinker.prototype.MateSearch = function (board) {
// Search for a forced checkmate.
var bestPath = null;
var searching = true;
for (var limit = 1; searching; ++limit) {
try {
var nextBestPath = new BestPath();
nextBestPath.score = this.InternalMateSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
bestPath = nextBestPath; // search was not yet aborted via exception, so update best path
if (bestPath.score >= Score.ForcedWin) {
break;
}
}
catch (ex) {
if (ex instanceof SearchAbortedException) {
searching = false; // This is not an error; it is the normal way a search is terminated.
}
else {
throw ex; // This really is an error, so bubble the exception up!
}
}
}
bestPath.nodes = this.nodesVisitedCounter;
return bestPath;
};
Thinker.MateSearchMoveRater = function (board, move) {
Thinker.MoveRater = function (board, move) {
if (board.IsCurrentPlayerInCheck()) {
if (!board.CurrentPlayerCanMove()) {
// Put moves that cause checkmate to the very front.
Expand All @@ -2061,7 +2036,7 @@ var Flywheel;
}
return 0;
};
Thinker.prototype.InternalMateSearch = function (board, limit, depth, bestPath, alpha, beta) {
Thinker.prototype.InternalSearch = function (board, limit, depth, bestPath, alpha, beta) {
this.CheckSearchAborted(limit);
++this.nodesVisitedCounter;
bestPath.Truncate();
Expand All @@ -2073,7 +2048,7 @@ var Flywheel;
}
return Score.Draw;
}
var legal = board.LegalMoves(Thinker.MateSearchMoveRater);
var legal = board.LegalMoves(Thinker.MoveRater);
if (legal.length === 0) {
// Either checkmate or stalemate, depending on whether the current player is in check.
// Postponement adjustment:
Expand All @@ -2096,7 +2071,7 @@ var Flywheel;
board.PushMove(move);
// Tricky: we negate the return value, flip and negate the alpha-beta window.
// This is a "negamax" search -- whatever is good for one player is bad for the other.
var score = -this.InternalMateSearch(board, limit, 1 + depth, currPath, -beta, -alpha);
var score = -this.InternalSearch(board, limit, 1 + depth, currPath, -beta, -alpha);
board.PopMove();
if (score > bestScore) {
bestScore = score;
Expand Down
34 changes: 5 additions & 29 deletions src/flywheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ module Flywheel {
for (var limit=1; searching; ++limit) {
try {
var nextBestPath:BestPath = new BestPath();
nextBestPath.score = this.InternalMateSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
nextBestPath.score = this.InternalSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
bestPath = nextBestPath; // search was not yet aborted via exception, so update best path
if (bestPath.score >= Score.ForcedWin) {
break;
Expand All @@ -2123,31 +2123,7 @@ module Flywheel {
return bestPath;
}

public MateSearch(board:Board): BestPath {
// Search for a forced checkmate.
var bestPath:BestPath = null;
var searching = true;
for (var limit=1; searching; ++limit) {
try {
var nextBestPath:BestPath = new BestPath();
nextBestPath.score = this.InternalMateSearch(board, limit, 0, nextBestPath, Score.NegInf, Score.PosInf);
bestPath = nextBestPath; // search was not yet aborted via exception, so update best path
if (bestPath.score >= Score.ForcedWin) {
break;
}
} catch (ex) {
if (ex instanceof SearchAbortedException) {
searching = false; // This is not an error; it is the normal way a search is terminated.
} else {
throw ex; // This really is an error, so bubble the exception up!
}
}
}
bestPath.nodes = this.nodesVisitedCounter;
return bestPath;
}

private static MateSearchMoveRater(board:Board, move:Move):Score {
private static MoveRater(board:Board, move:Move):Score {
if (board.IsCurrentPlayerInCheck()) {
if (!board.CurrentPlayerCanMove()) {
// Put moves that cause checkmate to the very front.
Expand All @@ -2159,7 +2135,7 @@ module Flywheel {
return 0;
}

private InternalMateSearch(
private InternalSearch(
board:Board,
limit:number,
depth:number,
Expand All @@ -2182,7 +2158,7 @@ module Flywheel {
return Score.Draw;
}

let legal:Move[] = board.LegalMoves(Thinker.MateSearchMoveRater);
let legal:Move[] = board.LegalMoves(Thinker.MoveRater);
if (legal.length === 0) {
// Either checkmate or stalemate, depending on whether the current player is in check.
// Postponement adjustment:
Expand All @@ -2207,7 +2183,7 @@ module Flywheel {
board.PushMove(move);
// Tricky: we negate the return value, flip and negate the alpha-beta window.
// This is a "negamax" search -- whatever is good for one player is bad for the other.
let score:Score = -this.InternalMateSearch(board, limit, 1+depth, currPath, -beta, -alpha);
let score:Score = -this.InternalSearch(board, limit, 1+depth, currPath, -beta, -alpha);
board.PopMove();

if (score > bestScore) {
Expand Down
2 changes: 1 addition & 1 deletion src/flyworker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/flyworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module FlyWorker {
board.PushHistory(data.game);
let thinker:Flywheel.Thinker = new Flywheel.Thinker();
thinker.SetMaxSearchLimit(data.limit);
let bestPath:Flywheel.BestPath = thinker.MateSearch(board);
let bestPath:Flywheel.BestPath = thinker.Search(board);
return Adapter.MakeSearchResponse(data, bestPath);
}

Expand Down

0 comments on commit b580d15

Please sign in to comment.