| View previous topic :: View next topic |
| Author |
Message |
Folkert van Heusden

Joined: 14 Mar 2008 Posts: 67 Location: Gouda, the Netherlands
|
Post subject: broken? Posted: Sun Jul 08, 2012 5:01 pm |
|
|
Hi,
As you people might have noticed, I've been working on my chess engine.
It'll become the original POS in a deep (multithreaded) brute force way.
First step is implementing a brute-force thingy, then bolting on the evaluator of the original pos. That last step won't be too difficult, but this brute force alpha/beta code; something is wrong with it.
I googled a little and it seems all implementations are different. Not just naming of variables and such, but how they work too. For example the implementation on wikipedia (english) seems to totally wrong.
So maybe you people could take a look at my code and tell me what is wrong?
| Code: |
int alphaBeta(final Scene scene, final PlayerColor side, final PlayerColor rootSide, final double finishBefore, int depth, final int maxExtension, final IO io, int alpha, int beta) throws IOException {
// keep track of the number of processed nodes
nodeCount.addAndGet(1);
final PlayerColor otherSide = Statics.opponentColor(side);
if (depth <= 0) {
// if the bottom of the tree is check, search a little deeper
if (depth > maxExtension && scene.isKingUnderAttack(side, otherSide) && !scene.isCheckMate(side)) {
// if check then extend the searchdepth
// by entering this if, the 'depth--' is not invoked and also the next 'depth == 0' is not triggered
//io.progressCallback("Search depth extension due to check " + depth);
long now = System.currentTimeMillis();
if (now - prev.get() > 5000) { // emit output after 5s
double took = Statics.getTimestamp() - startTs;
io.progressCallbackDepthReached(maxDepth - depth);
prev.set(now);
}
}
else {
return getShannonValue(scene, side); // score
}
}
depth--;
final List<Move> moves = scene.getMoveList(side);
int movesListSize = moves.size();
totalNMoves.addAndGet(movesListSize);
totalNodes.addAndGet(1);
for(int index=0; index<movesListSize; index++) {
// "do a move", 'afterMove' is the "situation" after 'currentMove' was executed
Scene afterMove = null;
final Move currentMove = moves.get(index);
try {
afterMove = currentMove.getScene();
if (afterMove == null)
afterMove = scene.Move(currentMove);
else
currentMove.setScene(null); // help GC, link is not required
afterMove.validateMoves(otherSide);
}
catch(Exception e) {
System.out.println(" side: " + side + " alpha " + alpha + " beta " + beta);
System.out.println(" " + (depth + 1) + " " + currentMove);
Statics.displayBoard(afterMove.getBoard());
System.out.println("" + e);
e.printStackTrace();
System.exit(1);
}
final int score = alphaBeta(afterMove, otherSide, rootSide, finishBefore, depth, maxExtension, io, alpha, beta);
if (score == -Integer.MAX_VALUE || score == Integer.MAX_VALUE)
continue;
afterMove.shrink();
if (side == rootSide) { // MAX
if (score >= beta)
return beta;
if (score > alpha)
alpha = score;
}
else { // opposite side: MIN
if (score <= alpha)
return alpha;
if (score < beta)
beta = score;
}
double nowTs = Statics.getTimestamp();
if (finishBefore > 0 && finishBefore <= nowTs) {
io.progressCallback("Abort search due to time limit");
break;
}
}
if (side == rootSide)
return alpha;
return beta;
} |
_________________ http://www.vanheusden.com/pos/ - takes 'experimental' to a whole new level |
|
| Back to top |
|
 |
|
| Subject |
Author |
Date/Time |
broken? |
Folkert van Heusden |
Sun Jul 08, 2012 5:01 pm |
Re: broken? |
Tim Kosse |
Sun Jul 08, 2012 5:43 pm |
Re: broken? |
Folkert van Heusden |
Sun Jul 08, 2012 6:13 pm |
Re: broken? |
Zong Li |
Sun Jul 08, 2012 5:47 pm |
Re: broken? |
Folkert van Heusden |
Sun Jul 08, 2012 6:15 pm |
Re: broken? |
Zong Li |
Sun Jul 08, 2012 6:37 pm |
Re: broken? |
Folkert van Heusden |
Sun Jul 08, 2012 6:53 pm |
Re: broken? |
Tim Kosse |
Sun Jul 08, 2012 7:04 pm |
Re: broken? |
Folkert van Heusden |
Sun Jul 08, 2012 7:35 pm |
Re: broken? |
Sven Schüle |
Sun Jul 08, 2012 9:15 pm |
Re: broken? |
Balint Pfliegel |
Sun Jul 08, 2012 9:56 pm |
Re: broken? |
Zong Li |
Sun Jul 08, 2012 11:31 pm |
Re: broken? |
Sven Schüle |
Sun Jul 08, 2012 11:25 pm |
Re: broken? |
Zong Li |
Sun Jul 08, 2012 7:35 pm |
Re: broken? |
Sven Schüle |
Sun Jul 08, 2012 6:01 pm |
Re: broken? |
Folkert van Heusden |
Sun Jul 08, 2012 6:25 pm |
Re: broken? |
Aart Bik |
Sun Jul 08, 2012 10:22 pm |
Re: broken? |
Balint Pfliegel |
Sun Jul 08, 2012 10:40 pm |
Re: broken? |
Adam Hair |
Mon Jul 09, 2012 12:22 am |
Re: broken? |
Aart Bik |
Mon Jul 09, 2012 12:37 am |
Re: broken? |
Aart Bik |
Mon Jul 09, 2012 12:57 am |
Re: broken? |
Balint Pfliegel |
Mon Jul 09, 2012 5:47 am |
Re: broken? |
Aart Bik |
Mon Jul 09, 2012 4:45 pm |
Re: broken? |
Folkert van Heusden |
Mon Jul 09, 2012 6:35 pm |
Re: broken? |
Zong Li |
Mon Jul 09, 2012 6:49 pm |
Re: broken? |
Folkert van Heusden |
Mon Jul 09, 2012 7:17 pm |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|