From bd64b375385f99e50ac917d2d50fab99d21c3e40 Mon Sep 17 00:00:00 2001 From: Frederico Jordan Date: Sat, 28 Jan 2017 01:01:00 -0200 Subject: [PATCH] Minor refactoring --- src/fast-chess.c | 61 +++++++++++++++--------------------------------- src/fast-chess.h | 2 +- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/fast-chess.c b/src/fast-chess.c index 534eb3b..7f1bc3d 100644 --- a/src/fast-chess.c +++ b/src/fast-chess.c @@ -1933,7 +1933,7 @@ Node quiescenceSearch(Position * position) { return (Node) { .move = bestMove, .score = bestScore }; } -Node alphaBeta(Position * position, char depth, int alpha, int beta, BOOL verbose) { +Node alphaBeta(Position * position, char depth, int alpha, int beta) { if (hasGameEnded(position)) return (Node) { .score = endNodeEvaluation(position) }; @@ -1948,7 +1948,6 @@ Node alphaBeta(Position * position, char depth, int alpha, int beta, BOOL verbos Move bestMove = 0; Move moves[MAX_BRANCHING_FACTOR]; -// int moveCount = legalMoves(moves, position, position->toMove); int moveCount = staticOrderLegalMoves(moves, position, position->toMove); Position newPosition; @@ -1956,40 +1955,22 @@ Node alphaBeta(Position * position, char depth, int alpha, int beta, BOOL verbos for (i=0; itoMove)) { return (Node) { .move = moves[i], .score = score }; } - if (position->toMove == WHITE) { - if (score > alpha) { - alpha = score; - bestMove = moves[i]; - if (alpha > beta) { - break; - } - } - } else if (position->toMove == BLACK) { - if (score < beta) { - beta = score; - bestMove = moves[i]; - if (alpha > beta) { - break; - } - } + if (position->toMove == WHITE && score > alpha) { + alpha = score; + bestMove = moves[i]; + } else if (position->toMove == BLACK && score < beta) { + beta = score; + bestMove = moves[i]; + } + + if (alpha > beta) { + break; } } @@ -2007,7 +1988,7 @@ int alphaBetaNodes(Node * sortedNodes, Position * position, char depth) { updatePosition(&newPosition, position, moves[i]); nodes[i].move = moves[i]; - nodes[i].score = depth>1?alphaBeta(&newPosition, depth-1, INT32_MIN, INT32_MAX, FALSE).score:staticEvaluation(&newPosition); + nodes[i].score = depth>1?alphaBeta(&newPosition, depth-1, INT32_MIN, INT32_MAX).score:staticEvaluation(&newPosition); } sortNodes(sortedNodes, nodes, moveCount, position->toMove); @@ -2108,16 +2089,12 @@ Node pIDAB(Position * position, char depth, int * p_alpha, int * p_beta) { return (Node) { .move = nodes[i].move, .score = score }; } - if (position->toMove == WHITE) { - if (score > alpha) { - alpha = score; - bestMove = nodes[i].move; - } - } else if (position->toMove == BLACK) { - if (score < beta) { - beta = score; - bestMove = nodes[i].move; - } + if (position->toMove == WHITE && score > alpha) { + alpha = score; + bestMove = nodes[i].move; + } else if (position->toMove == BLACK && score < beta) { + beta = score; + bestMove = nodes[i].move; } if (alpha > beta || alpha > *p_beta || *p_alpha > beta) { diff --git a/src/fast-chess.h b/src/fast-chess.h index 5a382dd..bfc3672 100644 --- a/src/fast-chess.h +++ b/src/fast-chess.h @@ -316,7 +316,7 @@ int quiescenceEvaluation(Position * position); Node staticSearch(Position * position); Node quiescenceSearch(Position * position); -Node alphaBeta(Position * position, char depth, int alpha, int beta, BOOL verbose); +Node alphaBeta(Position * position, char depth, int alpha, int beta); int alphaBetaNodes(Node * nodes, Position * position, char depth); Node iterativeDeepeningAlphaBeta(Position * position, char depth, int alpha, int beta, BOOL verbose); Node pIDAB(Position * position, char depth, int * p_alpha, int * p_beta);