김건우

algorithm v.1

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>일정</title>
<link rel="stylesheet" type="text/css"href="calander.css">
<script src = "kia.js"></script>
<script src = "algorithm.js"></script>
</head>
<body>
<div class = "container1">
<ul class = "image-container">
</ul>
<input type="button" onclick = algorithm() value = "start">
<img class = "please" src="player_picture/KIA/KIA_hitter/김호령.jpg" value="1">
</div>
<div class="container3">
</div>
</body>
</html>
\ No newline at end of file
/*var t = document.getElementById('image-container');
t.addEventListener('dragstart',function(event){
alert('please, '+event.target.value);
});*/
const container = document.querySelector(".please")
container.addEventListener('dragstart', e => {
console.log(e)
})
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[i+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){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능
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>")
}
else if(one < num && num <= one + two){
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>")
}
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){
exit(100);
}
document.write("아웃!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
}
}
\ No newline at end of file
var dusan_hitter = [
['선수명', 'AVG', 'H', '2B', '3B', 'HR']
['박건우', 0.356, 47, 9, 0, 2],
['허경민', 0.345, 49, 6, 0, 3],
['페르난데스', 0.336, 48, 5, 0, 6],
['최용제', 0.308, 8, 2, 0, 0],
['안재석', 0.304, 14, 1, 2, 0],
['김인태', 0.298, 25, 3, 0, 1],
['김재환', 0.285, 37, 4, 1, 9],
['장승현', 0.284, 23, 1, 0, 1],
['조수행', 0.278, 10, 1, 1, 0],
['양석환', 0.277, 38, 8, 0, 5],
['박계범', 0.266, 21, 5, 0, 2],
['김재호', 0.243, 18, 1, 0, 1],
['오재원', 0.22, 11, 2, 0, 0],
['강승호', 0.212, 7, 0, 0, 2],
['권민석', 0.167, 2, 1, 0, 0],
['박세혁', 0.161, 5, 0, 0, 0],
['안권수', 0.133, 2, 0, 0, 0],
['정수빈', 0.125, 4, 1, 0, 0]
]
var dusan_pitcher = [
['선수명', '볼넷%', '피안타율']
['로켓', 7.7, 0.267],
['미란다', 15.3, 0.259],
['최원준', 5.7, 0.215],
['홍건희', 12.5, 0.224],
['김강률', 13.8, 0.217],
['이승진', 7.2, 0.202],
['유희관', 7.7, 0.381],
['곽빈', 15.9, 0.291],
['김명신', 4.1, 0.303],
['조제영', 17.3, 0.286],
['김민규', 8.8, 0.3],
['박종기', 3.4, 0.236],
['이영하', 12.8, 0.388],
]
\ No newline at end of file
var kia_hitter = [
['선수명', 'AVG', 'H', '2B', '3B', 'HR'],
['김태진', 0.349, 22, 2, 1, 0],
['최원준', 0.342, 54, 2, 4, 0],
['이정훈', 0.293, 12, 2, 0, 1],
['김선빈', 0.292, 40, 8, 0, 0],
['터커', 0.265, 40, 9, 1, 2],
['김민식', 0.261, 18, 2, 0, 2],
['류지혁', 0.259, 21, 3, 0, 0],
['한승택', 0.259, 15, 3, 0, 0],
['이창진', 0.254, 18, 5, 0, 0],
['박찬호', 0.237, 28, 5, 2, 0],
['최형우', 0.2, 18, 0, 0, 4],
['나지완', 0.184, 9, 1, 0, 0],
['김호령', 0.163, 7, 2, 0, 1],
]
var kia_pitcher = [
['선수명', '볼넷%', '피안타율'],
['브룩스', 5.3, 0.317],
['멩덴', 10, 0.243],
['이의리', 12, 0.202]
]
\ No newline at end of file