00001 /* bigramKillerMove.cc 00002 */ 00003 #include "osl/search/bigramKillerMove.h" 00004 #include <iostream> 00005 00006 osl::search:: 00007 BigramKillerMove::BigramKillerMove() 00008 { 00009 clear(); 00010 } 00011 00012 osl::search:: 00013 BigramKillerMove::~BigramKillerMove() 00014 { 00015 } 00016 00017 void osl::search:: 00018 BigramKillerMove::clear() 00019 { 00020 for (size_t i=0; i<killer_moves.capacity1(); ++i) 00021 for (size_t j=0; j<killer_moves.capacity2(); ++j) 00022 killer_moves[i][j].clear(); 00023 } 00024 00025 void osl::search:: 00026 BigramKillerMove::getMove(const NumEffectState& state, Move last_move, 00027 MoveVector& out) const 00028 { 00029 if (last_move.isInvalid()) 00030 return; 00031 const LRUMoves& moves = operator[](last_move); 00032 00033 for (size_t i=0; i<moves.size(); ++i) 00034 { 00035 Move bigram_move = moves[i]; 00036 if (bigram_move.isInvalid()) 00037 return; 00038 const Ptype ptype = bigram_move.oldPtype(); 00039 const Position from = bigram_move.from(); 00040 if ((! from.isPieceStand()) 00041 && (state.getPieceOnBoard(from).ptype() != ptype)) 00042 { 00043 if (! Ptype_Table.hasLongMove(ptype)) 00044 return; 00045 assert(isPiece(ptype)); 00046 const Position to = bigram_move.to(); 00047 const Player player = state.getTurn(); 00048 const PieceMask pieces 00049 = state.getOnBoardMask(player) & state.getEffect(to); 00050 // to Ʊptype н 00051 for (int i=Ptype_Table.getIndexMin(unpromote(ptype)); 00052 i<Ptype_Table.getIndexLimit(unpromote(ptype)); ++i) 00053 { 00054 if (pieces.test(i)) 00055 { 00056 const Piece moving = state.getPieceOf(i); 00057 assert(moving.owner() == player); 00058 if (moving.ptype() != ptype) 00059 continue; 00060 const Position new_from = moving.position(); 00061 const bool promote = (! isPromoted(ptype)) 00062 && (to.canPromote(player) || new_from.canPromote(player)); 00063 bigram_move = Move(new_from, to, 00064 (promote 00065 ? osl::promote(moving.ptype()) : moving.ptype()), 00066 bigram_move.capturePtype(), 00067 promote, player); 00068 assert(state.isValidMoveByRule(bigram_move,false)); 00069 break; 00070 } 00071 } 00072 } 00073 if (state.isAlmostValidMove<false>(bigram_move)) 00074 out.push_back(bigram_move); 00075 } 00076 } 00077 00078 void osl::search:: 00079 BigramKillerMove::dump() const 00080 { 00081 for (int y=1; y<=9; ++y) 00082 { 00083 for (int x=1; x<=9; ++x) 00084 { 00085 const Position position(x,y); 00086 for (int p=PTYPEO_MIN; p<=PTYPEO_MAX; ++p) 00087 { 00088 const PtypeO ptypeo = static_cast<PtypeO>(p); 00089 const LRUMoves& moves 00090 = killer_moves[position.index()][ptypeOIndex(ptypeo)]; 00091 if (moves[0].isNormal()) 00092 { 00093 std::cerr << position << " " << moves[0]; 00094 if (moves[1].isNormal()) 00095 std::cerr << " " << moves[1]; 00096 std::cerr << "\n"; 00097 } 00098 } 00099 } 00100 } 00101 } 00102 00103 /* ------------------------------------------------------------------------- */ 00104 // ;;; Local Variables: 00105 // ;;; mode:c++ 00106 // ;;; c-basic-offset:2 00107 // ;;; End: