algorithm.TXT
6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function algorithm(){
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;
for(i = 0; i < 10; i++){
var num = Math.random();
document.write(num, "<br><br>");//////////////////////
//hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
hitter = kia_hitter[1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다.
document.write(hitter[0], "<br><br>")
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.write("확률" + "<br>" + "1루타 " + one, "<br>","2루타 " +
two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");//////////////////////////////
if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능
var num1 = Math.random();
if(num1 <= 0.5){
score = score + base3;
base3 = base2;
base2 = base1;
base1 = 1;
document.write("1루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
if(num1 > 0.5){
score = score + base3 + base2;
base3 = base1;
base2 = 0;
base1 = 1;
document.write("1루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
}
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.write("2루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
if(0.4 < num2 && num2 <=0.7){
score = score + base3 + base2 + base1;
base3 = 0;
base2 = 1;
base1 = 0;
document.write("2루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
if(0.7 < num2 && num2 <= 1){
score = score + base3 + base2;
base3 = 0;
base2 = 1;
base1 = 0;
out++;
document.write("2루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
}
else if(one + two < num && num <= one + two + three){
score = score + base3 + base2 + base1;
base3 = 1;
base2 = 0;
base1 = 0;
document.write("3루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
else if(one + two + three < num && num <= one + two + three + homerun){
score = score + base3 + base2 + base1 + 1;
base3 = 0;
base2 = 0;
base1 = 0;
document.write("홈런!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
}
if( kia_pitcher[1][2] < num && num <= kia_pitcher[1][2] + kia_pitcher[1][1]*0.01){
base3 = base2;
base2 = base1;
base1 = 1;
document.write("볼넷!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
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.write("아웃!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
}
}