Elin:Code Analysis/General Function: Difference between revisions

→‎Dice Roll: added EN description.
(Created the page)
 
(→‎Dice Roll: added EN description.)
Line 54: Line 54:
The slope of the function gradually decreases and finally reaches <code>(rate / 100)^10</code>
The slope of the function gradually decreases and finally reaches <code>(rate / 100)^10</code>


==ダイスロールなど==
==Dice Roll==


{{EA 23.109 Stable Patch 2}}
{{EA 23.109 Stable Patch 2}}
Line 64: Line 64:


     public int num;
     public int num;
ダイスの数量です。
This is the number of the dices.




     public int sides;
     public int sides;
日本語で言うとダイスの面数です。
This is the sides of each dice.




     public int bonus;
     public int bonus;
おそらくダイスロール結果に定数を加算するものです。
This is a constant that is added to the ressult of roll.


     public Card card;
     public Card card;


ここから、メインのRollの定義が述べられます。
Here starts the definition of the Roll()


     public static int Roll(int num, int sides, int bonus = 0, Card card = null)
     public static int Roll(int num, int sides, int bonus = 0, Card card = null)
Line 89: Line 89:
             a = 1 + Mathf.Abs(num3 / 100) + ((Mathf.Abs(num3 % 100) > rnd(100)) ? 1 : 0);
             a = 1 + Mathf.Abs(num3 / 100) + ((Mathf.Abs(num3 % 100) > rnd(100)) ? 1 : 0);
         }
         }
Evalue(78)は運であり、flagは運が0より大きいことを示す役割のようです。
Evalue(78) is luck, flag is used to show luck is greater than 0.


aはリロール回数を示す整数で、基本的には、初期値1に、運を100で割った絶対値を足したものですが、(運を100で割ったあまり)%の確率でそれにさらに1が足されます。
"a" is an integer that indicates how many tries the dices are thrown.


"a" is approximately |luck| / 100, but "a" increases by 1 at the chance of <b>rest of</b> |luck| / 100


          
          
Line 104: Line 105:
         }
         }
         return num2;
         return num2;
ここでは実際にダイスが振られます。


まず、ダイスロールが繰り返される回数はiが0からa-1もしくは20-1<ref>整数なので、i<20のときi=20は認められない。</ref>まで増えていくまでなので、
This part generates the results of dice rolls and records the best/worst result depending on flag.


'''a回、ただし上限20'''です。
There are "a"es of results (up to 20) and the final result of the whole Roll() process is the best result of this process if the luck is positive.


後述する関数であるroll()で出た値は、条件を満たせばnum2として記憶されます。
For a character with negative luck, the result will be the worst one among all the results.


その条件は、繰り返し回数0の初のロールであるとき、もしくは運が正かつ、前のnum2より大きい値が出たとき、もしくは運が負かつ、前のnum2より小さい値が出てしまったときです。
最後に、運が正であれば繰り返した中で最大のものを表し、運が負のときでは繰り返した中で最小のものを表すnum2が提示されます。
          
          
         int Roll()
         int Roll()
Line 127: Line 124:
     }
     }


これはnumの回数だけ、num5にrnd(sides) + 1を加えるというプログラムなので、
This is just a dice roll simulatiion, but bonus being added to the roll is an important point.
 
言い換えると個数numで、面数がsidesのサイコロを投げて出た目の総和です。
 
なお、この結果にbonusが足し算されてrollの値が決まります。


     public static int RollMax(int num, int sides, int bonus = 0)
     public static int RollMax(int num, int sides, int bonus = 0)
Line 138: Line 131:
     }
     }


これは複数のサイコロを投げて出る目の総和の最大値にbonusを足したものです。
This is the possible best ressult of roll + bonus as well.


     public static int rnd(int a)
     public static int rnd(int a)
Line 145: Line 138:
     }
     }


Elinの解析で頻出の、rnd(a)= ”0からa-1までのランダムな値”
This function emits a random number that is { 0, 1,..., a }.
となる関数です。
 
 
 
 
 
 




[[Category: Elin Spoiler]]
[[Category: Elin Spoiler]]
[[Category: EN]]
[[Category: EN]]