Showing
1 changed file
with
72 additions
and
14 deletions
1 | -function algorithm(){ | 1 | +function algorithm(){//algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2) => html에서 가지고와야 한다. |
2 | - var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다. | ||
3 | var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것 | 2 | var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것 |
4 | - var out = 0; ining = 1; //아웃카운트, 이닝 | 3 | + var out = 0; ining = 1; home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2. |
5 | var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호 | 4 | var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호 |
6 | var score = 0; score2 = 0; | 5 | var score = 0; score2 = 0; |
7 | - for(i = 0; i < 10; i++){ | 6 | + while(true){ |
7 | + document.write(ining, '회', "<br><br>"); | ||
8 | + if(ining >= 9 && home_away == 2 && score1 != score2){ | ||
9 | + score = [] | ||
10 | + score.push(score1); score.push(score2); | ||
11 | + return score; | ||
12 | + } | ||
13 | + if(home_away == 1){ | ||
14 | + var hitter = kia_hitter[hitter_number1%9]; //hitter = hitter_list1[hitter_number1%9] | ||
15 | + var pitcher = dusan_pitcher[1]; //pitcher = pitcher1 | ||
16 | + } | ||
17 | + else if(home_away == 2){ | ||
18 | + var hitter = dusan_hitter[hitter_number2%9]; //hitter = hitter_list2[hitter_number2%9] | ||
19 | + var pitcher = kia_pitcher[1]; //pitcher = pitcher2 | ||
20 | + } | ||
8 | var num = Math.random(); | 21 | var num = Math.random(); |
9 | document.write(num, "<br><br>");////////////////////// | 22 | document.write(num, "<br><br>");////////////////////// |
10 | //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan); | 23 | //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan); |
11 | - hitter = kia_hitter[1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다. | ||
12 | document.write(hitter[0], "<br><br>") | 24 | document.write(hitter[0], "<br><br>") |
13 | var one = 0; var two = 0; var three = 0; var homerun = 0; | 25 | var one = 0; var two = 0; var three = 0; var homerun = 0; |
14 | if( num <= kia_pitcher[1][2]){ | 26 | if( num <= kia_pitcher[1][2]){ |
... | @@ -19,10 +31,17 @@ function algorithm(){ | ... | @@ -19,10 +31,17 @@ function algorithm(){ |
19 | document.write("확률" + "<br>" + "1루타 " + one, "<br>","2루타 " + | 31 | document.write("확률" + "<br>" + "1루타 " + one, "<br>","2루타 " + |
20 | two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");////////////////////////////// | 32 | two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");////////////////////////////// |
21 | 33 | ||
22 | - if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능 | 34 | + if(num <= one){ //안타 |
23 | var num1 = Math.random(); | 35 | var num1 = Math.random(); |
24 | if(num1 <= 0.5){ | 36 | if(num1 <= 0.5){ |
25 | - score = score + base3; | 37 | + switch(home_away){ |
38 | + case home_away == 1: | ||
39 | + score1 = score1 + base3; | ||
40 | + hitter_number1++; | ||
41 | + case home_away == 2: | ||
42 | + score2 = score2 + base3; | ||
43 | + hitter_number2++; | ||
44 | + } | ||
26 | base3 = base2; | 45 | base3 = base2; |
27 | base2 = base1; | 46 | base2 = base1; |
28 | base1 = 1; | 47 | base1 = 1; |
... | @@ -32,7 +51,14 @@ function algorithm(){ | ... | @@ -32,7 +51,14 @@ function algorithm(){ |
32 | document.write("score: "+score+ "<br><br><br>") | 51 | document.write("score: "+score+ "<br><br><br>") |
33 | } | 52 | } |
34 | if(num1 > 0.5){ | 53 | if(num1 > 0.5){ |
35 | - score = score + base3 + base2; | 54 | + switch(home_away){ |
55 | + case home_away == 1: | ||
56 | + score1 = score1 + base3 + base2; | ||
57 | + hitter_number1++; | ||
58 | + case home_away == 2: | ||
59 | + score2 = score2 + base3 + base2; | ||
60 | + hitter_number2++; | ||
61 | + } | ||
36 | base3 = base1; | 62 | base3 = base1; |
37 | base2 = 0; | 63 | base2 = 0; |
38 | base1 = 1; | 64 | base1 = 1; |
... | @@ -43,10 +69,17 @@ function algorithm(){ | ... | @@ -43,10 +69,17 @@ function algorithm(){ |
43 | } | 69 | } |
44 | 70 | ||
45 | } | 71 | } |
46 | - else if(one < num && num <= one + two){ | 72 | + else if(one < num && num <= one + two){//2루타 |
47 | var num2 = Math.random(); | 73 | var num2 = Math.random(); |
48 | if(num2 <= 0.4){ | 74 | if(num2 <= 0.4){ |
49 | - score = score + base3 + base2; | 75 | + switch(home_away){ |
76 | + case home_away == 1: | ||
77 | + score1 = score1 + base3 + base2; | ||
78 | + hitter_number1++; | ||
79 | + case home_away == 2: | ||
80 | + score2 = score2 + base3 + base2; | ||
81 | + hitter_number2++; | ||
82 | + } | ||
50 | base3 = base1; | 83 | base3 = base1; |
51 | base2 = 1; | 84 | base2 = 1; |
52 | base1 = 0; | 85 | base1 = 0; |
... | @@ -56,7 +89,14 @@ function algorithm(){ | ... | @@ -56,7 +89,14 @@ function algorithm(){ |
56 | document.write("score: "+score+ "<br><br><br>") | 89 | document.write("score: "+score+ "<br><br><br>") |
57 | } | 90 | } |
58 | if(0.4 < num2 && num2 <=0.7){ | 91 | if(0.4 < num2 && num2 <=0.7){ |
59 | - score = score + base3 + base2 + base1; | 92 | + switch(home_away){ |
93 | + case home_away == 1: | ||
94 | + score1 = score1 + base3 + base2 + base1; | ||
95 | + hitter_number1++; | ||
96 | + case home_away == 2: | ||
97 | + score2 = score2 + base3 + base2 + base1; | ||
98 | + hitter_number2++; | ||
99 | + } | ||
60 | base3 = 0; | 100 | base3 = 0; |
61 | base2 = 1; | 101 | base2 = 1; |
62 | base1 = 0; | 102 | base1 = 0; |
... | @@ -66,11 +106,22 @@ function algorithm(){ | ... | @@ -66,11 +106,22 @@ function algorithm(){ |
66 | document.write("score: "+score+ "<br><br><br>") | 106 | document.write("score: "+score+ "<br><br><br>") |
67 | } | 107 | } |
68 | if(0.7 < num2 && num2 <= 1){ | 108 | if(0.7 < num2 && num2 <= 1){ |
109 | + if(base1 == 1){ | ||
110 | + out++; | ||
111 | + } | ||
112 | + switch(home_away){ | ||
113 | + case home_away == 1: | ||
114 | + score1 = score1 + base3 + base2; | ||
115 | + hitter_number1++; | ||
116 | + case home_away == 2: | ||
117 | + score2 = score2 + base3 + base2; | ||
118 | + hitter_number2++; | ||
119 | + } | ||
69 | score = score + base3 + base2; | 120 | score = score + base3 + base2; |
70 | base3 = 0; | 121 | base3 = 0; |
71 | base2 = 1; | 122 | base2 = 1; |
72 | base1 = 0; | 123 | base1 = 0; |
73 | - out++; | 124 | + |
74 | document.write("2루타!") | 125 | document.write("2루타!") |
75 | document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | 126 | document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", |
76 | "3루 " + base3 + "<br><br>")/////////////////////////// | 127 | "3루 " + base3 + "<br><br>")/////////////////////////// |
... | @@ -78,7 +129,7 @@ function algorithm(){ | ... | @@ -78,7 +129,7 @@ function algorithm(){ |
78 | } | 129 | } |
79 | 130 | ||
80 | } | 131 | } |
81 | - else if(one + two < num && num <= one + two + three){ | 132 | + else if(one + two < num && num <= one + two + three){//3루타 |
82 | score = score + base3 + base2 + base1; | 133 | score = score + base3 + base2 + base1; |
83 | base3 = 1; | 134 | base3 = 1; |
84 | base2 = 0; | 135 | base2 = 0; |
... | @@ -88,7 +139,7 @@ function algorithm(){ | ... | @@ -88,7 +139,7 @@ function algorithm(){ |
88 | "3루 " + base3 + "<br><br>")/////////////////////////// | 139 | "3루 " + base3 + "<br><br>")/////////////////////////// |
89 | document.write("score: "+score+ "<br><br><br>") | 140 | document.write("score: "+score+ "<br><br><br>") |
90 | } | 141 | } |
91 | - else if(one + two + three < num && num <= one + two + three + homerun){ | 142 | + else if(one + two + three < num && num <= one + two + three + homerun){//홈런 |
92 | score = score + base3 + base2 + base1 + 1; | 143 | score = score + base3 + base2 + base1 + 1; |
93 | base3 = 0; | 144 | base3 = 0; |
94 | base2 = 0; | 145 | base2 = 0; |
... | @@ -113,6 +164,13 @@ function algorithm(){ | ... | @@ -113,6 +164,13 @@ function algorithm(){ |
113 | if(out >= 3){ | 164 | if(out >= 3){ |
114 | hitter = dusan_hitter[1]; | 165 | hitter = dusan_hitter[1]; |
115 | pitcher = dusan_pitcher[1]; | 166 | pitcher = dusan_pitcher[1]; |
167 | + switch(home_away){ | ||
168 | + case home_away == 1: | ||
169 | + home_away++; | ||
170 | + case home_away == 2: | ||
171 | + home_away = 1; | ||
172 | + ining++; | ||
173 | + } | ||
116 | break; | 174 | break; |
117 | } | 175 | } |
118 | document.write("아웃!") | 176 | document.write("아웃!") | ... | ... |
-
Please register or login to post a comment