@@ -240,6 +240,9 @@ class RangeIterator {
240240 bool operator !=(const RangeIterator& other) const {
241241 return id_ != other.id_ || tree_ != other.tree_ ;
242242 }
243+ bool operator ==(const RangeIterator& other) const {
244+ return !(this ->operator !=(other));
245+ }
243246 Id operator *() { return Id (id_, tree_); }
244247};
245248
@@ -289,7 +292,7 @@ std::shared_ptr<InfostateTree> MakeInfostateTree(
289292 const std::vector<InfostateNode*>& start_nodes,
290293 bool store_world_states = false , int max_move_ahead_limit = 1000 );
291294
292- class InfostateTree final {
295+ class InfostateTree final : public std::enable_shared_from_this<InfostateTree> {
293296 // Note that only MakeInfostateTree is allowed to call the constructor
294297 // to ensure the trees are always allocated on heap. We do this so that all
295298 // the collected pointers are valid throughout the tree's lifetime even if
@@ -310,6 +313,12 @@ class InfostateTree final {
310313 const std::vector<const InfostateNode*>&, bool , int );
311314
312315 public:
316+ // -- gain shared ownership of the allocated infostate object
317+ std::shared_ptr<InfostateTree> shared_ptr () { return shared_from_this (); }
318+ std::shared_ptr<const InfostateTree> shared_ptr () const {
319+ return shared_from_this ();
320+ }
321+
313322 // -- Root accessors ---------------------------------------------------------
314323 const InfostateNode& root () const { return *root_; }
315324 InfostateNode* mutable_root () { return root_.get (); }
@@ -349,7 +358,8 @@ class InfostateTree final {
349358 // Returns `None` if the sequence is the empty sequence.
350359 absl::optional<DecisionId> DecisionIdForSequence (const SequenceId&) const ;
351360 // Returns `None` if the sequence is the empty sequence.
352- absl::optional<InfostateNode*> DecisionForSequence (const SequenceId&);
361+ absl::optional<InfostateNode*> DecisionForSequence (
362+ const SequenceId& sequence_id) const ;
353363 // Returns whether the sequence ends with the last action the player can make.
354364 bool IsLeafSequence (const SequenceId&) const ;
355365
@@ -392,13 +402,13 @@ class InfostateTree final {
392402 // Compute best response and value based on gradient from opponents.
393403 // This consumes the gradient vector, as it is used to compute the value.
394404 std::pair<double , SfStrategy> BestResponse (
395- TreeplexVector<double >&& gradient) const ;
405+ TreeplexVector<double > gradient) const ;
396406 // Compute best response value based on gradient from opponents over leaves.
397407 // This consumes the gradient vector, as it is used to compute the value.
398- double BestResponseValue (LeafVector<double >&& gradient) const ;
408+ double BestResponseValue (LeafVector<double > gradient) const ;
399409
400410 // -- For debugging ----------------------------------------------------------
401- std::ostream& operator <<(std::ostream& os) const ;
411+ friend std::ostream& operator <<(std::ostream& os, const InfostateTree& tree) ;
402412
403413 private:
404414 const Player acting_player_;
0 commit comments