정주희

simulation_kia_vs_dusan

1 var dusan_hitter = [ 1 var dusan_hitter = [
2 -['선수명', 'AVG', 'H', '2B', '3B', 'HR'] 2 +['선수명', 'AVG', 'H', '2B', '3B', 'HR'],
3 ['박건우', 0.356, 47, 9, 0, 2], 3 ['박건우', 0.356, 47, 9, 0, 2],
4 ['허경민', 0.345, 49, 6, 0, 3], 4 ['허경민', 0.345, 49, 6, 0, 3],
5 ['페르난데스', 0.336, 48, 5, 0, 6], 5 ['페르난데스', 0.336, 48, 5, 0, 6],
...@@ -9,19 +9,10 @@ var dusan_hitter = [ ...@@ -9,19 +9,10 @@ var dusan_hitter = [
9 ['김재환', 0.285, 37, 4, 1, 9], 9 ['김재환', 0.285, 37, 4, 1, 9],
10 ['장승현', 0.284, 23, 1, 0, 1], 10 ['장승현', 0.284, 23, 1, 0, 1],
11 ['조수행', 0.278, 10, 1, 1, 0], 11 ['조수행', 0.278, 10, 1, 1, 0],
12 -['양석환', 0.277, 38, 8, 0, 5],
13 -['박계범', 0.266, 21, 5, 0, 2],
14 -['김재호', 0.243, 18, 1, 0, 1],
15 -['오재원', 0.22, 11, 2, 0, 0],
16 -['강승호', 0.212, 7, 0, 0, 2],
17 -['권민석', 0.167, 2, 1, 0, 0],
18 -['박세혁', 0.161, 5, 0, 0, 0],
19 -['안권수', 0.133, 2, 0, 0, 0],
20 -['정수빈', 0.125, 4, 1, 0, 0]
21 ] 12 ]
22 13
23 var dusan_pitcher = [ 14 var dusan_pitcher = [
24 -['선수명', '볼넷%', '피안타율'] 15 +['선수명', '볼넷%', '피안타율'],
25 ['로켓', 7.7, 0.267], 16 ['로켓', 7.7, 0.267],
26 ['미란다', 15.3, 0.259], 17 ['미란다', 15.3, 0.259],
27 ['최원준', 5.7, 0.215], 18 ['최원준', 5.7, 0.215],
......
...@@ -9,17 +9,21 @@ var kia_hitter = [ ...@@ -9,17 +9,21 @@ var kia_hitter = [
9 ['류지혁', 0.259, 21, 3, 0, 0], 9 ['류지혁', 0.259, 21, 3, 0, 0],
10 ['한승택', 0.259, 15, 3, 0, 0], 10 ['한승택', 0.259, 15, 3, 0, 0],
11 ['이창진', 0.254, 18, 5, 0, 0], 11 ['이창진', 0.254, 18, 5, 0, 0],
12 -['박찬호', 0.237, 28, 5, 2, 0],
13 -['최형우', 0.2, 18, 0, 0, 4],
14 -['나지완', 0.184, 9, 1, 0, 0],
15 -['김호령', 0.163, 7, 2, 0, 1],
16 ] 12 ]
17 13
18 var kia_pitcher = [ 14 var kia_pitcher = [
19 ['선수명', '볼넷%', '피안타율'], 15 ['선수명', '볼넷%', '피안타율'],
20 - ['브룩스', 5.3, 0.317], 16 + ['브룩스', 5.3, 0.317],
21 - ['멩덴', 10, 0.243], 17 + ['멩덴', 10, 0.243],
22 - ['이의리', 12, 0.202] 18 + ['이의리', 12, 0.202],
19 + ['이승재', 7.3, 0.277],
20 + ['박진태', 8.9, 0.218],
21 + ['임기영', 10.1, 0.287],
22 + ['박준표', 16.7, 0.366],
23 + ['장민기', 25.9, 0.105],
24 + ['김유신', 16.2, 0.269],
25 + ['정해영', 18.5, 0.210],
26 + ['장현식', 19, 0.26],
23 ] 27 ]
24 28
25 var kia_hitter_shuffle = [] 29 var kia_hitter_shuffle = []
......
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
8 <script src = "algorithm.js"></script> 8 <script src = "algorithm.js"></script>
9 <script src = "shuffle_list.js"></script> 9 <script src = "shuffle_list.js"></script>
10 <script src = "aaaa.js"></script> 10 <script src = "aaaa.js"></script>
11 + <script src = "temp_algorithm.js"></script>
11 <script> 12 <script>
12 - var wonjung=6; 13 + var wonjung=8;
13 - var home=8; 14 + var home=6;
14 function imgchange1(a){ 15 function imgchange1(a){
15 var img=document.getElementById("wonjung"); 16 var img=document.getElementById("wonjung");
16 if(a==1){ 17 if(a==1){
...@@ -97,6 +98,7 @@ ...@@ -97,6 +98,7 @@
97 img.setAttribute("src","pngs/Lotte.png"); 98 img.setAttribute("src","pngs/Lotte.png");
98 } 99 }
99 } 100 }
101 +
100 </script> 102 </script>
101 </head> 103 </head>
102 <body> 104 <body>
...@@ -178,17 +180,17 @@ ...@@ -178,17 +180,17 @@
178 </div> 180 </div>
179 <div class="container3"> 181 <div class="container3">
180 <div class="l"> 182 <div class="l">
181 - <img src="pngs/dusan.png" id="wonjung" class="vs" style="margin:0px 0px 0px 50px;"> 183 + <img src="pngs/kia.png" id="wonjung" class="vs" style="margin:0px 0px 0px 50px;">
182 </div> 184 </div>
183 <div class="l"> 185 <div class="l">
184 <p id="vss">VS</p> 186 <p id="vss">VS</p>
185 </div> 187 </div>
186 <div class="l"> 188 <div class="l">
187 - <img src="pngs/kia.png" id="home" class="vs"> 189 + <img src="pngs/dusan.png" id="home" class="vs">
188 </div> 190 </div>
189 <div class="simul"> 191 <div class="simul">
190 <div class="but"> 192 <div class="but">
191 - <input type="button" onclick=aaaa() class="simulbtr" value="시뮬레이션"> 193 + <input type="button" onclick=pre_algorithm() class="simulbtr" value="시뮬레이션">
192 </div> 194 </div>
193 <div class="result"> 195 <div class="result">
194 196
......
1 +function pre_algorithm(){//algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2) => html에서 가지고와야 한다.
2 + var base1 = 0; var base2 = 0; var base3 = 0; //1이면 주자 있고 0이면 비어있는것
3 + var out = 0; var ining = 1; var home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2.
4 + var score1 = 0; var score2 = 0;
5 + var hitter_num1 = 1; var hitter_num2 = 1;
6 + var hit=false;
7 + document.getElementById('jstest').innerHTML="";
8 + while(true){
9 + if(ining == 9 && home_away == 2 && score1 < score2){//9회 초 후 home팀이 이기고 있을 때!
10 + break;
11 + }
12 + else if(ining==10 && home_away==1 && score1>score2 && hit==false){//9회 말 후 home팀이 이기고 있을 때!
13 + break;
14 + }
15 + else if(ining>9 && score1 < score2){//9회 말 후 home팀이 이기고 있을 때!
16 + break;
17 + }
18 + else if(ining>=11 && home_away==1 && hit==false && score1>score2){//연장 이후 원정팀이 이기고 있을 때!
19 + break;
20 + }
21 + else if(ining>=10 && home_away==2 && hit==true && score1<score2){//끝내기
22 + break;
23 + }
24 + else if(ining==13 && score1==score2){//무승부
25 + break;
26 + }
27 +
28 + if(home_away == 1){
29 + var hitter = kia_hitter[hitter_num1]; //hitter = hitter_list1[hitter_number1%9]
30 + var pitcher = dusan_pitcher[1]; //pitcher = pitcher1
31 + document.getElementById('jstest').innerHTML+=(ining+ "회 초"+ "<br\><br\>");
32 + }
33 + else if(home_away == 2){
34 + var hitter = dusan_hitter[hitter_num2]; //hitter = hitter_list2[hitter_number2%9]
35 + var pitcher = kia_pitcher[1]; //pitcher = pitcher2
36 + document.getElementById('jstest').innerHTML+=(ining+ "회 말"+ "<br\><br\>");
37 + }
38 +
39 + var num = Math.random();
40 + //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
41 + if(home_away == 1){
42 + document.getElementById('jstest').innerHTML+=(hitter_num1+"번 타자: "+hitter[0]+ "<br\><br\>");
43 + }
44 + else if(home_away == 2){
45 + document.getElementById('jstest').innerHTML+=(hitter_num2+"번 타자: "+hitter[0]+ "<br\><br\>");
46 + }
47 + var one = 0; var two = 0; var three = 0; var homerun = 0;
48 + one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2];
49 + two = pitcher[2] * hitter[3]/hitter[2];
50 + three = pitcher[2] * hitter[4]/hitter[2];
51 + homerun = pitcher[2] * hitter[5]/hitter[2];
52 + hit=true;
53 + if(num <= one){ //안타
54 + var num1 = Math.random();
55 + if(num1 <= 0.5){
56 + switch(home_away){
57 + case 1:
58 + score1 = score1 + base3;
59 + break;
60 + case 2:
61 + score2 = score2 + base3;
62 + break;
63 + }
64 + base3 = base2;
65 + base2 = base1;
66 + base1 = 1;
67 + document.getElementById('jstest').innerHTML+=("1루타!");
68 +
69 + }
70 + else{
71 + switch(home_away){
72 + case 1:
73 + score1 = score1 + base3 + base2;
74 + break;
75 + case 2:
76 + score2 = score2 + base3 + base2;
77 + break;
78 + }
79 + base3 = base1;
80 + base2 = 0;
81 + base1 = 1;
82 + document.getElementById('jstest').innerHTML+=("1루타!");
83 +
84 + }
85 +
86 + }
87 + else if((one < num) && (num <= one + two)){//2루타
88 + var num2 = Math.random();
89 + if(num2 <= 0.4){
90 + switch(home_away){
91 + case 1:
92 + score1 = score1 + base3 + base2;
93 + break;
94 + case 2:
95 + score2 = score2 + base3 + base2;
96 + break;
97 + }
98 + base3 = base1;
99 + base2 = 1;
100 + base1 = 0;
101 + document.getElementById('jstest').innerHTML+=("2루타!");
102 +
103 + }
104 + if(0.4 < num2 && num2 <=0.7){
105 + switch(home_away){
106 + case 1:
107 + score1 = score1 + base3 + base2 + base1;
108 + break;
109 + case 2:
110 + score2 = score2 + base3 + base2 + base1;
111 + break;
112 + }
113 + base3 = 0;
114 + base2 = 1;
115 + base1 = 0;
116 + document.getElementById('jstest').innerHTML+=("2루타!");
117 +
118 + }
119 + else{
120 + switch(home_away){
121 + case 1:
122 + score1 = score1 + base3 + base2;
123 + break;
124 + case 2:
125 + score2 = score2 + base3 + base2;
126 + break;
127 + }
128 + base3 = 0;
129 + base2 = 1;
130 + base1 = 0;
131 +
132 + document.getElementById('jstest').innerHTML+=("2루타!");
133 +
134 + }
135 +
136 + }
137 + else if((one + two < num) && (num <= one + two + three)){//3루타
138 + switch(home_away){
139 + case 1:
140 + score1 = score1 + base3 + base2 + base1;
141 + break;
142 + case 2:
143 + score2 = score2 + base3 + base2 + base1;
144 + break;
145 + }
146 + base3 = 1;
147 + base2 = 0;
148 + base1 = 0;
149 + document.getElementById('jstest').innerHTML+=("3루타!");
150 +
151 + }
152 + else if(one + two + three < num && num <= one + two + three + homerun){//홈런
153 + switch(home_away){
154 + case 1:
155 + score1 = score1 + base3 + base2 + base1 + 1;
156 + break;
157 + case 2:
158 + score2 = score2 + base3 + base2 + base1 + 1;
159 + break;
160 + }
161 + base3 = 0;
162 + base2 = 0;
163 + base1 = 0;
164 + document.getElementById('jstest').innerHTML+=("홈런!");
165 +
166 + }
167 +
168 +
169 + else if( pitcher[2] < num && (num <= pitcher[2] +pitcher[1]*0.01)){//볼넷
170 + if(base1==1 && base2==1 && base3==1){
171 + if(home_away==1){
172 + score1++;
173 + }
174 + else{
175 + score2++;
176 + }
177 + }
178 + else{
179 + if((base2==1 && base1==0 )||(base3==1 && base1==0)){
180 + base1=1;
181 + }
182 + else{
183 + base3 = base2;
184 + base2 = base1;
185 + base1 = 1;
186 + }
187 + }
188 + document.getElementById('jstest').innerHTML+=("볼넷!");
189 + }
190 +
191 + else{//아웃
192 + out++;
193 + document.getElementById('jstest').innerHTML+=("아웃!");
194 +
195 + }
196 +
197 + document.getElementById('jstest').innerHTML+=("베이스 상태"+"<br\>"+ "1루 " + base1 + "<br\>"+"2루 " + base2 + "<br\>"+
198 + "3루 " + base3 + "<br\><br\>");///////////////////////////
199 + document.getElementById('jstest').innerHTML+=("score: "+score1 +"vs"+score2+ "<br\>");
200 + document.getElementById('jstest').innerHTML+=("아웃카운트: "+out+"<br\><br\>");
201 + if(out >= 3){
202 + switch(home_away){
203 + case 1:
204 + home_away = 2;
205 + hit=false;
206 + break;
207 + case 2:
208 + home_away = 1;
209 + ining++;
210 + hit=false;
211 + break;
212 + }
213 + out=0;
214 + base1=0; base2=0; base3=0;
215 + }
216 + else{
217 + if(home_away == 1){
218 + hitter_num1++;
219 + if(hitter_num1>=10){
220 + hitter_num1=1;
221 + }
222 + }
223 + else if(home_away == 2){
224 + hitter_num2++;
225 + if(hitter_num2>=10){
226 + hitter_num2=1;
227 + }
228 + }
229 + }
230 +
231 + }
232 + document.getElementById('jstest').innerHTML+=("<br\><br\>"+"최종스코어 : "+score1+"vs"+score2);
233 +}
...\ No newline at end of file ...\ No newline at end of file