D'angband  0.0.0
Deeangband
 全て クラス 名前空間 ファイル 関数 変数 型定義 列挙型 列挙値 フレンド マクロ定義 ページ
Dice.cpp
[詳解]
1 
9 #include "stdafx.h"
10 #include "Dice.h"
11 
12 namespace Deeangband
13 {
14 
15  std::mt19937 Dice::mt;
16 
17  Dice::Dice(void)
18  {
19  this->Set(0, 0);
20  }
21 
22  Dice::Dice(int num, int side)
23  {
24  this->Set(num, side);
25  }
26 
27  Dice::‾Dice(void)
28  {
29  }
30 
31  void Dice::Set(int num, int side)
32  {
33  this->num = num;
34  this->side = side;
35  }
36 
37  void Dice::Initialize(void)
38  {
39  std::random_device rd;
40  std::array<unsigned, 100> seeds;
41  for(auto & s : seeds) s = rd();
42  std::seed_seq seq(seeds.begin(), seeds.end());
43  mt.seed(seq);
44  }
45 
46  int Dice::GetNum(void)
47  {
48  return this->num;
49  }
50 
51  int Dice::GetSide(void)
52  {
53  return this->side;
54  }
55 
56  int Dice::Cast(void)
57  {
58  int i, n = 0;
59  for(i = 0; i < this->num; i++) n += Dice::Rand1(this->side);
60  return n;
61  }
62 
63  int Dice::Cast(int num, int side)
64  {
65  int i, n = 0;
66  for(i = 0; i < num; i++) n += Dice::Rand1(side);
67  return n;
68  };
69 
70  int Dice::MaxCast(void)
71  {
72  return this->num * this->side;
73  }
74 
75  int Dice::MaxCast(int num, int side)
76  {
77  return num * side;
78  };
79 
80  int Dice::Rand0(int max)
81  {
82  std::uniform_int_distribution<int> dist(0, max-1);
83  return dist(mt);
84  }
85 
86  int Dice::Rand1(int max)
87  {
88  return Dice::Rand0(max) + 1;
89  }
90 
91  bool Dice::Saving(int diff)
92  {
93  std::normal_distribution<int> dist(0, 20);
94  return (diff >= dist(mt));
95  }
96 
97 }
Diceクラスとその他付随要素の定義
int side
ダイスの面数
Definition: Dice.h:30
標準のシステム インクルード ファイルのインクルード ファイル、または 参照回数が多く、かつあまり変更さ...
static int Dice::Rand0(int max)
0を最小値とした乱数を返す
int num
ダイスの数
Definition: Dice.h:29