오진혁

Modify README

......@@ -25,10 +25,10 @@
</ul>
</nav>
<div class="container2">
<a href="https://sports.news.naver.com/kbaseball/record/index.nhn?category=kbo&year=2021"><img src="pngs/rank.jpg" style="display:block; margin:0 auto; width:600px; height:400px;"></a>
<a href="https://sports.news.naver.com/kbaseball/record/index.nhn?category=kbo&year=2021"><img src="pngs/rank.JPG" style="display:block; margin:0 auto; width:600px; height:400px;"></a>
</div>
<div class="container3">
<a href="https://sports.news.naver.com/kbaseball/schedule/index.nhn"><img src="pngs/today.jpg" style="display:block; margin:0 auto; width:655px; height:150px;"></a>
<a href="https://sports.news.naver.com/kbaseball/schedule/index.nhn"><img src="pngs/today.JPG" style="display:block; margin:0 auto; width:655px; height:150px;"></a>
</div>
<div class="container4">
<img src="pngs/1.jpg" style="display:block; margin:0 auto; width:200px; height:100px;">
......
This diff is collapsed. Click to expand it.
function add_predict(){
var s="";
s+=("<option value="+10+">"+10+"</option>");
s+=("<option value="+20+">"+20+"</option>");
s+=("<option value="+50+">"+50+"</option>");
s+=("<option value="+70+">"+70+"</option>");
s+=("<option value="+100+">"+100+"</option>");
s+=("<option value="+500+">"+500+"</option>");
s+=("<option value="+1000+">"+1000+"</option>");
s+=("<option value="+5000+">"+5000+"</option>");
s+=("<option value="+10000+">"+10000+"</option>");
s+=("<option value="+50000+">"+50000+"</option>");
s+=("<option value="+100000+">"+100000+"</option>");
document.getElementById('pr').innerHTML=s;
}
function predict(value, hitter_list1, hitter_list2, pitcher1, pitcher2){
var score=[0,0];
var w=0;
var h=0;
var d=0;
for(var i=0; i<value; i++){
score=algorithms(hitter_list1, hitter_list2, pitcher1, pitcher2);
if(score[0]>score[1]){
w++;
}else if(score[0]<score[1]){
h++;
}else{
d++;
}
}
document.getElementById('jstest').innerHTML="예측 결과"+"<br\>"+"TEST "+value+"번"+"<br\><br\>"+"원정팀 승리 횟수 : "+w+"<br\>"
+"홈팀 승리 횟수 : "+h+"<br\>"+"무승부 횟수 : "+d+"<br\><br\>"+"원정팀 승리 확률 : "+w*100/value+"%"+"<br\>"+"홈팀 승리 확률 : "+h*100/value+"%"+"<br\>";
}
function algorithms(hitter_list1, hitter_list2, pitcher1, pitcher2){
var base1 = 0; var base2 = 0; var base3 = 0; //1이면 주자 있고 0이면 비어있는것
var out = 0; var ining = 1; var home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2.
var score1 = 0; var score2 = 0;
var hitter_num1 = 1; var hitter_num2 = 1;
var hit=false;
while(true){
if(ining == 9 && home_away == 2 && score1 < score2){//9회 초 후 home팀이 이기고 있을 때!
break;
}
else if(ining==10 && home_away==1 && score1>score2 && hit==false){//9회 말 후 home팀이 이기고 있을 때!
break;
}
else if(ining>9 && score1 < score2){//9회 말 후 home팀이 이기고 있을 때!
break;
}
else if(ining>=11 && home_away==1 && hit==false && score1>score2){//연장 이후 원정팀이 이기고 있을 때!
break;
}
else if(ining>=10 && home_away==2 && hit==true && score1<score2){//끝내기
break;
}
else if(ining==13 && score1==score2){//무승부
break;
}
if(home_away == 1){
var hitter = hitter_list1[hitter_num1]; //hitter = hitter_list1[hitter_number1%9]
var pitcher = pitcher2; //pitcher = pitcher1
}
else if(home_away == 2){
var hitter = hitter_list2[hitter_num2]; //hitter = hitter_list2[hitter_number2%9]
var pitcher = pitcher1; //pitcher = pitcher2
}
var num = Math.random();
//hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
var one = 0; var two = 0; var three = 0; var homerun = 0;
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];
hit=true;
if(num <= one){ //안타
var num1 = Math.random();
if(num1 <= 0.5){
switch(home_away){
case 1:
score1 = score1 + base3;
break;
case 2:
score2 = score2 + base3;
break;
}
base3 = base2;
base2 = base1;
base1 = 1;
}
else{
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = base1;
base2 = 0;
base1 = 1;
}
}
else if((one < num) && (num <= one + two)){//2루타
var num2 = Math.random();
if(num2 <= 0.4){
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = base1;
base2 = 1;
base1 = 0;
}
else if(0.4 < num2 && num2 <=0.7){
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
}
else{
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
}
}
else if((one + two < num) && (num <= one + two + three)){//3루타
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 1;
base2 = 0;
base1 = 0;
}
else if(one + two + three < num && num <= one + two + three + homerun){//홈런
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1 + 1;
break;
case 2:
score2 = score2 + base3 + base2 + base1 + 1;
break;
}
base3 = 0;
base2 = 0;
base1 = 0;
}
else if( pitcher[2] < num && (num <= pitcher[2] +pitcher[1]*0.01)){//볼넷
if(base1==1 && base2==1 && base3==1){//만루 밀어내기 득점 -> 스코어 ++
if(home_away==1){
score1++;
}
else{
score2++;
}
}
else{//스코어 추가되지 않는 경우
if((base2==1 && base1==0 )||(base3==1 && base1==0)||(base2==1&&base3==1&&base1==0)){//2루만 채워져있거나 3루만 채워져있거나 2,3루만 채워져있거나
base1=1;
}
else if(base1==1 && base3==1 && base2==0){//1루 3루 채워져있고 2루 비워져있거나
base2=base1;
base1=1;
}
else{
base3 = base2;
base2 = base1;
base1 = 1;
}
}
}
else{//아웃
out++;
}
if(out >= 3){
switch(home_away){
case 1:
home_away = 2;
hit=false;
break;
case 2:
home_away = 1;
ining++;
hit=false;
break;
}
out=0;
base1=0; base2=0; base3=0;
}
else{
if(home_away == 1){
hitter_num1++;
if(hitter_num1>=10){
hitter_num1=1;
}
}
else if(home_away == 2){
hitter_num2++;
if(hitter_num2>=10){
hitter_num2=1;
}
}
}
}
var score = [score1, score2];
return score;
}
const express = require('express');
const app = express();
app.use(express.static(__dirname));
app.listen(8080, function(){
console.log('listening on 8080');
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/main.html');
app.get('/test', function(req, res){
res.send('test');
});
app.get('/main.html', function(req, res){
app.get('/', function(req, res){
res.sendFile(__dirname + '/main.html');
res.sendFile(__dirname + '/main.css');
});
\ No newline at end of file
app.get('/introduction.html', function(req, res){
res.sendFile(__dirname + '/introduction.html');
});
app.get('/calendar.html', function(req, res){
res.sendFile(__dirname + '/calendar.html');
});
app.get('/simulation.html', function(req, res){
res.sendFile(__dirname + '/simulation.html');
});
......
......@@ -78,6 +78,10 @@ body{
font-size:15px;
border-radius:5px;
}
.t1:hover{
color:#0053b3;
background-color: #2E294E;
}
.row{
display:flex;
justify-content: space-evenly;
......@@ -102,6 +106,10 @@ body{
font-size:15px;
border-radius:5px;
}
.t2:hover{
color:#be4209;
background-color: #2E294E;
}
.l{
width:33%;
height:200px;
......@@ -118,24 +126,26 @@ body{
text-align:center;
}
.simul{
width:50%;
height:150px;
display:flex;
float:left;
margin-top:50px;
margin-left:250px;
}
.but{
height:150px;
margin: 0px auto;
margin: auto;
text-align:center;
}
.simulbtr{
width:250px;
width:200px;
height:50px;
color: #c9d6de;
border: 1px solid #c9d6de;
background: black;
font-size:30px;
margin-top:50px;
font-size:20px;
border-radius:5px;
margin-right:5px;
}
.simulbtr:hover{
color:#7700ff;
background-color: #2E294E;
}
.tb{
padding: 10px 0px 0px 90px;
......@@ -156,3 +166,9 @@ td{
overflow-x: auto;
background-color:white;
}
#select_list{
width:50%;
margin: auto;
text-align:center;
margin-bottom:50px;
}
\ No newline at end of file
......
......@@ -6,6 +6,7 @@
<script src = "player.js"></script>
<script src = "temp_algorithm.js"></script>
<script src = "simulation.js"></script>
<script src = "predict.js"></script>
</head>
<body>
<div class="container1">
......@@ -125,12 +126,11 @@
<img src="pngs/dusan.png" id="home" class="vs">
</div>
<div class="simul">
<div class="but">
<input type="button" onclick="pre_algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2);" class="simulbtr" value="시뮬레이션">
<input type="button" onclick="add_predict();" class="simulbtr" value="승률예측">
</div>
<div class="result">
</div>
<div id="select_list">
<select name="pr" id="pr" onclick="predict(this.value, hitter_list1, hitter_list2, pitcher1, pitcher2);"></select>
</div>
<div id="jstest"></div>
</div>
......
......@@ -193,8 +193,84 @@ function pre_algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2){//algorit
}
else{//아웃
var ran = Math.random()*0.2;
if(ran>0.197){
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1 + 1;
break;
case 2:
score2 = score2 + base3 + base2 + base1 + 1;
break;
}
base3 = 0;
base2 = 0;
base1 = 0;
document.getElementById('jstest').innerHTML+=("홈런!");
}else if(ran>0.1955){
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 1;
base2 = 0;
base1 = 0;
document.getElementById('jstest').innerHTML+=("3루타!");
}else if(ran>0.18){
var n = Math.random();
if(n <= 0.4){
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = base1;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
else if(0.4 < n && n <=0.7){
switch(home_away){
case 1:
score1 = score1 + base3 + base2 + base1;
break;
case 2:
score2 = score2 + base3 + base2 + base1;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
else{
switch(home_away){
case 1:
score1 = score1 + base3 + base2;
break;
case 2:
score2 = score2 + base3 + base2;
break;
}
base3 = 0;
base2 = 1;
base1 = 0;
document.getElementById('jstest').innerHTML+=("2루타!");
}
}else{
out++;
document.getElementById('jstest').innerHTML+=("아웃!");
}
}
......@@ -234,4 +310,6 @@ function pre_algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2){//algorit
}
document.getElementById('jstest').innerHTML+=("<br\><br\>"+"최종스코어 : "+score1+"vs"+score2);
var score = [score1, score2];
return score;
}
\ No newline at end of file
......