정주희

simulation_kia_vs_dusan

var dusan_hitter = [
['선수명', 'AVG', 'H', '2B', '3B', 'HR']
['선수명', 'AVG', 'H', '2B', '3B', 'HR'],
['박건우', 0.356, 47, 9, 0, 2],
['허경민', 0.345, 49, 6, 0, 3],
['페르난데스', 0.336, 48, 5, 0, 6],
......@@ -9,19 +9,10 @@ var dusan_hitter = [
['김재환', 0.285, 37, 4, 1, 9],
['장승현', 0.284, 23, 1, 0, 1],
['조수행', 0.278, 10, 1, 1, 0],
['양석환', 0.277, 38, 8, 0, 5],
['박계범', 0.266, 21, 5, 0, 2],
['김재호', 0.243, 18, 1, 0, 1],
['오재원', 0.22, 11, 2, 0, 0],
['강승호', 0.212, 7, 0, 0, 2],
['권민석', 0.167, 2, 1, 0, 0],
['박세혁', 0.161, 5, 0, 0, 0],
['안권수', 0.133, 2, 0, 0, 0],
['정수빈', 0.125, 4, 1, 0, 0]
]
var dusan_pitcher = [
['선수명', '볼넷%', '피안타율']
['선수명', '볼넷%', '피안타율'],
['로켓', 7.7, 0.267],
['미란다', 15.3, 0.259],
['최원준', 5.7, 0.215],
......
......@@ -9,17 +9,21 @@ var kia_hitter = [
['류지혁', 0.259, 21, 3, 0, 0],
['한승택', 0.259, 15, 3, 0, 0],
['이창진', 0.254, 18, 5, 0, 0],
['박찬호', 0.237, 28, 5, 2, 0],
['최형우', 0.2, 18, 0, 0, 4],
['나지완', 0.184, 9, 1, 0, 0],
['김호령', 0.163, 7, 2, 0, 1],
]
var kia_pitcher = [
['선수명', '볼넷%', '피안타율'],
['브룩스', 5.3, 0.317],
['멩덴', 10, 0.243],
['이의리', 12, 0.202]
['브룩스', 5.3, 0.317],
['멩덴', 10, 0.243],
['이의리', 12, 0.202],
['이승재', 7.3, 0.277],
['박진태', 8.9, 0.218],
['임기영', 10.1, 0.287],
['박준표', 16.7, 0.366],
['장민기', 25.9, 0.105],
['김유신', 16.2, 0.269],
['정해영', 18.5, 0.210],
['장현식', 19, 0.26],
]
var kia_hitter_shuffle = []
......
......@@ -8,9 +8,10 @@
<script src = "algorithm.js"></script>
<script src = "shuffle_list.js"></script>
<script src = "aaaa.js"></script>
<script src = "temp_algorithm.js"></script>
<script>
var wonjung=6;
var home=8;
var wonjung=8;
var home=6;
function imgchange1(a){
var img=document.getElementById("wonjung");
if(a==1){
......@@ -97,6 +98,7 @@
img.setAttribute("src","pngs/Lotte.png");
}
}
</script>
</head>
<body>
......@@ -178,17 +180,17 @@
</div>
<div class="container3">
<div class="l">
<img src="pngs/dusan.png" id="wonjung" class="vs" style="margin:0px 0px 0px 50px;">
<img src="pngs/kia.png" id="wonjung" class="vs" style="margin:0px 0px 0px 50px;">
</div>
<div class="l">
<p id="vss">VS</p>
</div>
<div class="l">
<img src="pngs/kia.png" id="home" class="vs">
<img src="pngs/dusan.png" id="home" class="vs">
</div>
<div class="simul">
<div class="but">
<input type="button" onclick=aaaa() class="simulbtr" value="시뮬레이션">
<input type="button" onclick=pre_algorithm() class="simulbtr" value="시뮬레이션">
</div>
<div class="result">
......
function pre_algorithm(){//algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2) => html에서 가지고와야 한다.
var base1 = 0; var base2 = 0; var base3 = 0; //1이면 주자 있고 0이면 비어있는것
var out = 0; var ining = 1; var home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2.
var score1 = 0; var score2 = 0;
var hitter_num1 = 1; var hitter_num2 = 1;
var hit=false;
document.getElementById('jstest').innerHTML="";
while(true){
if(ining == 9 && home_away == 2 && score1 < score2){//9회 초 후 home팀이 이기고 있을 때!
break;
}
else if(ining==10 && home_away==1 && score1>score2 && hit==false){//9회 말 후 home팀이 이기고 있을 때!
break;
}
else if(ining>9 && score1 < score2){//9회 말 후 home팀이 이기고 있을 때!
break;
}
else if(ining>=11 && home_away==1 && hit==false && score1>score2){//연장 이후 원정팀이 이기고 있을 때!
break;
}
else if(ining>=10 && home_away==2 && hit==true && score1<score2){//끝내기
break;
}
else if(ining==13 && score1==score2){//무승부
break;
}
if(home_away == 1){
var hitter = kia_hitter[hitter_num1]; //hitter = hitter_list1[hitter_number1%9]
var pitcher = dusan_pitcher[1]; //pitcher = pitcher1
document.getElementById('jstest').innerHTML+=(ining+ "회 초"+ "<br\><br\>");
}
else if(home_away == 2){
var hitter = dusan_hitter[hitter_num2]; //hitter = hitter_list2[hitter_number2%9]
var pitcher = kia_pitcher[1]; //pitcher = pitcher2
document.getElementById('jstest').innerHTML+=(ining+ "회 말"+ "<br\><br\>");
}
var num = Math.random();
//hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
if(home_away == 1){
document.getElementById('jstest').innerHTML+=(hitter_num1+"번 타자: "+hitter[0]+ "<br\><br\>");
}
else if(home_away == 2){
document.getElementById('jstest').innerHTML+=(hitter_num2+"번 타자: "+hitter[0]+ "<br\><br\>");
}
var one = 0; var two = 0; var three = 0; var homerun = 0;
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];
hit=true;
if(num <= one){ //안타
var num1 = Math.random();
if(num1 <= 0.5){
switch(home_away){
case 1:
score1 = score1 + base3;
break;
case 2:
score2 = score2 + base3;
break;
}
base3 = base2;
base2 = base1;
base1 = 1;
document.getElementById('jstest').innerHTML+=("1루타!");
}
else{
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = base1;
base2 = 0;
base1 = 1;
document.getElementById('jstest').innerHTML+=("1루타!");
}
}
else if((one < num) && (num <= one + two)){//2루타
var num2 = Math.random();
if(num2 <= 0.4){
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = base1;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
if(0.4 < num2 && num2 <=0.7){
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
else{
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
}
else if((one + two < num) && (num <= one + two + three)){//3루타
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 1;
base2 = 0;
base1 = 0;
document.getElementById('jstest').innerHTML+=("3루타!");
}
else if(one + two + three < num && num <= one + two + three + homerun){//홈런
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1 + 1;
break;
case 2:
score2 = score2 + base3 + base2 + base1 + 1;
break;
}
base3 = 0;
base2 = 0;
base1 = 0;
document.getElementById('jstest').innerHTML+=("홈런!");
}
else if( pitcher[2] < num && (num <= pitcher[2] +pitcher[1]*0.01)){//볼넷
if(base1==1 && base2==1 && base3==1){
if(home_away==1){
score1++;
}
else{
score2++;
}
}
else{
if((base2==1 && base1==0 )||(base3==1 && base1==0)){
base1=1;
}
else{
base3 = base2;
base2 = base1;
base1 = 1;
}
}
document.getElementById('jstest').innerHTML+=("볼넷!");
}
else{//아웃
out++;
document.getElementById('jstest').innerHTML+=("아웃!");
}
document.getElementById('jstest').innerHTML+=("베이스 상태"+"<br\>"+ "1루 " + base1 + "<br\>"+"2루 " + base2 + "<br\>"+
"3루 " + base3 + "<br\><br\>");///////////////////////////
document.getElementById('jstest').innerHTML+=("score: "+score1 +"vs"+score2+ "<br\>");
document.getElementById('jstest').innerHTML+=("아웃카운트: "+out+"<br\><br\>");
if(out >= 3){
switch(home_away){
case 1:
home_away = 2;
hit=false;
break;
case 2:
home_away = 1;
ining++;
hit=false;
break;
}
out=0;
base1=0; base2=0; base3=0;
}
else{
if(home_away == 1){
hitter_num1++;
if(hitter_num1>=10){
hitter_num1=1;
}
}
else if(home_away == 2){
hitter_num2++;
if(hitter_num2>=10){
hitter_num2=1;
}
}
}
}
document.getElementById('jstest').innerHTML+=("<br\><br\>"+"최종스코어 : "+score1+"vs"+score2);
}
\ No newline at end of file