Moves valid_moves() const { int i = space_index(); int row = i / 4; int col = i % 4; Moves cand; if (row != 0) cand.push_back('U'); if (row != 3) cand.push_back('D'); if (col != 0) cand.push_back('L'); if (col != 3) cand.push_back('R'); return cand; }
Moves MoveGenerator::generateOpening(const Board& board) const { Moves result; if(board.getIdleCount() == 0) { QMessageBox::critical(0, "error", "idle == 0"); return result; } for(int i=0; i<23; ++i) { if(board.isEmpty(i)) { Board next = board.makeChild(); // a clone next.setManAt(i, board.getSelfColor()); if(next.closeMill(i)) { Moves removeMoves = generateRemove(next, board.getOpponentColor()); // remove 1 opponent chessman copy(removeMoves.begin(), removeMoves.end(), back_inserter(result)); } else result.push_back(next); } } return result; }
const ConnectThree::Move ConnectThree::CheckTwoOther(const std::bitset<3>& is_player_human) const { const Moves moves(GetAllPossibleMoves()); const int nMoves = moves.size(); if (nMoves==0) return CreateInvalidMove(); { //Get anti-human moves Moves v; BOOST_FOREACH(const Move& m, moves) { assert(CanDoMove(m)); //Player is human if (is_player_human[boost::tuples::get<2>(m)]) v.push_back(m); } //If there are anti-player moves, choose one at random if (!v.empty()) { const Move m = v[std::rand() % v.size()]; assert(CanDoMove(m)); return boost::tuples::make_tuple( boost::tuples::get<0>(m), boost::tuples::get<1>(m), boost::tuples::get<2>(m)); } }
Moves BoardC4::get_possible_moves(Token player) const { Moves moves; for (Size column=0; column<width; column++) { if (tokens[column]<=token_for_columns[column]) moves.push_back(new MoveC4(player,column)); } return moves; }
/*-----------------------------------------------------------------------------*/ void MoveKif::AddBranch(Moves* parent, const MoveKif& move) { this->branches_.emplace_back(new Moves()); Moves* moves = this->branches_.back().get(); moves->set_parent(parent); moves->push_back(move); }
void build_path(ull_t v, const Searched & searched, Moves & steps) { Searched::const_iterator it = searched.find(v); while (it != searched.end()) { const State & s = it->second; steps.push_back(s.step); it = searched.find(s.parent); } //pop up the first step, which must be 0, rather than one of U,D,L,R steps.pop_back(); reverse(steps.begin(), steps.end()); }
Moves MoveGenerator::generateRemove(const Board& old, QChar color) const { Moves result; for(int i=0; i<23; ++i) { if(old.getManAt(i) == color) { if(!old.closeMill(i)) { // DO NOT use old.makeChild // next is a semi-finished product of a move Board next = old; next.setManAt(i, 'x'); result.push_back(next); } } } if(result.empty()) // no possible remove result.push_back(old); return result; }
Moves MoveGenerator::generateHopping(const Board& board) const { Moves result; for(int from=0; from<23; ++from) if(board.getManAt(from) == board.getSelfColor()) { for(int to=0; to<23; ++to) if(board.isEmpty(to)) { Board next = board.makeChild(); next.move(from, to); if(next.closeMill(to)) { Moves removeMoves = generateRemove(next, board.getOpponentColor()); copy(removeMoves.begin(), removeMoves.end(), back_inserter(result)); } else result.push_back(next); } } return result; }
Moves MoveGenerator::generateMove(const Board& board) const { Moves result; for(int from=0; from<23; ++from) if(board.getManAt(from) == board.getSelfColor()) { Neighbors neighbors = Board::getNeighbors(from); for(Neighbors::iterator it = neighbors.begin(); it != neighbors.end(); ++it) if(board.isEmpty(*it)) { Board next = board.makeChild(); next.move(from, *it); if(next.closeMill(*it)) { Moves removeMoves = generateRemove(next, board.getOpponentColor()); copy(removeMoves.begin(), removeMoves.end(), back_inserter(result)); } else result.push_back(next); } } return result; }