Showing
4 changed files
with
287 additions
and
28 deletions
algorithm.TXT
0 → 100644
| 1 | +function algorithm(){ | ||
| 2 | + var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다. | ||
| 3 | + var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것 | ||
| 4 | + var out = 0; ining = 1; //아웃카운트, 이닝 | ||
| 5 | + var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호 | ||
| 6 | + var score = 0; score2 = 0; | ||
| 7 | + for(i = 0; i < 10; i++){ | ||
| 8 | + var num = Math.random(); | ||
| 9 | + document.write(num, "<br><br>");////////////////////// | ||
| 10 | + //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan); | ||
| 11 | + hitter = kia_hitter[1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다. | ||
| 12 | + document.write(hitter[0], "<br><br>") | ||
| 13 | + var one = 0; var two = 0; var three = 0; var homerun = 0; | ||
| 14 | + if( num <= kia_pitcher[1][2]){ | ||
| 15 | + one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2]; | ||
| 16 | + two = pitcher[2] * hitter[3]/hitter[2]; | ||
| 17 | + three = pitcher[2] * hitter[4]/hitter[2]; | ||
| 18 | + homerun = pitcher[2] * hitter[5]/hitter[2]; | ||
| 19 | + document.write("확률" + "<br>" + "1루타 " + one, "<br>","2루타 " + | ||
| 20 | + two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");////////////////////////////// | ||
| 21 | + | ||
| 22 | + if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능 | ||
| 23 | + var num1 = Math.random(); | ||
| 24 | + if(num1 <= 0.5){ | ||
| 25 | + score = score + base3; | ||
| 26 | + base3 = base2; | ||
| 27 | + base2 = base1; | ||
| 28 | + base1 = 1; | ||
| 29 | + document.write("1루타!") | ||
| 30 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 31 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 32 | + document.write("score: "+score+ "<br><br><br>") | ||
| 33 | + } | ||
| 34 | + if(num1 > 0.5){ | ||
| 35 | + score = score + base3 + base2; | ||
| 36 | + base3 = base1; | ||
| 37 | + base2 = 0; | ||
| 38 | + base1 = 1; | ||
| 39 | + document.write("1루타!") | ||
| 40 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 41 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 42 | + document.write("score: "+score+ "<br><br><br>") | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + else if(one < num && num <= one + two){ | ||
| 47 | + var num2 = Math.random(); | ||
| 48 | + if(num2 <= 0.4){ | ||
| 49 | + score = score + base3 + base2; | ||
| 50 | + base3 = base1; | ||
| 51 | + base2 = 1; | ||
| 52 | + base1 = 0; | ||
| 53 | + document.write("2루타!") | ||
| 54 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 55 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 56 | + document.write("score: "+score+ "<br><br><br>") | ||
| 57 | + } | ||
| 58 | + if(0.4 < num2 && num2 <=0.7){ | ||
| 59 | + score = score + base3 + base2 + base1; | ||
| 60 | + base3 = 0; | ||
| 61 | + base2 = 1; | ||
| 62 | + base1 = 0; | ||
| 63 | + document.write("2루타!") | ||
| 64 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 65 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 66 | + document.write("score: "+score+ "<br><br><br>") | ||
| 67 | + } | ||
| 68 | + if(0.7 < num2 && num2 <= 1){ | ||
| 69 | + score = score + base3 + base2; | ||
| 70 | + base3 = 0; | ||
| 71 | + base2 = 1; | ||
| 72 | + base1 = 0; | ||
| 73 | + out++; | ||
| 74 | + document.write("2루타!") | ||
| 75 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 76 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 77 | + document.write("score: "+score+ "<br><br><br>") | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + } | ||
| 81 | + else if(one + two < num && num <= one + two + three){ | ||
| 82 | + score = score + base3 + base2 + base1; | ||
| 83 | + base3 = 1; | ||
| 84 | + base2 = 0; | ||
| 85 | + base1 = 0; | ||
| 86 | + document.write("3루타!") | ||
| 87 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 88 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 89 | + document.write("score: "+score+ "<br><br><br>") | ||
| 90 | + } | ||
| 91 | + else if(one + two + three < num && num <= one + two + three + homerun){ | ||
| 92 | + score = score + base3 + base2 + base1 + 1; | ||
| 93 | + base3 = 0; | ||
| 94 | + base2 = 0; | ||
| 95 | + base1 = 0; | ||
| 96 | + document.write("홈런!") | ||
| 97 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 98 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 99 | + document.write("score: "+score+ "<br><br><br>") | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + if( kia_pitcher[1][2] < num && num <= kia_pitcher[1][2] + kia_pitcher[1][1]*0.01){ | ||
| 103 | + base3 = base2; | ||
| 104 | + base2 = base1; | ||
| 105 | + base1 = 1; | ||
| 106 | + document.write("볼넷!") | ||
| 107 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 108 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 109 | + document.write("score: "+score+ "<br><br><br>") | ||
| 110 | + } | ||
| 111 | + if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){ | ||
| 112 | + out++; | ||
| 113 | + if(out >= 3){ | ||
| 114 | + hitter = dusan_hitter[1]; | ||
| 115 | + pitcher = dusan_pitcher[1]; | ||
| 116 | + break; | ||
| 117 | + } | ||
| 118 | + document.write("아웃!") | ||
| 119 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 120 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 121 | + document.write("score: "+score+ "<br><br><br>") | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | +} | ||
| ... | \ 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(){ | 1 | function algorithm(){ |
| 11 | var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다. | 2 | var pitcher = kia_pitcher[1]; //선발투수, 나중에 사용자가 지정해주는 투수로 바뀌도록 수정해야 한다. |
| 12 | var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것 | 3 | var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것 |
| ... | @@ -17,11 +8,10 @@ function algorithm(){ | ... | @@ -17,11 +8,10 @@ function algorithm(){ |
| 17 | var num = Math.random(); | 8 | var num = Math.random(); |
| 18 | document.write(num, "<br><br>");////////////////////// | 9 | document.write(num, "<br><br>");////////////////////// |
| 19 | //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan); | 10 | //hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan); |
| 20 | - hitter = kia_hitter[i+1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다. | 11 | + hitter = kia_hitter[1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다. |
| 21 | document.write(hitter[0], "<br><br>") | 12 | document.write(hitter[0], "<br><br>") |
| 22 | var one = 0; var two = 0; var three = 0; var homerun = 0; | 13 | var one = 0; var two = 0; var three = 0; var homerun = 0; |
| 23 | if( num <= kia_pitcher[1][2]){ | 14 | if( num <= kia_pitcher[1][2]){ |
| 24 | - | ||
| 25 | one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2]; | 15 | one = pitcher[2] * (hitter[2] - hitter[3] - hitter[4] - hitter[5])/hitter[2]; |
| 26 | two = pitcher[2] * hitter[3]/hitter[2]; | 16 | two = pitcher[2] * hitter[3]/hitter[2]; |
| 27 | three = pitcher[2] * hitter[4]/hitter[2]; | 17 | three = pitcher[2] * hitter[4]/hitter[2]; |
| ... | @@ -30,24 +20,63 @@ function algorithm(){ | ... | @@ -30,24 +20,63 @@ function algorithm(){ |
| 30 | two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");////////////////////////////// | 20 | two, "<br>","3루타 "+ three, "<br>","홈런 " + homerun, "<br><br>");////////////////////////////// |
| 31 | 21 | ||
| 32 | if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능 | 22 | if(num <= one){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능 |
| 33 | - score = score + base3; | 23 | + var num1 = Math.random(); |
| 34 | - base3 = base2; | 24 | + if(num1 <= 0.5){ |
| 35 | - base2 = base1; | 25 | + score = score + base3; |
| 36 | - base1 = 1; | 26 | + base3 = base2; |
| 37 | - document.write("1루타!") | 27 | + base2 = base1; |
| 38 | - document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | 28 | + base1 = 1; |
| 39 | - "3루 " + base3 + "<br><br>")/////////////////////////// | 29 | + document.write("1루타!") |
| 40 | - document.write("score: "+score+ "<br><br><br>") | 30 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", |
| 31 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 32 | + document.write("score: "+score+ "<br><br><br>") | ||
| 33 | + } | ||
| 34 | + if(num1 > 0.5){ | ||
| 35 | + score = score + base3 + base2; | ||
| 36 | + base3 = base1; | ||
| 37 | + base2 = 0; | ||
| 38 | + base1 = 1; | ||
| 39 | + document.write("1루타!") | ||
| 40 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 41 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 42 | + document.write("score: "+score+ "<br><br><br>") | ||
| 43 | + } | ||
| 44 | + | ||
| 41 | } | 45 | } |
| 42 | else if(one < num && num <= one + two){ | 46 | else if(one < num && num <= one + two){ |
| 43 | - score = score + base3 + base2; | 47 | + var num2 = Math.random(); |
| 44 | - base3 = base1; | 48 | + if(num2 <= 0.4){ |
| 45 | - base2 = 1; | 49 | + score = score + base3 + base2; |
| 46 | - base1 = 0; | 50 | + base3 = base1; |
| 47 | - document.write("2루타!") | 51 | + base2 = 1; |
| 48 | - document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | 52 | + base1 = 0; |
| 49 | - "3루 " + base3 + "<br><br>")/////////////////////////// | 53 | + document.write("2루타!") |
| 50 | - document.write("score: "+score+ "<br><br><br>") | 54 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", |
| 55 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 56 | + document.write("score: "+score+ "<br><br><br>") | ||
| 57 | + } | ||
| 58 | + if(0.4 < num2 && num2 <=0.7){ | ||
| 59 | + score = score + base3 + base2 + base1; | ||
| 60 | + base3 = 0; | ||
| 61 | + base2 = 1; | ||
| 62 | + base1 = 0; | ||
| 63 | + document.write("2루타!") | ||
| 64 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 65 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 66 | + document.write("score: "+score+ "<br><br><br>") | ||
| 67 | + } | ||
| 68 | + if(0.7 < num2 && num2 <= 1){ | ||
| 69 | + score = score + base3 + base2; | ||
| 70 | + base3 = 0; | ||
| 71 | + base2 = 1; | ||
| 72 | + base1 = 0; | ||
| 73 | + out++; | ||
| 74 | + document.write("2루타!") | ||
| 75 | + document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ||
| 76 | + "3루 " + base3 + "<br><br>")/////////////////////////// | ||
| 77 | + document.write("score: "+score+ "<br><br><br>") | ||
| 78 | + } | ||
| 79 | + | ||
| 51 | } | 80 | } |
| 52 | else if(one + two < num && num <= one + two + three){ | 81 | else if(one + two < num && num <= one + two + three){ |
| 53 | score = score + base3 + base2 + base1; | 82 | score = score + base3 + base2 + base1; |
| ... | @@ -82,7 +111,9 @@ function algorithm(){ | ... | @@ -82,7 +111,9 @@ function algorithm(){ |
| 82 | if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){ | 111 | if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){ |
| 83 | out++; | 112 | out++; |
| 84 | if(out >= 3){ | 113 | if(out >= 3){ |
| 85 | - exit(100); | 114 | + hitter = dusan_hitter[1]; |
| 115 | + pitcher = dusan_pitcher[1]; | ||
| 116 | + break; | ||
| 86 | } | 117 | } |
| 87 | document.write("아웃!") | 118 | document.write("아웃!") |
| 88 | document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | 119 | document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>", | ... | ... |
shuffle_list.TXT
0 → 100644
| 1 | +function shuffle(x){ | ||
| 2 | + if(x.name === "kia"){ | ||
| 3 | + for(j = 0; j < kia_hitter_shuffle.length; j++){ | ||
| 4 | + if(kia_hitter_shuffle.length == 0){ | ||
| 5 | + continue; | ||
| 6 | + } | ||
| 7 | + else if(x.value == kia_hitter_shuffle[j][0]){ | ||
| 8 | + console.log(x.value == kia_hitter_shuffle[j][0]) | ||
| 9 | + return 0; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + for(i = 0; i < kia_hitter.length; i++){ | ||
| 13 | + if(x.value == kia_hitter[i][0]){ | ||
| 14 | + kia_hitter_shuffle.push(kia_hitter[i]); | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + } | ||
| 18 | + console.log(kia_hitter_shuffle); | ||
| 19 | + //////////////////////////////////////////////////////////////// | ||
| 20 | + if(x.name === "dusan"){ | ||
| 21 | + for(j = 0; j < dusan_hitter_shuffle.length; j++){ | ||
| 22 | + if(dusan_hitter_shuffle.length == 0){ | ||
| 23 | + continue; | ||
| 24 | + } | ||
| 25 | + else if(x.value == dusan_hitter_shuffle[j][0]){ | ||
| 26 | + console.log(x.value == dusan_hitter_shuffle[j][0]) | ||
| 27 | + return 0; | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + for(i = 0; i < dusan_hitter.length; i++){ | ||
| 31 | + if(x.value == dusan_hitter[i][0]){ | ||
| 32 | + dusan_hitter_shuffle.push(dusan_hitter[i]); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + //나머지 팀들 똑같이 추가 | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +function remove(x){ | ||
| 40 | + if(document.getElementById(x.name).name == 'kia'){ | ||
| 41 | + for(i = 0; i < kia_hitter_shuffle.length; i++){ | ||
| 42 | + if(kia_hitter_shuffle.length == 0){ | ||
| 43 | + return 0; | ||
| 44 | + } | ||
| 45 | + else if(document.getElementById(x.name).value == kia_hitter_shuffle[i][0]){ | ||
| 46 | + kia_hitter_shuffle.splice(i,1); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + console.log(kia_hitter_shuffle); | ||
| 51 | + //나머지 팀들 똑같이 추가 | ||
| 52 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
shuffle_list.js
0 → 100644
| 1 | +function shuffle(x){ | ||
| 2 | + if(x.name === "kia"){ | ||
| 3 | + for(j = 0; j < kia_hitter_shuffle.length; j++){ | ||
| 4 | + if(kia_hitter_shuffle.length == 0){ | ||
| 5 | + continue; | ||
| 6 | + } | ||
| 7 | + else if(x.value == kia_hitter_shuffle[j][0]){ | ||
| 8 | + console.log(x.value == kia_hitter_shuffle[j][0]) | ||
| 9 | + return 0; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + for(i = 0; i < kia_hitter.length; i++){ | ||
| 13 | + if(x.value == kia_hitter[i][0]){ | ||
| 14 | + kia_hitter_shuffle.push(kia_hitter[i]); | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + } | ||
| 18 | + console.log(kia_hitter_shuffle); | ||
| 19 | + //////////////////////////////////////////////////////////////// | ||
| 20 | + if(x.name === "dusan"){ | ||
| 21 | + for(j = 0; j < dusan_hitter_shuffle.length; j++){ | ||
| 22 | + if(dusan_hitter_shuffle.length == 0){ | ||
| 23 | + continue; | ||
| 24 | + } | ||
| 25 | + else if(x.value == dusan_hitter_shuffle[j][0]){ | ||
| 26 | + console.log(x.value == dusan_hitter_shuffle[j][0]) | ||
| 27 | + return 0; | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + for(i = 0; i < dusan_hitter.length; i++){ | ||
| 31 | + if(x.value == dusan_hitter[i][0]){ | ||
| 32 | + dusan_hitter_shuffle.push(dusan_hitter[i]); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + //나머지 팀들 똑같이 추가 | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +function remove(x){ | ||
| 40 | + if(document.getElementById(x.name).name == 'kia'){ | ||
| 41 | + for(i = 0; i < kia_hitter_shuffle.length; i++){ | ||
| 42 | + if(kia_hitter_shuffle.length == 0){ | ||
| 43 | + return 0; | ||
| 44 | + } | ||
| 45 | + else if(document.getElementById(x.name).value == kia_hitter_shuffle[i][0]){ | ||
| 46 | + kia_hitter_shuffle.splice(i,1); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + console.log(kia_hitter_shuffle); | ||
| 51 | + //나머지 팀들 똑같이 추가 | ||
| 52 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment