movegen: refator
This commit is contained in:
parent
75276915be
commit
216c9bfadb
|
@ -20,11 +20,8 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "option.h"
|
|
||||||
#include "types.h"
|
|
||||||
#include "search.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
#include "option.h"
|
||||||
|
|
||||||
void MoveList::create()
|
void MoveList::create()
|
||||||
{
|
{
|
||||||
|
@ -285,30 +282,24 @@ void MoveList::shuffle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// generate generates all the legal moves in the given position
|
||||||
|
|
||||||
/// generate<LEGAL> generates all the legal moves in the given position
|
ExtMove *generate(Position *position, ExtMove *moveList)
|
||||||
|
|
||||||
//template<>
|
|
||||||
ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
|
||||||
{
|
{
|
||||||
Square s;
|
Square s;
|
||||||
|
|
||||||
Color us = position->sideToMove;
|
Color us = position->side_to_move();
|
||||||
Color them = ~us;
|
Color them = ~us;
|
||||||
|
|
||||||
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
|
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
|
||||||
|
|
||||||
//moves.clear();
|
|
||||||
ExtMove *cur = moveList;
|
ExtMove *cur = moveList;
|
||||||
|
|
||||||
switch (position->action) {
|
switch (position->action) {
|
||||||
case ACTION_SELECT:
|
case ACTION_SELECT:
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
// 对于摆子阶段
|
if (position->phase & (PHASE_PLACING | PHASE_READY)) {
|
||||||
if (position->phase & (PHASE_PLACING | PHASE_READY)) {
|
for (auto s : MoveList::movePriorityTable) {
|
||||||
for (Square i : MoveList::movePriorityTable) {
|
|
||||||
s = i;
|
|
||||||
|
|
||||||
if (position->board[s]) {
|
if (position->board[s]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -317,14 +308,14 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
moves.push_back((Move)s);
|
moves.push_back((Move)s);
|
||||||
#else // MCTS_AI
|
#else // MCTS_AI
|
||||||
if (position->phase != PHASE_READY) {
|
if (position->phase != PHASE_READY) {
|
||||||
*cur++ = ((Move)s);
|
*cur++ = (Move)s;
|
||||||
} else {
|
} else {
|
||||||
#ifdef FIRST_MOVE_STAR_PREFERRED
|
#ifdef FIRST_MOVE_STAR_PREFERRED
|
||||||
if (Position::is_star_square(s)) {
|
if (Position::is_star_square(s)) {
|
||||||
moves.push_back((Move)s);
|
moves.push_back((Move)s);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
*cur++ = ((Move)s);
|
*cur++ = (Move)s;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif // MCTS_AI
|
#endif // MCTS_AI
|
||||||
|
@ -349,7 +340,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
newSquare = static_cast<Square>(MoveList::moveTable[oldSquare][direction]);
|
newSquare = static_cast<Square>(MoveList::moveTable[oldSquare][direction]);
|
||||||
if (newSquare && !position->board[newSquare]) {
|
if (newSquare && !position->board[newSquare]) {
|
||||||
Move m = make_move(oldSquare, newSquare);
|
Move m = make_move(oldSquare, newSquare);
|
||||||
*cur++ = ((Move)m);
|
*cur++ = (Move)m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -357,7 +348,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
for (newSquare = SQ_BEGIN; newSquare < SQ_END; newSquare = static_cast<Square>(newSquare + 1)) {
|
for (newSquare = SQ_BEGIN; newSquare < SQ_END; newSquare = static_cast<Square>(newSquare + 1)) {
|
||||||
if (!position->board[newSquare]) {
|
if (!position->board[newSquare]) {
|
||||||
Move m = make_move(oldSquare, newSquare);
|
Move m = make_move(oldSquare, newSquare);
|
||||||
*cur++ = ((Move)m);
|
*cur++ = (Move)m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,7 +361,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||||
s = MoveList::movePriorityTable[i];
|
s = MoveList::movePriorityTable[i];
|
||||||
if (position->board[s]& (them << PLAYER_SHIFT)) {
|
if (position->board[s]& (them << PLAYER_SHIFT)) {
|
||||||
*cur++ = ((Move)-s);
|
*cur++ = (Move)-s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -379,9 +370,9 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
// not is all in mills
|
// not is all in mills
|
||||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||||
s = MoveList::movePriorityTable[i];
|
s = MoveList::movePriorityTable[i];
|
||||||
if (position->board[s]& (them << PLAYER_SHIFT)) {
|
if (position->board[s] & (them << PLAYER_SHIFT)) {
|
||||||
if (rule.allowRemovePieceInMill || !position->in_how_many_mills(s, NOBODY)) {
|
if (rule.allowRemovePieceInMill || !position->in_how_many_mills(s, NOBODY)) {
|
||||||
*cur++ = ((Move)-s);
|
*cur++ = (Move)-s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,4 +385,3 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue