정주희

Update files about javascript

This diff is collapsed. Click to expand it.
1 +function add_predict(){
2 + var s="";
3 + s+=("<option value="+10+">"+10+"</option>");
4 + s+=("<option value="+20+">"+20+"</option>");
5 + s+=("<option value="+50+">"+50+"</option>");
6 + s+=("<option value="+70+">"+70+"</option>");
7 + s+=("<option value="+100+">"+100+"</option>");
8 + s+=("<option value="+500+">"+500+"</option>");
9 + s+=("<option value="+1000+">"+1000+"</option>");
10 + s+=("<option value="+5000+">"+5000+"</option>");
11 + s+=("<option value="+10000+">"+10000+"</option>");
12 + s+=("<option value="+50000+">"+50000+"</option>");
13 + s+=("<option value="+100000+">"+100000+"</option>");
14 + document.getElementById('pr').innerHTML=s;
15 +}
16 +
17 +function predict(value, hitter_list1, hitter_list2, pitcher1, pitcher2){
18 + var score=[0,0];
19 + var w=0;
20 + var h=0;
21 + var d=0;
22 + for(var i=0; i<value; i++){
23 + score=algorithms(hitter_list1, hitter_list2, pitcher1, pitcher2);
24 + if(score[0]>score[1]){
25 + w++;
26 + }else if(score[0]<score[1]){
27 + h++;
28 + }else{
29 + d++;
30 + }
31 + }
32 + document.getElementById('jstest').innerHTML="예측 결과"+"<br\>"+"TEST "+value+"번"+"<br\><br\>"+"원정팀 승리 횟수 : "+w+"<br\>"
33 + +"홈팀 승리 횟수 : "+h+"<br\>"+"무승부 횟수 : "+d+"<br\><br\>"+"원정팀 승리 확률 : "+w*100/value+"%"+"<br\>"+"홈팀 승리 확률 : "+h*100/value+"%"+"<br\>";
34 +}
35 +
36 +function algorithms(hitter_list1, hitter_list2, pitcher1, pitcher2){
37 + var base1 = 0; var base2 = 0; var base3 = 0; //1이면 주자 있고 0이면 비어있는것
38 + var out = 0; var ining = 1; var home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2.
39 + var score1 = 0; var score2 = 0;
40 + var hitter_num1 = 1; var hitter_num2 = 1;
41 + var hit=false;
42 + while(true){
43 + if(ining == 9 && home_away == 2 && score1 < score2){//9회 초 후 home팀이 이기고 있을 때!
44 + break;
45 + }
46 + else if(ining==10 && home_away==1 && score1>score2 && hit==false){//9회 말 후 home팀이 이기고 있을 때!
47 + break;
48 + }
49 + else if(ining>9 && score1 < score2){//9회 말 후 home팀이 이기고 있을 때!
50 + break;
51 + }
52 + else if(ining>=11 && home_away==1 && hit==false && score1>score2){//연장 이후 원정팀이 이기고 있을 때!
53 + break;
54 + }
55 + else if(ining>=10 && home_away==2 && hit==true && score1<score2){//끝내기
56 + break;
57 + }
58 + else if(ining==13 && score1==score2){//무승부
59 + break;
60 + }
61 +
62 + if(home_away == 1){
63 + var hitter = hitter_list1[hitter_num1]; //hitter = hitter_list1[hitter_number1%9]
64 + var pitcher = pitcher2; //pitcher = pitcher1
65 +
66 + }
67 + else if(home_away == 2){
68 + var hitter = hitter_list2[hitter_num2]; //hitter = hitter_list2[hitter_number2%9]
69 + var pitcher = pitcher1; //pitcher = pitcher2
70 +
71 + }
72 +
73 + var num = Math.random();
74 + //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
75 + var one = 0; var two = 0; var three = 0; var homerun = 0;
76 + one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2];
77 + two = pitcher[2] * hitter[3]/hitter[2];
78 + three = pitcher[2] * hitter[4]/hitter[2];
79 + homerun = pitcher[2] * hitter[5]/hitter[2];
80 + hit=true;
81 + if(num <= one){ //안타
82 + var num1 = Math.random();
83 + if(num1 <= 0.5){
84 + switch(home_away){
85 + case 1:
86 + score1 = score1 + base3;
87 + break;
88 + case 2:
89 + score2 = score2 + base3;
90 + break;
91 + }
92 + base3 = base2;
93 + base2 = base1;
94 + base1 = 1;
95 +
96 + }
97 + else{
98 + switch(home_away){
99 + case 1:
100 + score1 = score1 + base3 + base2;
101 + break;
102 + case 2:
103 + score2 = score2 + base3 + base2;
104 + break;
105 + }
106 + base3 = base1;
107 + base2 = 0;
108 + base1 = 1;
109 +
110 + }
111 +
112 + }
113 + else if((one < num) && (num <= one + two)){//2루타
114 + var num2 = Math.random();
115 + if(num2 <= 0.4){
116 + switch(home_away){
117 + case 1:
118 + score1 = score1 + base3 + base2;
119 + break;
120 + case 2:
121 + score2 = score2 + base3 + base2;
122 + break;
123 + }
124 + base3 = base1;
125 + base2 = 1;
126 + base1 = 0;
127 +
128 + }
129 + else if(0.4 < num2 && num2 <=0.7){
130 + switch(home_away){
131 + case 1:
132 + score1 = score1 + base3 + base2 + base1;
133 + break;
134 + case 2:
135 + score2 = score2 + base3 + base2 + base1;
136 + break;
137 + }
138 + base3 = 0;
139 + base2 = 1;
140 + base1 = 0;
141 +
142 + }
143 + else{
144 + switch(home_away){
145 + case 1:
146 + score1 = score1 + base3 + base2;
147 + break;
148 + case 2:
149 + score2 = score2 + base3 + base2;
150 + break;
151 + }
152 + base3 = 0;
153 + base2 = 1;
154 + base1 = 0;
155 +
156 + }
157 +
158 + }
159 + else if((one + two < num) && (num <= one + two + three)){//3루타
160 + switch(home_away){
161 + case 1:
162 + score1 = score1 + base3 + base2 + base1;
163 + break;
164 + case 2:
165 + score2 = score2 + base3 + base2 + base1;
166 + break;
167 + }
168 + base3 = 1;
169 + base2 = 0;
170 + base1 = 0;
171 +
172 + }
173 + else if(one + two + three < num && num <= one + two + three + homerun){//홈런
174 + switch(home_away){
175 + case 1:
176 + score1 = score1 + base3 + base2 + base1 + 1;
177 + break;
178 + case 2:
179 + score2 = score2 + base3 + base2 + base1 + 1;
180 + break;
181 + }
182 + base3 = 0;
183 + base2 = 0;
184 + base1 = 0;
185 +
186 + }
187 +
188 +
189 + else if( pitcher[2] < num && (num <= pitcher[2] +pitcher[1]*0.01)){//볼넷
190 + if(base1==1 && base2==1 && base3==1){//만루 밀어내기 득점 -> 스코어 ++
191 + if(home_away==1){
192 + score1++;
193 + }
194 + else{
195 + score2++;
196 + }
197 + }
198 + else{//스코어 추가되지 않는 경우
199 + if((base2==1 && base1==0 )||(base3==1 && base1==0)||(base2==1&&base3==1&&base1==0)){//2루만 채워져있거나 3루만 채워져있거나 2,3루만 채워져있거나
200 + base1=1;
201 + }
202 + else if(base1==1 && base3==1 && base2==0){//1루 3루 채워져있고 2루 비워져있거나
203 + base2=base1;
204 + base1=1;
205 + }
206 + else{
207 + base3 = base2;
208 + base2 = base1;
209 + base1 = 1;
210 + }
211 + }
212 +
213 + }
214 +
215 + else{//아웃
216 + out++;
217 +
218 + }
219 +
220 + if(out >= 3){
221 + switch(home_away){
222 + case 1:
223 + home_away = 2;
224 + hit=false;
225 + break;
226 + case 2:
227 + home_away = 1;
228 + ining++;
229 + hit=false;
230 + break;
231 + }
232 + out=0;
233 + base1=0; base2=0; base3=0;
234 + }
235 + else{
236 + if(home_away == 1){
237 + hitter_num1++;
238 + if(hitter_num1>=10){
239 + hitter_num1=1;
240 + }
241 + }
242 + else if(home_away == 2){
243 + hitter_num2++;
244 + if(hitter_num2>=10){
245 + hitter_num2=1;
246 + }
247 + }
248 + }
249 +
250 + }
251 + var score = [score1, score2];
252 + return score;
253 +}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.