김건우

algorithm v.2 & shuffle list

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
/*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이면 비어있는것
......@@ -17,11 +8,10 @@ function algorithm(){
var num = Math.random();
document.write(num, "<br><br>");//////////////////////
//hitter_number1 = hitter_number(kia); hitter_number2 = hitter_number(dusan);
hitter = kia_hitter[i+1]; //선발타자, 나중에 사용자가 지정해주는 타자로 바뀌도록 수정해야 한다.
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];
......@@ -30,24 +20,63 @@ function algorithm(){
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>")
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){
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>")
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;
......@@ -82,7 +111,9 @@ function algorithm(){
if( kia_pitcher[1][2] + kia_pitcher[1][1]*0.01 < num && num <= 1){
out++;
if(out >= 3){
exit(100);
hitter = dusan_hitter[1];
pitcher = dusan_pitcher[1];
break;
}
document.write("아웃!")
document.write("베이스 상태"+"<br>", "1루 " + base1 + "<br>", "2루 " + base2 + "<br>",
......
function shuffle(x){
if(x.name === "kia"){
for(j = 0; j < kia_hitter_shuffle.length; j++){
if(kia_hitter_shuffle.length == 0){
continue;
}
else if(x.value == kia_hitter_shuffle[j][0]){
console.log(x.value == kia_hitter_shuffle[j][0])
return 0;
}
}
for(i = 0; i < kia_hitter.length; i++){
if(x.value == kia_hitter[i][0]){
kia_hitter_shuffle.push(kia_hitter[i]);
}
}
}
console.log(kia_hitter_shuffle);
////////////////////////////////////////////////////////////////
if(x.name === "dusan"){
for(j = 0; j < dusan_hitter_shuffle.length; j++){
if(dusan_hitter_shuffle.length == 0){
continue;
}
else if(x.value == dusan_hitter_shuffle[j][0]){
console.log(x.value == dusan_hitter_shuffle[j][0])
return 0;
}
}
for(i = 0; i < dusan_hitter.length; i++){
if(x.value == dusan_hitter[i][0]){
dusan_hitter_shuffle.push(dusan_hitter[i]);
}
}
}
//나머지 팀들 똑같이 추가
}
function remove(x){
if(document.getElementById(x.name).name == 'kia'){
for(i = 0; i < kia_hitter_shuffle.length; i++){
if(kia_hitter_shuffle.length == 0){
return 0;
}
else if(document.getElementById(x.name).value == kia_hitter_shuffle[i][0]){
kia_hitter_shuffle.splice(i,1);
}
}
}
console.log(kia_hitter_shuffle);
//나머지 팀들 똑같이 추가
}
\ No newline at end of file
function shuffle(x){
if(x.name === "kia"){
for(j = 0; j < kia_hitter_shuffle.length; j++){
if(kia_hitter_shuffle.length == 0){
continue;
}
else if(x.value == kia_hitter_shuffle[j][0]){
console.log(x.value == kia_hitter_shuffle[j][0])
return 0;
}
}
for(i = 0; i < kia_hitter.length; i++){
if(x.value == kia_hitter[i][0]){
kia_hitter_shuffle.push(kia_hitter[i]);
}
}
}
console.log(kia_hitter_shuffle);
////////////////////////////////////////////////////////////////
if(x.name === "dusan"){
for(j = 0; j < dusan_hitter_shuffle.length; j++){
if(dusan_hitter_shuffle.length == 0){
continue;
}
else if(x.value == dusan_hitter_shuffle[j][0]){
console.log(x.value == dusan_hitter_shuffle[j][0])
return 0;
}
}
for(i = 0; i < dusan_hitter.length; i++){
if(x.value == dusan_hitter[i][0]){
dusan_hitter_shuffle.push(dusan_hitter[i]);
}
}
}
//나머지 팀들 똑같이 추가
}
function remove(x){
if(document.getElementById(x.name).name == 'kia'){
for(i = 0; i < kia_hitter_shuffle.length; i++){
if(kia_hitter_shuffle.length == 0){
return 0;
}
else if(document.getElementById(x.name).value == kia_hitter_shuffle[i][0]){
kia_hitter_shuffle.splice(i,1);
}
}
}
console.log(kia_hitter_shuffle);
//나머지 팀들 똑같이 추가
}
\ No newline at end of file