public bool checkgerakan(int x_start, int y_start, int x_end, int y_end, string nama) { board temps1 = boards[tempx, tempy]; if (temps1.warna_team != boards[x_end, y_end].warna_team) { if (nama == "Knight") { if (x_start - x_end == 2 && y_start - y_end == 1) { return(true); } if (x_start - x_end == -2 && y_start - y_end == 1) { return(true); } if (x_start - x_end == 2 && y_start - y_end == -1) { return(true); } if (x_start - x_end == -2 && y_start - y_end == -1) { return(true); } if (x_start - x_end == 1 && y_start - y_end == 2) { return(true); } if (x_start - x_end == -1 && y_start - y_end == 2) { return(true); } if (x_start - x_end == 1 && y_start - y_end == -2) { return(true); } if (x_start - x_end == -1 && y_start - y_end == -2) { return(true); } else { return(false); } } if (nama == "Rook") { bool sementara = true; if (x_start - x_end == 0 && y_start - y_end != 0) { if (y_end - y_start > 0) { for (int i = y_start + 1; i < y_end; i++) { if (boards[x_start, i].nama != "kosong") { sementara = false; } } } else if (y_end - y_start < 0) { for (int i = y_end + 1; i < y_start; i++) { if (boards[x_start, i].nama != "kosong") { sementara = false; } } } if (sementara == true) { return(true); } else { return(false); } } if (x_start - x_end != 0 && y_start - y_end == 0) { ; if (x_end - x_start > 0) { for (int i = x_start + 1; i < x_end; i++) { if (boards[i, y_start].nama != "kosong") { sementara = false; } } } else if (x_end - x_start < 0) { for (int i = x_end + 1; i < x_start; i++) { if (boards[i, y_start].nama != "kosong") { sementara = false; } } } if (sementara == true) { return(true); } else { return(false); } return(true); } else { return(false); } } if (nama == "Bishop") { if (Math.Abs(x_start - x_end) == Math.Abs(y_start - y_end)) { bool sementara = true; if (y_end > y_start) { //bawah int jarak = y_end - y_start; if (x_end > x_start) { //bawah-kanan for (int i = 1; i < jarak; i++) { if (boards[i + x_start, i + y_start].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } if (x_end < x_start) { //bawah-kiri for (int i = 1; i < jarak; i++) { if (boards[x_start - i, y_start + i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } } if (y_end < y_start) { int jarak = y_start - y_end; if (x_end > x_start) { //atas-kanan for (int i = 1; i < jarak; i++) { if (boards[i + x_start, y_start - i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } if (x_end < x_start) { //atas-kiri for (int i = 1; i < jarak; i++) { if (boards[x_start - i, y_start - i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } } return(true); } else { return(false); } } else if (nama == "Queen") { if (Math.Abs(x_start - x_end) == Math.Abs(y_start - y_end)) { bool sementara = true; if (y_end > y_start) { //bawah int jarak = y_end - y_start; if (x_end > x_start) { //bawah-kanan for (int i = 1; i < jarak; i++) { if (boards[i + x_start, i + y_start].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } if (x_end < x_start) { //bawah-kiri for (int i = 1; i < jarak; i++) { if (boards[x_start - i, y_start + i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } } if (y_end < y_start) { int jarak = y_start - y_end; if (x_end > x_start) { //atas-kanan for (int i = 1; i < jarak; i++) { if (boards[i + x_start, y_start - i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } if (x_end < x_start) { //atas-kiri for (int i = 1; i < jarak; i++) { if (boards[x_start - i, y_start - i].nama != "kosong") { sementara = false; } } if (sementara == true) { return(true); } else { return(false); } } } return(true); } else if (x_start - x_end == 0 && y_start - y_end != 0) { bool sementara = true; if (y_end - y_start > 0) { for (int i = y_start + 1; i < y_end; i++) { if (boards[x_start, i].nama != "kosong") { sementara = false; } } } else if (y_end - y_start < 0) { for (int i = y_end + 1; i < y_start; i++) { if (boards[x_start, i].nama != "kosong") { sementara = false; } } } if (sementara == true) { return(true); } else { return(false); } } if (x_start - x_end != 0 && y_start - y_end == 0) { bool sementara = true; if (x_end - x_start > 0) { for (int i = x_start + 1; i < x_end; i++) { if (boards[i, y_start].nama != "kosong") { sementara = false; } } } else if (x_end - x_start < 0) { for (int i = x_end + 1; i < x_start; i++) { if (boards[i, y_start].nama != "kosong") { sementara = false; } } } if (sementara == true) { return(true); } else { return(false); } return(true); } else { return(false); } } else if (nama == "King") { if (x_start - x_end != 0 || y_start - y_end != 0) { if ((Math.Abs(x_start - x_end) == 1 && Math.Abs(y_end - y_start) < 2) || (Math.Abs(y_end - y_start) == 1 && Math.Abs(x_start - x_end) < 2)) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } }