import java.util.Arrays;
import java.text.*;
public class PokerTest {
public static void main(String args[]){
//System.out.println("Hello world!");
//int[] startLife={20,25,33,40,50,100};
int[] startLife={0};
double[] winPercent={0.44,0.46,0.48,0.50,0.52,0.54,0.56};
int[] timeEnd={300,600,1500,3000};
//RandomWalk[] rw=new RandomWalk[100];
RandomWalkHP0[] rw=new RandomWalkHP0[100];
int count=0;
for(int i=0;i<startLife.length;i++){
for(int k=0;k<timeEnd.length;k++){
for(int j=0;j<winPercent.length;j++){
//rw[count]=new RandomWalk(startLife[i],winPercent[j],timeEnd[k]);
rw[count]=new RandomWalkHP0(startLife[i],winPercent[j],timeEnd[k]);
rw[count].info();
count++;
}
}
}
}
}
public class RandomWalkHP0 {
int timeEnd=3000;//タイムスパン
//int memberMax=10000;//試す人数
int N=1000000;//試行回数
double startLife=0; //開始HP
//double deadLife=startLife/2.0; //死亡HP
//int nextRateLife=startLife*2;//終了HP
double[] life=new double[N]; //残りHP
double winPercent=0.52; //勝率
double winlife=1.0; //勝利の際、得るHP
double loselife=1.0; //敗北の際、失うHP
double lifeExpect=0;//終了HP期待値
double lifeVariance=0;//終了HP分散
double lifeDeviation=0;//終了HP標準偏差
/*
int[] surviveCount= new int[N];//生存数
int[] nextRateCount= new int[N];//ダブルアップ数
double nextRateExpect=0;//ダブルアップ確率期待値
double nextRateVariance=0;//ダブルアップ確率分散
double nextRateDeviation=0;//ダブルアップ確率標準偏差
*/
RandomWalkHP0(){//コンストラクタ。通常は↑↑の変数が適用される
startWalk();
statistics();
}
RandomWalkHP0(int st,double wp,int ts){//コンストラクタ 変数指定バージョン
startLife=st;
winPercent=wp;
timeEnd=ts;
startWalk();
statistics();
}
void info(){
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(2);//小数点以下桁数は2
System.out.println("試行回数:"+N+"回 タイムスパン:"+timeEnd);
System.out.println("開始HP"+startLife+" 勝率:"+winPercent*100+"%");
System.out.println("平均HP:"+format.format(lifeExpect)+"±"+format.format(lifeDeviation));
}
void statistics(){
expect();
variance();
}
void expect(){//生存確率期待値を出す。
for(int i=0;i<N;i++){
lifeExpect+=life[i];
}
lifeExpect=lifeExpect/(double)N;
}
void variance(){//分散を出す。expect前提
for(int i=0;i<N;i++){
lifeVariance+=Math.pow((life[i]-lifeExpect),2.0);
}
lifeVariance=lifeVariance/(double)N;
lifeDeviation=Math.pow(lifeVariance, 0.5);//標準偏差
}
void startWalk(){//実際にランダムウォークを実行する
//Arrays.fill(surviveCount,memberMax);//生存数初期化(最大値から、どんどん死んでく)
//Arrays.fill(nextRateCount,0);//ダブルアップ数初期化
Arrays.fill(life,startLife);//HP初期化
for (int i=0;i<N;i++){//N回試すよ
for(int time=0;time<timeEnd;time++){
if(winPercent>Math.random()){
life[i]+=winlife;
}else{
life[i]-=loselife;
}
/*
if(life<=deadLife){
surviveCount[i]--;//死ぬ
break;
}else if(life>=nextRateLife){
nextRateCount[i]++;//ダブルアップ
break;
}*/
}
}//N回end
}//func end
}