From 0569fb3129808c9d01575eeece44b78ef14b6aeb Mon Sep 17 00:00:00 2001 From: jcoupey Date: Mon, 2 Dec 2024 14:53:44 +0100 Subject: [PATCH] Move depth and searches calculation to reusable static functions. --- src/structures/cl_args.cpp | 16 +++++++++++++--- src/structures/cl_args.h | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/structures/cl_args.cpp b/src/structures/cl_args.cpp index b1d534e4..caf7c08d 100644 --- a/src/structures/cl_args.cpp +++ b/src/structures/cl_args.cpp @@ -75,18 +75,28 @@ void update_port(Servers& servers, std::string_view value) { } } -void CLArgs::set_exploration_level(unsigned exploration_level) { - depth = exploration_level; +unsigned CLArgs::get_depth(unsigned exploration_level) { + return exploration_level; +} +unsigned CLArgs::get_nb_searches(unsigned exploration_level) { assert(exploration_level <= MAX_EXPLORATION_LEVEL); - nb_searches = 4 * (exploration_level + 1); + unsigned nb_searches = 4 * (exploration_level + 1); if (exploration_level >= 4) { nb_searches += 4; } if (exploration_level == MAX_EXPLORATION_LEVEL) { nb_searches += 4; } + + return nb_searches; +} + +void CLArgs::set_exploration_level(unsigned exploration_level) { + depth = get_depth(exploration_level); + + nb_searches = get_nb_searches(exploration_level); } } // namespace vroom::io diff --git a/src/structures/cl_args.h b/src/structures/cl_args.h index 71b4ef9e..53f3c131 100644 --- a/src/structures/cl_args.h +++ b/src/structures/cl_args.h @@ -37,6 +37,10 @@ struct CLArgs { unsigned nb_searches; // derived from -x unsigned depth; // derived from -x + static unsigned get_depth(unsigned exploration_level); + + static unsigned get_nb_searches(unsigned exploration_level); + void set_exploration_level(unsigned exploration_level); };