PlayAndSolve.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef PLAYANDSOLVE_H
00007 #define PLAYANDSOLVE_H
00008
00009 #include <boost/thread.hpp>
00010 #include <boost/thread/barrier.hpp>
00011 #include <boost/thread/mutex.hpp>
00012
00013 #include "BenzenePlayer.hpp"
00014 #include "DfpnCommands.hpp"
00015 #include "HexEnvironment.hpp"
00016 #include "HexHtpEngine.hpp"
00017 #include "HexState.hpp"
00018 #include "DfsSolver.hpp"
00019 #include "DfsCommands.hpp"
00020 #include "VCCommands.hpp"
00021
00022 _BEGIN_BENZENE_NAMESPACE_
00023
00024
00025
00026
00027 class PlayAndSolve
00028 {
00029 public:
00030 PlayAndSolve(HexBoard& playerBrd, HexBoard& solverBrd,
00031 BenzenePlayer& player, DfpnSolver& solver,
00032 DfpnStates& positions, const Game& game);
00033
00034 HexPoint GenMove(const HexState& state, double maxTime);
00035
00036 private:
00037 class PlayerThread
00038 {
00039 public:
00040 PlayerThread(PlayAndSolve& ps, boost::mutex& mutex,
00041 boost::barrier& barrier, const HexState& state,
00042 double maxTime)
00043 : m_ps(ps), m_mutex(mutex), m_barrier(barrier),
00044 m_state(state), m_maxTime(maxTime) {};
00045
00046 void operator()();
00047 private:
00048 PlayAndSolve& m_ps;
00049 boost::mutex& m_mutex;
00050 boost::barrier& m_barrier;
00051 const HexState& m_state;
00052 double m_maxTime;
00053 };
00054
00055 friend class SolverThread;
00056
00057 class SolverThread
00058 {
00059 public:
00060 SolverThread(PlayAndSolve& ps, boost::mutex& mutex,
00061 boost::barrier& barrier, const HexState& state)
00062 : m_ps(ps), m_mutex(mutex), m_barrier(barrier),
00063 m_state(state) {};
00064
00065 void operator()();
00066 private:
00067 PlayAndSolve& m_ps;
00068 boost::mutex& m_mutex;
00069 boost::barrier& m_barrier;
00070 const HexState& m_state;
00071 };
00072
00073 HexBoard& m_playerBrd;
00074
00075 HexBoard& m_solverBrd;
00076
00077 BenzenePlayer& m_player;
00078
00079 DfpnSolver& m_solver;
00080
00081 DfpnStates& m_positions;
00082
00083 const Game& m_game;
00084
00085 HexPoint m_parallelResult;
00086 };
00087
00088
00089
00090 _END_BENZENE_NAMESPACE_
00091
00092 #endif // PLAYANDSOLVE_HPP