Adding basic basic basic AI
This commit is contained in:
53
src/dawn/util/random.hpp
Normal file
53
src/dawn/util/random.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
/**
|
||||
* Seed the random number generator
|
||||
* @param seed Seed to use for the seeded random number generator.
|
||||
*/
|
||||
static void randSeed(int32_t seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
static int32_t randomGeneratei32() {
|
||||
return (int32_t)rand();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random number.
|
||||
* @returns A random number.
|
||||
*/
|
||||
template<typename T>
|
||||
static T randomGenerate() {
|
||||
return (T)((float_t)randomGeneratei32() * MATH_PI);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Clamps a random number generation.
|
||||
*
|
||||
* @param min Minimum value to generate from. (Inclusive)
|
||||
* @param max Maximum value to generate to. (Exclusive)
|
||||
* @return Random number between min and max.
|
||||
*/
|
||||
template<typename T>
|
||||
static inline T randRange(T min, T max) {
|
||||
return mathMod<T>(randomGenerate<T>(), (max - min)) + min;
|
||||
}
|
||||
|
||||
static inline float_t randRange(float_t min, float_t max) {
|
||||
return mathMod(randomGenerate<float_t>(), (max - min)) + min;
|
||||
}
|
||||
|
||||
static inline glm::vec2 randRange(glm::vec2 min, glm::vec2 max) {
|
||||
return glm::vec2(randRange(min.x, max.x), randRange(min.y, max.y));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user