Skip to content

Commit

Permalink
Fix VCF movegen of Renju rule
Browse files Browse the repository at this point in the history
This patch fixes vcf movegen bug of Renju rule, when a vcf move is judged as forbidden point, but a false one.

bench fc476890
bench (msvc) b6100afc
  • Loading branch information
dhbloo committed Sep 24, 2023
1 parent 368bd96 commit 3029db3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 12 additions & 3 deletions Rapfi/game/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/

#include "movegen.h"

Expand All @@ -30,9 +30,10 @@ constexpr int MaxFindDist = 4;

/// Filter move by Pattern4 according to GenType.
template <GenType Type>
constexpr bool basicPatternFilter(const Board &board, Pos pos, Color side)
inline bool basicPatternFilter(const Board &board, Pos pos, Color side)
{
Pattern4 p4 = board.cell(pos).pattern4[side];
const Cell &c = board.cell(pos);
Pattern4 p4 = c.pattern4[side];

if (bool(Type & WINNING)) {
if (p4 >= B_FLEX4)
Expand All @@ -44,6 +45,13 @@ constexpr bool basicPatternFilter(const Board &board, Pos pos, Color side)
if (p4 >= D_BLOCK4_PLUS)
return true;
}
else if constexpr (bool(Type & RULE_RENJU)) {
if (p4 >= E_BLOCK4
|| p4 == FORBID
&& (c.pattern(side, 0) >= B4 || c.pattern(side, 1) >= B4
|| c.pattern(side, 2) >= B4 || c.pattern(side, 3) >= B4))
return true;
}
else {
if (p4 >= E_BLOCK4)
return true;
Expand Down Expand Up @@ -617,6 +625,7 @@ Move *generate(const Board &board, Move *moveList)
}

template Move *generate<VCF>(const Board &, Move *);
template Move *generate<VCF | RULE_RENJU>(const Board &, Move *);
template Move *generate<ALL>(const Board &, Move *);

template <GenType Type>
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/search/ab/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ constexpr Depth reduction(const std::array<Depth, MAX_MOVES + 1> (&lut)[RULE_NB]
Value rootDelta)
{
assert(d > 0.0f);
assert(moveCount > 0 && moveCount < lut.size());
assert(moveCount > 0 && moveCount < lut[R].size());
Depth r = lut[R][(int)d] * lut[R][moveCount];
if constexpr (PvNode)
return std::max(r - Depth(delta) / Depth(rootDelta), 0.0f);
Expand Down
10 changes: 5 additions & 5 deletions Rapfi/search/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ MovePicker::MovePicker(Rule rule, const Board &board, ExtraArgs<MovePicker::ROOT
endMove = generate<WINNING>(board, curMove);
else if (board.p4Count(oppo, B_FLEX4)) {
endMove = generate<DEFEND_FOUR | ALL>(board, curMove);
endMove = generate<VCF>(board, endMove);
endMove = (rule == RENJU ? generate<VCF | RULE_RENJU> : generate<VCF>)(board, endMove);
}
else if (board.p4Count(oppo, C_BLOCK4_FLEX3)
&& (rule != Rule::RENJU || validateOpponentCMove(board))) {
Expand All @@ -113,7 +113,7 @@ MovePicker::MovePicker(Rule rule, const Board &board, ExtraArgs<MovePicker::ROOT
if (endMove == curMove)
endMove = generate<ALL>(board, curMove);
else
endMove = generate<VCF>(board, endMove);
endMove = (rule == RENJU ? generate<VCF | RULE_RENJU> : generate<VCF>)(board, endMove);
}
else
endMove = generate<ALL>(board, curMove);
Expand Down Expand Up @@ -203,7 +203,7 @@ Pos MovePicker::pickNextMove(Pred filter)
if constexpr (T == Best)
std::swap(*curMove, *std::max_element(curMove, endMove));

if (curMove->pos != ttMove && (!forbidden || !board.checkForbiddenPoint(*curMove))
if (curMove->pos != ttMove && (!forbidden || !board.checkForbiddenPoint(curMove->pos))
&& filter()) {
curScore = curMove->score;
curPolicyScore = curMove->rawScore;
Expand Down Expand Up @@ -318,7 +318,7 @@ Pos MovePicker::operator()()

curMove = moves;
endMove = generate<DEFEND_FOUR>(board, curMove);
endMove = generate<VCF>(board, endMove);
endMove = (rule == RENJU ? generate<VCF | RULE_RENJU> : generate<VCF>)(board, endMove);

scoreMoves<ScoreType(BALANCED | POLICY | MAIN_HISTORY)>();
fastPartialSort(curMove, endMove, 0);
Expand All @@ -342,7 +342,7 @@ Pos MovePicker::operator()()
goto top;
}

endMove = generate<VCF>(board, endMove);
endMove = (rule == RENJU ? generate<VCF | RULE_RENJU> : generate<VCF>)(board, endMove);

scoreMoves<ScoreType(BALANCED | POLICY | MAIN_HISTORY)>();
fastPartialSort(curMove, endMove, 0);
Expand Down

0 comments on commit 3029db3

Please sign in to comment.