-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use custom std::minstd_rand based RNG for AI
- Loading branch information
Showing
4 changed files
with
49 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org) | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "ai/random.h" | ||
|
||
namespace AI { | ||
|
||
std::minstd_rand& getRandomGenerator() | ||
{ | ||
std::random_device rnd_dev; | ||
static std::minstd_rand rng(rnd_dev()); | ||
return rng; | ||
} | ||
|
||
} // namespace AI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org) | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "helpers/random.h" | ||
#include <random> | ||
|
||
namespace AI { | ||
|
||
std::minstd_rand& getRandomGenerator(); | ||
|
||
template<typename T> | ||
T randomValue(T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) | ||
{ | ||
return helpers::randomValue(getRandomGenerator(), min, max); | ||
} | ||
|
||
} // namespace AI |