-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpieces_move.js
More file actions
96 lines (89 loc) · 2.92 KB
/
Copy pathpieces_move.js
File metadata and controls
96 lines (89 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function change(positionx, positiony, piece1,piece2, box, className, color1,color2) {
if ((select1 && select2) && (temp_positionx !== positionx || temp_positiony !== positiony)) {
if (temp_color1 === color1 && temp_color2 === color2) {
select1 = '';
select2 = '';
mainloop();
} else {
if (conditions(temp_positionx, temp_positiony, positionx, positiony, temp_color1,temp_color2, select1,select2)) {
chess1[positionx][positiony] = select1;
chess2[positionx][positiony] = select2;
colors1[positionx][positiony] = temp_color1;
colors2[positionx][positiony] = temp_color2;
select1 = '';
select2 = '';
colors1[temp_positionx][temp_positiony] = '';
colors2[temp_positionx][temp_positiony] = '';
chess1[temp_positionx][temp_positiony] = '';
chess2[temp_positionx][temp_positiony] = '';
board.innerHTML = '';
if (type_c==1){
box.style.color = temp_color1;
}
else {
box.style.color = temp_color2;
}
change_move();
mainloop();
}
else {
select1 = '';
select2 = '';
newClass = className;
box.className = newClass;
mainloop();
}
}
}
else if(temp_positionx === positionx || temp_positiony === positiony){
select1 = '';
select2 = '';
mainloop();
}
else {
// Ensure temp_color and temp are updated even when there's no piece selected
if (color1==move) {
temp_positionx = positionx;
temp_positiony = positiony;
temp_color1= color1;
temp_color2= color2;
select1 = piece1;
select2 = piece2;
let newClass = className + ' select';
box.className = newClass;
if (isvalid){ valid_move(temp_positionx,temp_positiony,temp_color1,temp_color2,select1,select2,className);
}}
else{
// this is other players move
alert('Now opposite player move')
}
}
}
let select
function selectPiece(option){
if (option=="Bishop") {
select1="♝"
select2="♗"
}
else if (option=="Queen") {
select1="♛"
select2="♕"
}
else if (option=="Rook") {
select1="♜"
select2="♖"
}
else if (option=='Knight') {
select1="♞"
select2="♘"
}
Xx=promotion_box.value[0]
Yy=promotion_box.value[1]
promotePawn(Xx,Yy,select1,select2)
promotion_box.style.display='none'
}
function promotePawn(positionx, positiony,select1,select2){
chess1[positionx][positiony] = select1;
chess2[positionx][positiony] =select2;
mainloop()
}