Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-open-source
/
BaseBallSimulator
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김건우
2021-06-04 20:46:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d90fdeadb77e1f2adabb609261be3645007f43d7
d90fdead
1 parent
d3e7d32c
algorithm v.3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
14 deletions
algorithm.js
algorithm.js
View file @
d90fdea
function
algorithm
(){
var
pitcher
=
kia_pitcher
[
1
];
//선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다.
function
algorithm
(){
//algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2) => html에서 가지고와야 한다.
var
base1
=
0
;
base2
=
0
;
base3
=
0
;
//1이면 주자 있고 0이면 비어있는것
var
out
=
0
;
ining
=
1
;
//아웃카운트, 이닝
var
out
=
0
;
ining
=
1
;
home_away
=
1
;
//아웃카운트, 이닝, home이면 1이고 away이면 2.
var
hitter_number1
=
0
;
hitter_number2
=
0
;
//이전 타석 타자 번호
var
score
=
0
;
score2
=
0
;
for
(
i
=
0
;
i
<
10
;
i
++
){
while
(
true
){
document
.
write
(
ining
,
'회'
,
"<br><br>"
);
if
(
ining
>=
9
&&
home_away
==
2
&&
score1
!=
score2
){
score
=
[]
score
.
push
(
score1
);
score
.
push
(
score2
);
return
score
;
}
if
(
home_away
==
1
){
var
hitter
=
kia_hitter
[
hitter_number1
%
9
];
//hitter = hitter_list1[hitter_number1%9]
var
pitcher
=
dusan_pitcher
[
1
];
//pitcher = pitcher1
}
else
if
(
home_away
==
2
){
var
hitter
=
dusan_hitter
[
hitter_number2
%
9
];
//hitter = hitter_list2[hitter_number2%9]
var
pitcher
=
kia_pitcher
[
1
];
//pitcher = pitcher2
}
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
]){
...
...
@@ -19,10 +31,17 @@ function algorithm(){
document
.
write
(
"확률"
+
"<br>"
+
"1루타 "
+
one
,
"<br>"
,
"2루타 "
+
two
,
"<br>"
,
"3루타 "
+
three
,
"<br>"
,
"홈런 "
+
homerun
,
"<br><br>"
);
//////////////////////////////
if
(
num
<=
one
){
//
그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능
if
(
num
<=
one
){
//
안타
var
num1
=
Math
.
random
();
if
(
num1
<=
0.5
){
score
=
score
+
base3
;
switch
(
home_away
){
case
home_away
==
1
:
score1
=
score1
+
base3
;
hitter_number1
++
;
case
home_away
==
2
:
score2
=
score2
+
base3
;
hitter_number2
++
;
}
base3
=
base2
;
base2
=
base1
;
base1
=
1
;
...
...
@@ -32,7 +51,14 @@ function algorithm(){
document
.
write
(
"score: "
+
score
+
"<br><br><br>"
)
}
if
(
num1
>
0.5
){
score
=
score
+
base3
+
base2
;
switch
(
home_away
){
case
home_away
==
1
:
score1
=
score1
+
base3
+
base2
;
hitter_number1
++
;
case
home_away
==
2
:
score2
=
score2
+
base3
+
base2
;
hitter_number2
++
;
}
base3
=
base1
;
base2
=
0
;
base1
=
1
;
...
...
@@ -43,10 +69,17 @@ function algorithm(){
}
}
else
if
(
one
<
num
&&
num
<=
one
+
two
){
else
if
(
one
<
num
&&
num
<=
one
+
two
){
//2루타
var
num2
=
Math
.
random
();
if
(
num2
<=
0.4
){
score
=
score
+
base3
+
base2
;
switch
(
home_away
){
case
home_away
==
1
:
score1
=
score1
+
base3
+
base2
;
hitter_number1
++
;
case
home_away
==
2
:
score2
=
score2
+
base3
+
base2
;
hitter_number2
++
;
}
base3
=
base1
;
base2
=
1
;
base1
=
0
;
...
...
@@ -56,7 +89,14 @@ function algorithm(){
document
.
write
(
"score: "
+
score
+
"<br><br><br>"
)
}
if
(
0.4
<
num2
&&
num2
<=
0.7
){
score
=
score
+
base3
+
base2
+
base1
;
switch
(
home_away
){
case
home_away
==
1
:
score1
=
score1
+
base3
+
base2
+
base1
;
hitter_number1
++
;
case
home_away
==
2
:
score2
=
score2
+
base3
+
base2
+
base1
;
hitter_number2
++
;
}
base3
=
0
;
base2
=
1
;
base1
=
0
;
...
...
@@ -66,11 +106,22 @@ function algorithm(){
document
.
write
(
"score: "
+
score
+
"<br><br><br>"
)
}
if
(
0.7
<
num2
&&
num2
<=
1
){
if
(
base1
==
1
){
out
++
;
}
switch
(
home_away
){
case
home_away
==
1
:
score1
=
score1
+
base3
+
base2
;
hitter_number1
++
;
case
home_away
==
2
:
score2
=
score2
+
base3
+
base2
;
hitter_number2
++
;
}
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>"
)
///////////////////////////
...
...
@@ -78,7 +129,7 @@ function algorithm(){
}
}
else
if
(
one
+
two
<
num
&&
num
<=
one
+
two
+
three
){
else
if
(
one
+
two
<
num
&&
num
<=
one
+
two
+
three
){
//3루타
score
=
score
+
base3
+
base2
+
base1
;
base3
=
1
;
base2
=
0
;
...
...
@@ -88,7 +139,7 @@ function algorithm(){
"3루 "
+
base3
+
"<br><br>"
)
///////////////////////////
document
.
write
(
"score: "
+
score
+
"<br><br><br>"
)
}
else
if
(
one
+
two
+
three
<
num
&&
num
<=
one
+
two
+
three
+
homerun
){
else
if
(
one
+
two
+
three
<
num
&&
num
<=
one
+
two
+
three
+
homerun
){
//홈런
score
=
score
+
base3
+
base2
+
base1
+
1
;
base3
=
0
;
base2
=
0
;
...
...
@@ -113,6 +164,13 @@ function algorithm(){
if
(
out
>=
3
){
hitter
=
dusan_hitter
[
1
];
pitcher
=
dusan_pitcher
[
1
];
switch
(
home_away
){
case
home_away
==
1
:
home_away
++
;
case
home_away
==
2
:
home_away
=
1
;
ining
++
;
}
break
;
}
document
.
write
(
"아웃!"
)
...
...
Please
register
or
login
to post a comment