Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Feb 13, 2019
1 parent 2f98d00 commit 1e6868d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
10 changes: 5 additions & 5 deletions DungeonTemplateLibrary/DungeonRandom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,30 @@ namespace dtl {
class Xor8
{
private:
uint_fast8_t x{1};
uint_fast8_t x{ 1 };
uint_fast8_t a{ 1 };
uint_fast8_t b{ 1 };
uint_fast8_t c{ 2 };
public:
explicit Xor8() noexcept :x(mersenne_twister_32bit(1, 255)) {}

//通常の乱数
constexpr std::uint_fast8_t operator()() noexcept {
std::uint_fast8_t operator()() noexcept {
x ^= x >> a;
x ^= x << b;
x ^= x >> c;
return x;
}
//0~最大値-1 (余りの範囲の一様分布乱数)
constexpr std::uint_fast8_t operator()(const std::uint_fast8_t max_) noexcept {
std::uint_fast8_t operator()(const std::uint_fast8_t max_) noexcept {
return ((std::uint_fast8_t)(((double)operator()() / ((double)(std::numeric_limits<std::uint_fast8_t>::max)() + 1)) * max_));
}
//最小値~最大値
constexpr std::uint_fast8_t operator()(const std::uint_fast8_t min_, const std::uint_fast8_t max_) noexcept {
std::uint_fast8_t operator()(const std::uint_fast8_t min_, const std::uint_fast8_t max_) noexcept {
return ((std::uint_fast8_t)(((double)operator()() / ((double)(std::numeric_limits<std::uint_fast8_t>::max)() + 1)) * (max_ - min_ + 1)) + min_);
}

constexpr void seed(const std::uint_fast8_t x_) noexcept {
void seed(const std::uint_fast8_t x_) noexcept {
x = x_;
}

Expand Down
2 changes: 1 addition & 1 deletion include/cpp14/DungeonNoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace dtl {

for (std::size_t row{ 1 }; row < matrix_.size(); ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size(); ++col) {
if ((matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col]) || mersenne_twister_32bit.probability(rbool_)) continue;
if ((matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col]) || !mersenne_twister_32bit.probability(rbool_)) continue;
if (matrix_[row][col]) matrix_[row][col] = false;
else matrix_[row][col] = true;
}
Expand Down
33 changes: 33 additions & 0 deletions include/cpp14/DungeonRandom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@ namespace dtl {
};
static thread_local dtl::random::Xor128 xor_128;

class Xor8
{
private:
uint_fast8_t x{ 1 };
uint_fast8_t a{ 1 };
uint_fast8_t b{ 1 };
uint_fast8_t c{ 2 };
public:
explicit Xor8() noexcept :x(mersenne_twister_32bit(1, 255)) {}

//通常の乱数
std::uint_fast8_t operator()() noexcept {
x ^= x >> a;
x ^= x << b;
x ^= x >> c;
return x;
}
//0~最大値-1 (余りの範囲の一様分布乱数)
std::uint_fast8_t operator()(const std::uint_fast8_t max_) noexcept {
return ((std::uint_fast8_t)(((double)operator()() / ((double)(std::numeric_limits<std::uint_fast8_t>::max)() + 1)) * max_));
}
//最小値~最大値
std::uint_fast8_t operator()(const std::uint_fast8_t min_, const std::uint_fast8_t max_) noexcept {
return ((std::uint_fast8_t)(((double)operator()() / ((double)(std::numeric_limits<std::uint_fast8_t>::max)() + 1)) * (max_ - min_ + 1)) + min_);
}

void seed(const std::uint_fast8_t x_) noexcept {
x = x_;
}

};
static thread_local dtl::random::Xor8 xor_8;



} //namespace
Expand Down
37 changes: 37 additions & 0 deletions include/cpp14/FractalIsland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ namespace dtl {
namespace terrain {

namespace stl {

//ランダム法
template<typename Matrix_Int_>
class SimpleCellularAutomatonIsland {
public:
//コンストラクタ
constexpr SimpleCellularAutomatonIsland() noexcept = default;
template<typename Matrix_>
constexpr explicit SimpleCellularAutomatonIsland(Matrix_& matrix_, const std::size_t max_value_ = 2) noexcept {
create(matrix_, max_value_);
}
//ワールドマップ生成
template<typename Matrix_>
constexpr void create(Matrix_& matrix_, const std::size_t max_value_ = 2) const noexcept {

using dtl::random::mersenne_twister_32bit;

for (std::size_t row{ 1 }; row < matrix_.size() - 1; ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size() - 1; ++col)
if (mersenne_twister_32bit.probability()) matrix_[row][col] = 1;

for (std::size_t i{}; i < max_value_; ++i)
for (std::size_t row{ 1 }; row < matrix_.size() - 1; ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size() - 1; ++col) {
if (matrix_[row][col - 1] && matrix_[row][col + 1] && matrix_[row - 1][col] && matrix_[row + 1][col]) matrix_[row][col] = matrix_[row][col + 1];
else switch (mersenne_twister_32bit(4))
{
case 0:matrix_[row][col] = matrix_[row][col - 1]; break;
case 1:matrix_[row][col] = matrix_[row][col + 1]; break;
case 2:matrix_[row][col] = matrix_[row - 1][col]; break;
case 3:matrix_[row][col] = matrix_[row + 1][col]; break;
}
}

}
};

//Diamond Square (Average)
//ダイヤモンド・スクエア法(平均値)
template<typename Matrix_Int_, typename Matrix_>
Expand Down
3 changes: 3 additions & 0 deletions include/cpp14/SimpleRogueLike.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace dtl {
namespace dungeon {

namespace stl {

template<typename Matrix_Int_>
constexpr Matrix_Int_ absTemplate(const Matrix_Int_& value_) noexcept {
return (value_ < 0) ? (-value_) : value_;
Expand All @@ -29,6 +30,8 @@ namespace dtl {
RL_COUNT_Y
};



template<typename Matrix_Int_>
class SimpleRogueLike {
private:
Expand Down

0 comments on commit 1e6868d

Please sign in to comment.