-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.java
105 lines (78 loc) · 3.52 KB
/
Driver.java
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
97
98
99
100
101
102
103
104
105
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ChessGame;
import java.util.Scanner;
/**
*
* @author Alizey
*/
public class Driver {
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
Chessboard ch = new Chessboard();
int i, j, inirow, inicol, firow, ficol;
// stores the index of the last dead in the Graveyard array.
int dead = 0;
// White pieces are above and black ones are towards bottom initially!
while(true){
dead = Chessboard.gravecounter;
System.out.println("");
for(i = 0; i <= 7; i++){
for(j = 0; j <= 7; j++){
if(Chessboard.boxes[i][j] == null)
System.out.print("-" + " ");
else
System.out.print(Chessboard.boxes[i][j]+" ");
}
System.out.println("");
}
System.out.println("");
if(Chessboard.chance%2 == 0)
System.out.println("White's chance!");
else
System.out.println("Black's chance!");
System.out.println("");
System.out.println("Enter the initial location of the piece you want to move and then its final location all seperated by enters!");
inirow = sc.nextInt();
inicol = sc.nextInt();
firow = sc.nextInt();
ficol = sc.nextInt();
Chessboard.boxes[inirow][inicol].move(inirow, inicol, firow, ficol);
/*
This loop is for checking the condition for when after a piece moves
it
*/
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
if(Chessboard.boxes[i][j] != null){
//System.out.print("ch ");
if(Chessboard.boxes[i][j].check(i, j) == true){
System.out.println("Invalid move, this will get your king killed!");
// even if one piece threatens the king it is check, and hence we can break out of
// the loop to avoid multiple printing of message.
/*Avoiding the move here because this will result in a checkmate and thus, reducing the
chance counter in order to revert chance
*/
Chessboard.chance--;
/*Reverting back the move*/
Chessboard.boxes[inirow][inicol] = Chessboard.boxes[firow][ficol];
/* This part is necessary for the bringing back of a piece which
got killed due to a wrong move.
*/
if(dead != Chessboard.gravecounter){
//System.out.println("Hey");
Chessboard.boxes[firow][ficol] = Chessboard.graveyard[dead];
}
else
Chessboard.boxes[firow][ficol] = null;
break;
}
}
}
}
}
}
}