Facebook
From Gray Agouti, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 51
  1.  
  2.     std::vector<std::unique_ptr<graph_state>> get_successors() const override {
  3.         std::vector<std::unique_ptr<graph_state>> r;
  4.         std::vector<move_direction> possibilities = {
  5.                 move_direction::UP,
  6.                 move_direction::DOWN,
  7.                 move_direction::LEFT,
  8.                 move_direction::RIGHT,
  9.         };
  10.  
  11.         for (move_direction n : possibilities) {
  12.             auto state_copy = clone();
  13.             if(!dynamic_cast<sliding_puzzle &>(*state_copy).make_move(n))
  14.                 continue;
  15.             state_copy->update_score(state_copy->get_g() + 1);
  16.             state_copy->set_parent(this);
  17.             r.push_back(std::move(state_copy));
  18.         }
  19.  
  20.         return r;
  21.     }