changed code -> Added separate movement for double pieces.

master
ElGurkus 4 years ago
parent a5347b16f2
commit 7c14adaafa

@ -5,7 +5,9 @@ let down2;
let up;
let up2;
let left;
let left2;
let right;
let right2;
let topRight;
let topLeft;
let bottomRight;
@ -165,6 +167,54 @@ function validMovesPlayer1(field){
topRight.validMove = 2;
}
}
if(field.piece === 11){
if((field.fieldNum + 16) < 64) {
down2 = document.getElementById("field" + (field.fieldNum + 16).toString());
if(down.validMove === 1 && down2.piece === 0){
down2.validMove = 1;
}
}
if((field.fieldNum + 2) <= rowMax){
right2 = document.getElementById("field" + (field.fieldNum + 2).toString());
if(right.validMove === 1 && right2.piece === 0){
right2.validMove = 1;
}
}
if((field.fieldNum - 2) >= rowMin){
left2 = document.getElementById("field" + (field.fieldNum - 2).toString());
if(left.validMove === 1 && left2.piece === 0){
left2.validMove = 1;
}
}
if((field.fieldNum + 7) >= (rowMin + 8) && (field.fieldNum + 7) < 64) {
bottomLeft = document.getElementById("field" + (field.fieldNum + 7).toString());
if (bottomLeft.piece === 2 || bottomLeft.piece === 22){
bottomLeft.validMove = 2;
} else if (bottomLeft.piece === 0) {
bottomLeft.validMove = 1;
}
}
if((field.fieldNum + 9) <= (rowMax + 8) && (field.fieldNum + 9) < 64) {
bottomRight = document.getElementById("field" + (field.fieldNum + 9).toString());
if (bottomRight.piece === 2 || bottomRight.piece === 22){
bottomRight.validMove = 2;
} else if (bottomRight.piece === 0) {
bottomRight.validMove = 1;
}
}
if((field.fieldNum - 9) >= (rowMin - 8) && (field.fieldNum - 9) >= 0) {
topLeft = document.getElementById("field" + (field.fieldNum - 9).toString());
if (topLeft.piece === 0){
topLeft.validMove = 1;
}
}
if((field.fieldNum - 7) <= (rowMax - 8) && (field.fieldNum - 7) >= 0) {
topRight = document.getElementById("field" + (field.fieldNum - 7).toString());
if (topRight.piece === 0){
topRight.validMove = 1;
}
}
}
for(let i = 0; i < 64; i++){
fieldId = i.toString();
if(document.getElementById("field"+fieldId).validMove === 1){
@ -246,6 +296,54 @@ function validMovesPlayer2(field){
bottomRight.validMove = 2;
}
}
if(field.piece === 22){
if((field.fieldNum - 16) >= 0) {
up2 = document.getElementById("field" + (field.fieldNum - 16).toString());
if(up.validMove === 1 && up2.piece === 0){
up2.validMove = 1;
}
}
if((field.fieldNum + 2) <= rowMax){
right2 = document.getElementById("field" + (field.fieldNum + 2).toString());
if(right.validMove === 1 && right2.piece === 0){
right2.validMove = 1;
}
}
if((field.fieldNum - 2) >= rowMin){
left2 = document.getElementById("field" + (field.fieldNum - 2).toString());
if(left.validMove === 1 && left2.piece === 0){
left2.validMove = 1;
}
}
if((field.fieldNum + 7) >= (rowMin + 8) && (field.fieldNum + 7) < 64) {
bottomLeft = document.getElementById("field" + (field.fieldNum + 7).toString());
if (bottomLeft.piece === 0) {
bottomLeft.validMove = 1;
}
}
if((field.fieldNum + 9) <= (rowMax + 8) && (field.fieldNum + 9) < 64) {
bottomRight = document.getElementById("field" + (field.fieldNum + 9).toString());
if (bottomRight.piece === 0) {
bottomRight.validMove = 1;
}
}
if((field.fieldNum - 9) >= (rowMin - 8) && (field.fieldNum - 9) >= 0) {
topLeft = document.getElementById("field" + (field.fieldNum - 9).toString());
if(topLeft.piece === 1 || topLeft.piece === 11){
topLeft.validMove = 2;
} else if (topLeft.piece === 0){
topLeft.validMove = 1;
}
}
if((field.fieldNum - 7) <= (rowMax - 8) && (field.fieldNum - 7) >= 0) {
topRight = document.getElementById("field" + (field.fieldNum - 7).toString());
if(topRight.piece === 1 || topRight.piece === 11){
topRight.validMove = 2;
} else if (topRight.piece === 0){
topRight.validMove = 1;
}
}
}
for(let i = 0; i < 64; i++){
fieldId = i.toString();
if(document.getElementById("field"+fieldId).validMove === 1){

Loading…
Cancel
Save