flash on 2010-7-21
天鳳の段位シミュレーション
七段1400pt(原点)からスタート
六段落ちor九段昇段で終了
1位率 = 2位率 = 3位率 = 4位率 = 0.25
でも九段全然なれるね!(約15%)
@see 天鳳 段級位制 http://tenhou.net/man/#DAN
ちなみに鳳南です
♥0 |
Line 105 |
Modified 2010-09-11 12:22:53 |
MIT License
archived:2017-03-20 05:37:20
ActionScript3 source code
/**
* Copyright enecre ( http://wonderfl.net/user/enecre )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/sQ4s
*/
// forked from enecre's 天鳳段位シミュレート
// 天鳳の段位シミュレーション
// 特南シミュレート
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
import com.bit101.components.*;
[SWF(width = 465, height = 465, backgroundColor = 0xddddff)]
public class TenhouDan extends Sprite {
private const HOUOU:int = 3;
private const TOKUJO:int = 2;
private const JOKYU:int = 1;
private const IPPAN:int = 0;
private var pt:int;
private var dan:int;
private var numPlay:int
private var numSimulate:int = 10000;
private var odds1:Number = 0.250;
private var odds2:Number = 0.275;
private var odds3:Number = 0.250;
private var odds4:Number = 0.225;
private var ton:Boolean = true;//東風
private var takuLevel:int = HOUOU;
private var _tf:TextField;
public function TenhouDan() {
// write as3 code here..
_tf = new TextField();
_tf.text = "";
_tf.width = 465;
_tf.height = 465;
_tf.y = 160;
addChild(_tf);
createLabelAndInput("numSimulate",5,numSimulate);
createLabelAndInput("odds1",25,odds1);
createLabelAndInput("odds2",45,odds2);
createLabelAndInput("odds3",65,odds3);
createLabelAndInput("odds4", 85,odds4);
var startSimulate:PushButton = new PushButton(this, 0, 140, "Simulate", simulate);
var ton_nan:PushButton = new PushButton(this, 0, 110, "ton", function(e:Event):void {
var t:PushButton = e.currentTarget as PushButton;
ton = (!ton);
if (ton == true) t.label = "ton";
else t.label = "nan";
tr(ton.toString());
} );
ton_nan.width = 25;
}
private function simulate(e:Event = null):void{
//if(e){(e.target as PushButton).enabled = false;}
//if(odds1 + odds2 + odds3 + odds4 != 1.0){tr("不正な値です");return;}
var num9d:int = 0;
var num6d:int = 0;
var numPlay9d:int = 0;
var numPlay6d:int = 0;
var l:int = numSimulate;
while(l--){
this.dan = 9;
this.pt = 1000;
this.numPlay = 0;
while((this.dan != 6) && (this.dan != 11)){
play();
}
if(this.dan == 11){num9d++;numPlay9d+=this.numPlay;}
if(this.dan == 6){num6d++;numPlay6d+=this.numPlay;}
}
tr("11段になった回数: " + num9d , "平均試合数: " + int(numPlay9d/num9d));
tr("6段になった回数: " + num6d , "平均試合数: " + int(numPlay6d/num6d));
}
private function play():void{
this.numPlay++;
var rand:int = int(Math.random() * 100);
var juni:int = 0;
if (rand >= (odds1)*100)juni++;
if (rand >= (odds1 + odds2)*100)juni++;
if (rand >= (odds1 + odds2 + odds3)*100)juni++;
switch(juni){
case 0: this.pt += 60;break;
case 1: this.pt += 30;break;
case 2: break;
case 3: this.pt -= (20 + this.dan * 10);break;
}
if(this.pt < 0){
this.dan--;
this.pt = (this.dan == 4)?800:(this.dan == 5)?1000:(this.dan == 6)?1200:(this.dan == 7)?1400:(this.dan == 8)?1600:1800;
return;
}
if((this.dan == 4 && this.pt >= 1800) || (this.dan == 5 && this.pt >= 2000) || (this.dan == 6 && this.pt >= 2400) || (this.dan == 7 && this.pt >= 2800) || (this.dan == 8 && this.pt >= 3200) || (this.dan == 9 && this.pt >= 3600) || (this.dan == 10 && this.pt >= 4000)){
this.dan++;
this.pt = (this.dan == 4)?800:(this.dan == 5)?1000:(this.dan == 6)?1200:(this.dan == 7)?1400:(this.dan == 8)?1600:(this.dan == 9)?1800:2000;
return;
}
}
private function createLabelAndInput(text:String,y:int,defaultNumber:Number):void{
var tf:Label = new Label(this, 0, y, text);
tf.width = 70;
var input:InputText = new InputText(this, tf.width, y, String(defaultNumber), onChangeText);
input.width = 50;
input.name = text;
}
private function onChangeText(e:Event):void{
var currentTarget:InputText = (e.currentTarget as InputText);
this[currentTarget.name] = Number(currentTarget.text);
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
_tf.scrollV = _tf.maxScrollV;
}
}
}