关于Pokemon精灵捕捉系统的模拟(一)

今天看了一下关于捕捉的计算方式,实现部分功能
关于Pokemon精灵捕捉系统的模拟(一)_第1张图片

package pokemonCapture;

public class test {
     

	//捕捉率 CaptureRate
	//最大HP  maxHp
	//当前HP currentHp
	//捕获度 capture
	//精灵球修正 PokemonBallCorrection
	//状态修正  StatusCorrection
	//计算公式:   捕捉率=(最大HP*3-当前HP*2)/(最大HP*3)*精灵捕获度*精灵球修正*状态修正/255
	
	private double captureRate;
	private int maxHp;
	private int currentHp;
	private int capture;
	private double pokemonBallCorrection;
	private double statusCorrection;
	
	
	public double getCaptureRate() {
     
		return captureRate;
	}
	public void setCaptureRate(double captureRate) {
     
		this.captureRate = captureRate;
	}
	public int getMaxHp() {
     
		return maxHp;
	}
	public void setMaxHp(int maxHp) {
     
		this.maxHp = maxHp;
	}
	public int getCurrentHp() {
     
		return currentHp;
	}
	public void setCurrentHp(int currentHp) {
     
		this.currentHp = currentHp;
	}
	public int getCapture() {
     
		return capture;
	}
	public void setCapture(int capture) {
     
		this.capture = capture;
	}
	public double getPokemonBallCorrection() {
     
		return pokemonBallCorrection;
	}
	public void setPokemonBallCorrection(double pokemonBallCorrection) {
     
		this.pokemonBallCorrection = pokemonBallCorrection;
	}
	public double getStatusCorrection() {
     
		return statusCorrection;
	}
	public void setStatusCorrection(double statusCorrection) {
     
		this.statusCorrection = statusCorrection;
	}
	
	public test(int maxHp, int currentHp, int capture, double pokemonBallCorrection, double statusCorrection) {
     
		this.maxHp = maxHp;
		this.currentHp = currentHp;
		this.capture = capture;
		this.pokemonBallCorrection = pokemonBallCorrection;
		this.statusCorrection = statusCorrection;
	}
	
	public double CR() {
     
		captureRate=(maxHp*3-currentHp*2)*capture*pokemonBallCorrection*statusCorrection/(maxHp*3*255);
		return captureRate;
	}
	
	/**
	 * Math.pow(a, b)//计算a的b次方
	 * @param captureNumber  捕捉次数
	 * @return 捕捉概率  :第N次才抓到的概率
	 */
	public double MultipleSnaps(int captureNumber) {
     
		
		//1 得到捕捉概率   captureRate
		CR();
		
		//2 计算多次捕捉均失败的概率
		double rate= Math.pow(1-captureRate, captureNumber);
		
		//3 以百分比形式输出  保留2为小数部分,并四舍五入
		System.out.print("用了"+captureNumber+"个超级球球都没抓到的概率:");
		double accurateRate=(double) Math.round(rate* 10000)/100;
		System.out.println(accurateRate+"%");
		
		//4 返回值是精确概率
		return rate;
	}
	
	public static void main(String[] args) {
     
		//计算炎帝使用30超级球并且加上催眠的概率
		test t2=new test(1000,1,3,1.5,2);
		
		for(int i=1;i<10;i++) {
     
			t2.MultipleSnaps(10*i);
		}	
	}
}

用了10个球都没抓到的概率:69.83%
用了20个球都没抓到的概率:48.77%
用了30个球都没抓到的概率:34.05%
用了40个球都没抓到的概率:23.78%
用了50个球都没抓到的概率:16.61%
用了60个球都没抓到的概率:11.6%
用了70个球都没抓到的概率:8.1%
用了80个球都没抓到的概率:5.66%
用了90个球都没抓到的概率:3.95%

这里的球使用的是超级球,假定炎帝血量是1000,我们将其打到一滴血,并且使用催眠术将其催眠,然后捕捉。上面是测试的一部分概率实际上对应的“第N个球才抓到的概率”=1-“N次都没抓到的概率”,因为对于伸手来说捕捉率趋近于0 。(大师球的修正是255 这使得他的捕捉概率就是100%)
下次对上面的函数命名以及功能进一步完善,添加多次进化中各个进化层级的概率计算
QQ:872742416

你可能感兴趣的:(宝可梦)