From b1dcec5200c2f48be62e124466920c42b9e742c2 Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Thu, 24 Oct 2024 15:54:03 +0200 Subject: [PATCH] Add hint about adding parameters to the main parameter struct --- docs/tasks/2_extend_arbitration_graph.md | 11 +++++++++++ docs/tasks/5_cost_arbitration.md | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/docs/tasks/2_extend_arbitration_graph.md b/docs/tasks/2_extend_arbitration_graph.md index 99c28ff8..4d7b6e38 100644 --- a/docs/tasks/2_extend_arbitration_graph.md +++ b/docs/tasks/2_extend_arbitration_graph.md @@ -23,6 +23,7 @@ Integrate the `ChaseGhost` behavior component into the arbitration graph defined - Take a look at how the other behavior components are defined in `include/demo/pacman_agent.hpp`. - Add the `ChaseGhost` behavior component as a new member of the `PacmanAgent` class and initialize it in the constructor. +- Extend the `PacmanAgent` parameter struct to include the parameters for the `ChaseGhost` behavior component. - Add a new option to the priority arbitrator. - Run the game, take a look at the new arbitration graph and observe how PacMan behaves. @@ -42,6 +43,16 @@ private: ChaseGhostBehavior::Ptr chaseGhostBehavior_; ``` +Extend the `PacmanAgent` parameter struct to include the parameters for the `ChaseGhost` behavior component: +```cpp +struct Parameters { + AvoidGhostBehavior::Parameters avoidGhostBehavior; + // Add the parameters for the ChaseGhost behavior component + ChaseGhostBehavior::Parameters chaseGhostBehavior; + MoveRandomlyBehavior::Parameters moveRandomlyBehavior; +}; +``` + In the constructor of the `PacmanAgent` class, initialize the `ChaseGhost` behavior component and add it to the priority arbitrator: ```cpp explicit PacmanAgent(const entt::Game& game) diff --git a/docs/tasks/5_cost_arbitration.md b/docs/tasks/5_cost_arbitration.md index 65dc7438..28debff1 100644 --- a/docs/tasks/5_cost_arbitration.md +++ b/docs/tasks/5_cost_arbitration.md @@ -30,6 +30,7 @@ Finish the implementation of the `CostEstimator` and replace the random arbitrat - In `cost_estimator.cpp`, fill in the blanks to compute `nDots` and `nCells`. - Add an instance of the `CostEstimator` to the `PacmanAgent` class and initialize it in the constructor. + Don't forget to include the necessary headers and extend the parameter struct with the parameters for the `CostEstimator`. - Replace the random arbitrator with a cost arbitrator in the `PacmanAgent` class. Pass the `CostEstimator` instance to the `addOption` method. ## Solution @@ -79,6 +80,18 @@ private: CostEstimator::Ptr costEstimator_; ``` +Extend the `Parameters` struct to contain the parameters for the `CostEstimator`: +```cpp +struct Parameters { + AvoidGhostBehavior::Parameters avoidGhostBehavior; + ChaseGhostBehavior::Parameters chaseGhostBehavior; + MoveRandomlyBehavior::Parameters moveRandomlyBehavior; + + // Add the parameters for the CostEstimator + CostEstimator::Parameters costEstimator; +}; +``` + As always, the magic happens in the constructor of the `PacmanAgent` class. Instantiate the cost estimator and pass it in the `addOption` calls: ```cpp