김건우

update simulation algorithm

Showing 301 changed files with 306 additions and 377 deletions
'적중률 99%' 야구 결과 시뮬레이션
프로젝트 참여자 : 김건우(2020105583), 오진혁(2020105636), 정주희(2020105660)
프로젝트 소개 : {
목적 : 야구 경기 시뮬레이션과 경기 일정 등을 종합적으로 제공하는 서비스
구현 계획 : [
1. node.js or js로 크롤링하여 순위, 일정 등을 불러들여 제공(미완) -> 임시 사진 대체. 링크만 걸어놓음
2. 구현 서비스, 과정을 담은 영상을 home에 연결(미완) -> 야구 경기 하이라이트로 대체.
3. 전반적인 4개의 site(main, introduction, calendar, simulation) 구축
-> main은 위 1, 2번 문제에 해당됨.
-> introduction은 readme.md 완성 시 update할 예정.
-> simulation은 구단 클릭 시 선수 list를 불러와 원하는 구단과 선수 명단을 짜고, 이를 바탕으로 시뮬레이션 하도록 프로그래밍 요망.
현재는 임시로 KIA(원정)VS두산(홈)의 구도와 9명의 짜여진 라인업, 1명의 투수로 시뮬레이션 진행하도록 설계함.
오류 발생하는 대로 수정하여 update&commit 예정.
]
}
알고리즘 소개 : {
업데이트 예정 ...
참고사항 : 기계학습, 딥러닝 사용하지 않아 99% 적중하기는 힘들다.
}
역할 분담 : {
김건우 : 전반적인 알고리즘 구축(with javascript), calendar 사진 및 기본 틀 구축, 정보 업데이트,
오진혁 : 서버 구축 담당(with node.js), main 기본 틀 구축, shuffle 알고리즘 구축, 정보 업데이트,
정주희 : 전반적인 프론트엔드(with html, css, javascript), 알고리즘 수정 및 적용
}
\ No newline at end of file
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[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){ //그냥 간단하게 다음 베이스로 한 칸씩 이동하도록 계산, 모든 경우의 수 계산하는게 불가능
var num1 = Math.random();
if(num1 <= 0.5){
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>")
}
if(num1 > 0.5){
score = score + base3 + base2;
base3 = base1;
base2 = 0;
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){
var num2 = Math.random();
if(num2 <= 0.4){
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>")
}
if(0.4 < num2 && num2 <=0.7){
score = score + base3 + base2 + base1;
base3 = 0;
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>")
}
if(0.7 < num2 && num2 <= 1){
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>")///////////////////////////
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){
hitter = dusan_hitter[1];
pitcher = dusan_pitcher[1];
break;
}
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
function algorithm(){//algorithm(hitter_list1, hitter_list2, pitcher1, pitcher2) => html에서 가지고와야 한다.
var base1 = 0; base2 = 0; base3 = 0; //1이면 주자 있고 0이면 비어있는것
var out = 0; ining = 1; home_away = 1;//아웃카운트, 이닝, home이면 1이고 away이면 2.
var hitter_number1 = 0; hitter_number2 = 0; //이전 타석 타자 번호
var score = 0; score2 = 0;
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);
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){ //안타
var num1 = Math.random();
if(num1 <= 0.5){
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;
document.write("1루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
if(num1 > 0.5){
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;
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){//2루타
var num2 = Math.random();
if(num2 <= 0.4){
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;
document.write("2루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
document.write("score: "+score+ "<br><br><br>")
}
if(0.4 < num2 && num2 <=0.7){
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;
document.write("2루타!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
"3루 " + base3 + "<br><br>")///////////////////////////
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;
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){//3루타
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){
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("아웃!")
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
body{
background-image:url(https://t1.daumcdn.net/cfile/blog/155A204A5026656D0E);
background-repeat: no-repeat;
background-size: cover;
}
.container1{
display:flex;
justify-content: center;
align-items: baseline;
padding:50px 0px 0px 0px;
}
.logo{
font-size:40px;
color:white;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
#menu{
margin:60px 250px 0px 250px;
height:90px;
width:1000px;
}
#menu ul li{
list-style:none;
color:white;
background-color:#011638;
float:left;
line-height:30px;
vertical-align:middle;
text-align:center;
display:inline;
}
#menu .me{
text-decoration:none;
color:white;
display:inline-block;
width:250px;
font-size:20px;
font-weight:bold;
font-family: "Trebuchet MS", Dotum, Arial;
}
#menu .me:hover{
color:#D499B9;
background-color: #2E294E;
}
.row{
display:flex;
justify-content: space-evenly;
padding: 0px 0px 50px 0px;
}
<!DOCTYPE html>
<html>
<head>
<title> Calendar </title>
<link rel="stylesheet" type="text/css"href="calendar.css">
</head>
<body>
<div class="container1">
<span class="logo">Welcome to Baseball Simulator</span>
</div>
<nav id="menu">
<ul>
<li>
<a class="me" href="main.html">Home</a>
</li>
<li>
<a class="me" href="introduction.html">Introduction</a>
</li>
<li>
<a class="me" href="calendar.html">Calendar</a>
</li>
<li>
<a class="me" href="simulation.html">Simulation</a>
</li>
</ul>
</nav>
<div class="container2">
<div class="row row1">
<span class="item1">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=%EC%82%BC%EC%84%B1">
<img src="pngs/samsung.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item2">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=NC">
<img src="pngs/nc.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item3">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=LG">
<img src="pngs/LG.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item4">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=KT">
<img src="pngs/kt.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item5">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=SSG">
<img src="pngs/ssg.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
</div>
<div class="row row2">
<span class="item6">
<a href="http://www.statiz.co.kr/team.php?cteam=%EB%91%90%EC%82%B0%2BOB&year=2021&opt=0&sopt=1">
<img src="pngs/dusan.png" style="display:block; margin:0 auto; width:150px; height:150px;"alt="">
</a>
</span>
<span class="item7">
<a href="http://www.statiz.co.kr/team.php?cteam=%ED%9E%88%EC%96%B4%EB%A1%9C%EC%A6%88&year=2021&opt=0&sopt=1">
<img src="pngs/kiwoom.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item8">
<a href="http://www.statiz.co.kr/team.php?opt=0&sopt=1&year=2021&team=KIA">
<img src="pngs/kia.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item9">
<a href="http://www.statiz.co.kr/team.php?cteam=%ED%95%9C%ED%99%94%2B%EB%B9%99%EA%B7%B8%EB%A0%88&year=2021&opt=0&sopt=1">
<img src="pngs/hanhwa.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
<span class="item10">
<a href="http://www.statiz.co.kr/team.php?cteam=%EB%A1%AF%EB%8D%B0&year=2021&opt=0&sopt=1">
<img src="pngs/Lotte.png" style="display:block; margin:0 auto; width:150px; height:150px;" alt="">
</a>
</span>
</div>
</div>
</body>
</html>
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
body{
background-image:url(https://t1.daumcdn.net/cfile/blog/155A204A5026656D0E);
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.container1{
display:flex;
justify-content: center;
align-items: baseline;
padding:50px 0px 0px 0px;
}
.logo{
font-size:40px;
color:white;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
#menu{
margin:60px 250px 0px 250px;
height:90px;
width:1000px;
}
#menu ul li{
list-style:none;
color:white;
background-color:#011638;
float:left;
line-height:30px;
vertical-align:middle;
text-align:center;
display:inline;
}
#menu .me{
text-decoration:none;
color:white;
display:inline-block;
width:250px;
font-size:20px;
font-weight:bold;
font-family: "Trebuchet MS", Dotum, Arial;
}
#menu .me:hover{
color:#D499B9;
background-color: #2E294E;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title> Introduction </title>
<link rel="stylesheet" type="text/css"href="introduction.css">
</head>
<body>
<div class="container1">
<span class="logo">Welcome to Baseball Simulator</span>
</div>
<nav id="menu">
<ul>
<li>
<a class="me" href="main.html">Home</a>
</li>
<li>
<a class="me" href="introduction.html">Introduction</a>
</li>
<li>
<a class="me" href="calendar.html">Calendar</a>
</li>
<li>
<a class="me" href="simulation.html">Simulation</a>
</li>
</ul>
</nav>
</body>
</html>
body{
background-image:url(https://t1.daumcdn.net/cfile/blog/155A204A5026656D0E);
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.container1{
display:flex;
justify-content: center;
align-items: baseline;
padding:50px 0px 0px 0px;
}
.logo{
font-size:40px;
color:white;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
#menu{
margin:60px 250px 0px 250px;
height:90px;
width:1000px;
}
#menu ul li{
list-style:none;
color:white;
background-color:#011638;
float:left;
line-height:30px;
vertical-align:middle;
text-align:center;
display:inline;
}
#menu .me{
text-decoration:none;
color:white;
display:inline-block;
width:250px;
font-size:20px;
font-weight:bold;
font-family: "Trebuchet MS", Dotum, Arial;
}
#menu .me:hover{
color:#D499B9;
background-color: #2E294E;
}
.container2{
width:50%;
height:600px;
float:left;
}
.container3{
width:50%;
height:200px;
float:left;
}
.container4{
width:20%;
height:400px;
float:left;
}
.container5{
width:30%;
height:400px;
float:left;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title> Baseball Simulator </title>
<link rel="stylesheet" type="text/css"href="main.css">
</head>
<body>
<div class="container1">
<span class="logo">Welcome to Baseball Simulator</span>
</div>
<nav id="menu">
<ul>
<li>
<a class="me" href="main.html">Home</a>
</li>
<li>
<a class="me" href="introduction.html">Introduction</a>
</li>
<li>
<a class="me" href="calendar.html">Calendar</a>
</li>
<li>
<a class="me" href="simulation.html">Simulation</a>
</li>
</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>
</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>
</div>
<div class="container4">
<img src="pngs/1.jpg" style="display:block; margin:0 auto; width:200px; height:100px;">
</div>
<div class="container5">
<iframe width="400" height="200" src="https://www.youtube.com/embed/dL_79KkHmQE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</body>
</html>
This diff is collapsed. Click to expand it.
{
"name": "homework",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.