김건우

algorithm v.1

1 +<!DOCTYPE html>
2 +<html lang="ko">
3 +<head>
4 + <meta charset="UTF-8">
5 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 + <title>일정</title>
7 + <link rel="stylesheet" type="text/css"href="calander.css">
8 + <script src = "kia.js"></script>
9 + <script src = "algorithm.js"></script>
10 +</head>
11 +<body>
12 + <div class = "container1">
13 + <ul class = "image-container">
14 +
15 + </ul>
16 + <input type="button" onclick = algorithm() value = "start">
17 + <img class = "please" src="player_picture/KIA/KIA_hitter/김호령.jpg" value="1">
18 + </div>
19 +
20 +
21 + <div class="container3">
22 +
23 + </div>
24 +</body>
25 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +/*var t = document.getElementById('image-container');
2 +t.addEventListener('dragstart',function(event){
3 + alert('please, '+event.target.value);
4 +});*/
5 +const container = document.querySelector(".please")
6 +container.addEventListener('dragstart', e => {
7 + console.log(e)
8 +})
9 +
10 +function algorithm(){
11 + var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다.
12 + var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것
13 + var out = 0; ining = 1; //아웃카운트, 이닝
14 + var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호
15 + var score = 0; score2 = 0;
16 + for(i = 0; i < 10; i++){
17 + var num = Math.random();
18 + document.write(num, "<br><br>");//////////////////////
19 + //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
20 + hitter = kia_hitter[i+1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다.
21 + document.write(hitter[0], "<br><br>")
22 + var one = 0; var two = 0; var three = 0; var homerun = 0;
23 + if( num <= kia_pitcher[1][2]){
24 +
25 + one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2];
26 + two = pitcher[2] * hitter[3]/hitter[2];
27 + three = pitcher[2] * hitter[4]/hitter[2];
28 + homerun = pitcher[2] * hitter[5]/hitter[2];
29 + document.write("확률" + "<br>" + "1루타 " + one, "<br>","2루타 " +
30 + two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");//////////////////////////////
31 +
32 + if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능
33 + score = score + base3;
34 + base3 = base2;
35 + base2 = base1;
36 + base1 = 1;
37 + document.write("1루타!")
38 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
39 + "3루 " + base3 + "<br><br>")///////////////////////////
40 + document.write("score: "+score+ "<br><br><br>")
41 + }
42 + else if(one < num && num <= one + two){
43 + score = score + base3 + base2;
44 + base3 = base1;
45 + base2 = 1;
46 + base1 = 0;
47 + document.write("2루타!")
48 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
49 + "3루 " + base3 + "<br><br>")///////////////////////////
50 + document.write("score: "+score+ "<br><br><br>")
51 + }
52 + else if(one + two < num && num <= one + two + three){
53 + score = score + base3 + base2 + base1;
54 + base3 = 1;
55 + base2 = 0;
56 + base1 = 0;
57 + document.write("3루타!")
58 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
59 + "3루 " + base3 + "<br><br>")///////////////////////////
60 + document.write("score: "+score+ "<br><br><br>")
61 + }
62 + else if(one + two + three < num && num <= one + two + three + homerun){
63 + score = score + base3 + base2 + base1 + 1;
64 + base3 = 0;
65 + base2 = 0;
66 + base1 = 0;
67 + document.write("홈런!")
68 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
69 + "3루 " + base3 + "<br><br>")///////////////////////////
70 + document.write("score: "+score+ "<br><br><br>")
71 + }
72 + }
73 + if( kia_pitcher[1][2] < num && num <= kia_pitcher[1][2] + kia_pitcher[1][1]*0.01){
74 + base3 = base2;
75 + base2 = base1;
76 + base1 = 1;
77 + document.write("볼넷!")
78 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
79 + "3루 " + base3 + "<br><br>")///////////////////////////
80 + document.write("score: "+score+ "<br><br><br>")
81 + }
82 + if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){
83 + out++;
84 + if(out >= 3){
85 + exit(100);
86 + }
87 + document.write("아웃!")
88 + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
89 + "3루 " + base3 + "<br><br>")///////////////////////////
90 + document.write("score: "+score+ "<br><br><br>")
91 + }
92 + }
93 +}
...\ No newline at end of file ...\ No newline at end of file
1 +var dusan_hitter = [
2 +['선수명', 'AVG', 'H', '2B', '3B', 'HR']
3 +['박건우', 0.356, 47, 9, 0, 2],
4 +['허경민', 0.345, 49, 6, 0, 3],
5 +['페르난데스', 0.336, 48, 5, 0, 6],
6 +['최용제', 0.308, 8, 2, 0, 0],
7 +['안재석', 0.304, 14, 1, 2, 0],
8 +['김인태', 0.298, 25, 3, 0, 1],
9 +['김재환', 0.285, 37, 4, 1, 9],
10 +['장승현', 0.284, 23, 1, 0, 1],
11 +['조수행', 0.278, 10, 1, 1, 0],
12 +['양석환', 0.277, 38, 8, 0, 5],
13 +['박계범', 0.266, 21, 5, 0, 2],
14 +['김재호', 0.243, 18, 1, 0, 1],
15 +['오재원', 0.22, 11, 2, 0, 0],
16 +['강승호', 0.212, 7, 0, 0, 2],
17 +['권민석', 0.167, 2, 1, 0, 0],
18 +['박세혁', 0.161, 5, 0, 0, 0],
19 +['안권수', 0.133, 2, 0, 0, 0],
20 +['정수빈', 0.125, 4, 1, 0, 0]
21 +]
22 +
23 +var dusan_pitcher = [
24 +['선수명', '볼넷%', '피안타율']
25 +['로켓', 7.7, 0.267],
26 +['미란다', 15.3, 0.259],
27 +['최원준', 5.7, 0.215],
28 +['홍건희', 12.5, 0.224],
29 +['김강률', 13.8, 0.217],
30 +['이승진', 7.2, 0.202],
31 +['유희관', 7.7, 0.381],
32 +['곽빈', 15.9, 0.291],
33 +['김명신', 4.1, 0.303],
34 +['조제영', 17.3, 0.286],
35 +['김민규', 8.8, 0.3],
36 +['박종기', 3.4, 0.236],
37 +['이영하', 12.8, 0.388],
38 +]
...\ No newline at end of file ...\ No newline at end of file
1 +var kia_hitter = [
2 +['선수명', 'AVG', 'H', '2B', '3B', 'HR'],
3 +['김태진', 0.349, 22, 2, 1, 0],
4 +['최원준', 0.342, 54, 2, 4, 0],
5 +['이정훈', 0.293, 12, 2, 0, 1],
6 +['김선빈', 0.292, 40, 8, 0, 0],
7 +['터커', 0.265, 40, 9, 1, 2],
8 +['김민식', 0.261, 18, 2, 0, 2],
9 +['류지혁', 0.259, 21, 3, 0, 0],
10 +['한승택', 0.259, 15, 3, 0, 0],
11 +['이창진', 0.254, 18, 5, 0, 0],
12 +['박찬호', 0.237, 28, 5, 2, 0],
13 +['최형우', 0.2, 18, 0, 0, 4],
14 +['나지완', 0.184, 9, 1, 0, 0],
15 +['김호령', 0.163, 7, 2, 0, 1],
16 +
17 +]
18 +
19 +var kia_pitcher = [
20 + ['선수명', '볼넷%', '피안타율'],
21 + ['브룩스', 5.3, 0.317],
22 + ['멩덴', 10, 0.243],
23 + ['이의리', 12, 0.202]
24 +]
...\ No newline at end of file ...\ No newline at end of file