From c5ae5d1137b9456fcb0b2e9e83c1bfc126522e92 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Mon, 7 Dec 2015 02:14:25 -0600 Subject: Move sim toward a message passing model. In prep for allowing sims to be handed off to a thread pool. --- sim.h | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'sim.h') diff --git a/sim.h b/sim.h index 9f31590..e6ba025 100644 --- a/sim.h +++ b/sim.h @@ -19,6 +19,7 @@ #ifndef QUACKLE_SIM_H #define QUACKLE_SIM_H +#include #include #include "alphabetparameters.h" @@ -113,11 +114,19 @@ struct Level PositionStatisticsList statistics; }; -typedef vector LevelList; +class LevelList : public vector +{ +public: + // expand the levels list to be at least number long + void setNumberLevels(unsigned int number); +}; struct SimmedMove { - SimmedMove(const Move &_move) : move(_move), m_includeInSimulation(true) { } + SimmedMove(const Move &_move) : + move(_move), + m_id(++objectIdCounter), + m_includeInSimulation(true) { } // + our scores - their scores + residual, except if we have no levels, // in which case returns move.equity @@ -127,15 +136,14 @@ struct SimmedMove // in which case returns move.win double calculateWinPercentage() const; - // expand the levels list to be at least number long - void setNumberLevels(unsigned int number); - // clear all level values void clear(); bool includeInSimulation() const; void setIncludeInSimulation(bool includeInSimulation); + long id() const { return m_id; }; + Move move; LevelList levels; AveragedValue residual; @@ -145,7 +153,10 @@ struct SimmedMove PositionStatistics getPositionStatistics(int level, int playerIndex) const; private: + long m_id; bool m_includeInSimulation; + + static std::atomic_long objectIdCounter; }; inline bool SimmedMove::includeInSimulation() const @@ -160,6 +171,19 @@ inline void SimmedMove::setIncludeInSimulation(bool includeInSimulation) typedef vector SimmedMoveList; +struct SimmedMoveMessage +{ + long id; + LevelList levels; + vector score; + vector bingos; + double residual; + double gameSpread; + double wins; + + bool bogowin; +}; + class Simulator { public: @@ -235,6 +259,10 @@ public: // simulate one iteration void simulate(int plies); + // Incoporate the results of a single simulation into the + // cumulative results + void incorporateMessage(const struct SimmedMoveMessage &message); + // Set oppo's rack to some partially-known tiles. // Set this to an empty rack if no tiles are known, so // that all tiles are chosen randomly each iteration. -- cgit v1.2.3