/usr/include/osl/game_playing/speculativeAllMoves.h is in libosl-dev 0.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /* speculativeAllMoves.h
*/
#ifndef OSL_SPECULATIVEALLMOVES_H
#define OSL_SPECULATIVEALLMOVES_H
#include "osl/game_playing/computerPlayer.h"
#include "osl/game_playing/speculativeModel.h"
#include "osl/misc/lightMutex.h"
#include "osl/misc/fixedCapacityVector.h"
#include "osl/misc/milliSeconds.h"
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
namespace osl
{
namespace misc
{
class RealTime;
}
namespace search
{
struct TimeAssigned;
}
namespace game_playing
{
class SearchPlayer;
/**
* 1threadで全ての手を順番に投機的探索をする
*/
class SpeculativeAllMoves : public SpeculativeModel
{
public:
class SearchAllMoves;
class ResultVector;
private:
boost::shared_ptr<SearchAllMoves> searcher;
boost::scoped_ptr<boost::thread> thread;
boost::scoped_ptr<ResultVector> results;
boost::mutex mutex;
int last_search_seconds;
bool has_byoyomi;
bool allowed;
HashKey search_state;
public:
SpeculativeAllMoves();
~SpeculativeAllMoves();
void startSpeculative(const boost::shared_ptr<GameState> state,
const SearchPlayer& main_player);
void stopOtherThan(Move);
void stopAll();
void setMaxThreads(int new_max_threads)
{
boost::mutex::scoped_lock lk(mutex);
allowed = (new_max_threads > 0);
}
const MoveWithComment waitResult(Move last_move, search::TimeAssigned wait_for,
SearchPlayer& main_player, int byoyomi);
void selectBestMoveCleanUp();
void clearResource();
const HashKey searchState() const { return search_state; }
private:
struct Runner;
};
class SpeculativeAllMoves::ResultVector
{
typedef FixedCapacityVector<std::pair<Move,MoveWithComment>,Move::MaxUniqMoves> vector_t;
vector_t data;
typedef LightMutex Mutex;
mutable Mutex mutex;
public:
ResultVector();
~ResultVector();
void add(Move prediction, const MoveWithComment& result);
const MoveWithComment* find(Move prediction) const;
void clear();
void show(std::ostream&) const;
};
/**
* 指手を生成し,結果をresultsにためる.
* run を別threadで動かすことを想定しているが,逐次でもテスト可
*/
class SpeculativeAllMoves::SearchAllMoves
{
public:
enum Status {
INITIAL, RUNNING, PREDICTION1, PREDICTION2, SEARCH1, SEARCH2, FINISHED
};
struct Generator;
friend struct Generator;
friend class SpeculativeAllMoves;
private:
boost::shared_ptr<GameState> state;
boost::shared_ptr<SearchPlayer> player;
boost::scoped_ptr<Generator> generator;
SpeculativeAllMoves::ResultVector& results;
double next_iteration_coefficient;
Move current_move;
volatile Status status;
int seconds;
typedef boost::mutex Mutex;
mutable Mutex mutex;
boost::condition condition;
/** true なら次の予想探索にはいらない */
volatile bool stop_flag;
public:
explicit SearchAllMoves(SpeculativeAllMoves::ResultVector&);
~SearchAllMoves();
void setUp(const GameState&, const SearchPlayer&, int standard_seconds,
bool has_byoyomi);
void run();
void stopNow();
void stopOtherThan(Move);
void waitRunning();
bool isFinished() const { return status == FINISHED; }
void setTimeAssign(const search::TimeAssigned&);
const MilliSeconds startTime();
const Move currentMove() const;
SearchPlayer* currentPlayer() { return player.get(); }
private:
const MoveWithComment testMove(Move);
struct StatusLock;
};
} // game_playing
} // osl
#endif /* OSL_SPECULATIVEALLMOVES_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|