aaaa.js 7.06 KB
function aaaa(){
    var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다.
    var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것
    var out = 0;  ining = 1; //아웃카운트, 이닝
    var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호 
    var score = 0; score2 = 0;
    document.getElementById('jstest').innerHTML=" ";
    for(i = 0; i < 10; i++){
        var num = Math.random(); 
        document.getElementById('jstest').innerHTML+=(num+"  "+"<br\>");
        //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);    
        hitter = kia_hitter[1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다.
        document.getElementById('jstest').innerHTML+=(hitter[0]+"  ");
        var one = 0; var two = 0; var three = 0; var homerun = 0;
        
        if( num <= kia_pitcher[1][2]){
            one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2];
            two = pitcher[2] * hitter[3]/hitter[2];
            three = pitcher[2] * hitter[4]/hitter[2];
            homerun = pitcher[2] * hitter[5]/hitter[2];
            document.getElementById('jstest').innerHTML+=("확률" + " " + "1루타   " + one+ " "+"2루타  " +
                two+" "+"3루타  "+ three+ " ","홈런  " + homerun, " ");//////////////////////////////           
                
            if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능 
                var num1 = Math.random();
                if(num1 <= 0.5){
                    score = score + base3;                
                    base3 = base2;
                    base2 = base1;
                    base1 = 1;
                    document.getElementById('jstest').innerHTML+=("1루타!");
                    document.getElementById('jstest').innerHTML+=("베이스 상태"+" ", "1루   " + base1 + " "+ "2루    " + base2 + " "+
                    "3루    " + base3 + "  ");///////////////////////////  
                    document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
                }
                if(num1 > 0.5){
                    score = score + base3 + base2;                
                    base3 = base1;
                    base2 = 0;
                    base1 = 1;
                    document.getElementById('jstest').innerHTML+=("1루타!");
                    document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                    "3루    " + base3 + "  ");///////////////////////////  
                    document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
                }
                    
            }
            else if(one < num && num <= one + two){
                var num2 = Math.random();
                if(num2 <= 0.4){
                    score = score + base3 + base2; 
                    base3 = base1;
                    base2 = 1;
                    base1 = 0;
                    document.getElementById('jstest').innerHTML+=("2루타!");
                    document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                    "3루    " + base3 + "  ");///////////////////////////  
                    document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
                }
                if(0.4 < num2 && num2 <=0.7){
                    score = score + base3 + base2 + base1; 
                    base3 = 0;
                    base2 = 1;
                    base1 = 0;
                    document.getElementById('jstest').innerHTML+=("2루타!");
                    document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                    "3루    " + base3 + "  ");///////////////////////////  
                    document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
                }
                if(0.7 < num2 && num2 <= 1){
                    score = score + base3 + base2; 
                    base3 = 0;
                    base2 = 1;
                    base1 = 0;
                    out++;
                    document.getElementById('jstest').innerHTML+=("2루타!");
                    document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                    "3루    " + base3 + "  ");///////////////////////////  
                    document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
                }
                
            }
            else if(one + two < num && num <= one + two + three){
                score = score + base3 + base2 + base1;
                base3 = 1;
                base2 = 0;
                base1 = 0;
                document.getElementById('jstest').innerHTML+=("3루타!");
                document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                "3루    " + base3 + "  ");///////////////////////////  
                document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
            }
            else if(one + two + three < num && num <= one + two + three + homerun){
                score = score + base3 + base2 + base1 + 1;
                base3 = 0;
                base2 = 0;
                base1 = 0;
                document.getElementById('jstest').innerHTML+=("홈런!");
                document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
                "3루    " + base3 + "  ");///////////////////////////  
                document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
            }
        }
        if( kia_pitcher[1][2] < num && num <= kia_pitcher[1][2] + kia_pitcher[1][1]*0.01){
            base3 = base2;
            base2 = base1;
             base1 = 1;
             document.getElementById('jstest').innerHTML+=("볼넷!");
             document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
            "3루    " + base3 + "  ");///////////////////////////  
            document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
        }
        if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){
            out++;
            if(out >= 3){
                hitter = dusan_hitter[1];
                pitcher = dusan_pitcher[1];
                break;
            }
            document.getElementById('jstest').innerHTML+=("아웃!");
            document.getElementById('jstest').innerHTML+=("베이스 상태"+" "+ "1루   " + base1 + " "+ "2루    " + base2 + " "+
            "3루    " + base3 + "  ");///////////////////////////  
            document.getElementById('jstest').innerHTML+=("score: "+score+ "   ");
        }
    }
}