-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess.java
More file actions
60 lines (42 loc) · 1.08 KB
/
chess.java
File metadata and controls
60 lines (42 loc) · 1.08 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
import java.util.Random;
// ---chess game
// ---board function
// ----square function
//16 pieces for each one
//manipulate 2d arrays
//analyze data stored in 2d array to make decisions
//deal appropriately with null values
// ----make square white or black
// ----make randomly place the pieces on the board
// ---make us move a piece pawns
// ----insert coordinate and see if there is a piece there
//----
public class chessboard{
int[][] board= new int[8][8];
//board[0][0]=1;
public int square(int i, int j){
return board[i][j];
}
public int changesquare(int i, int j, int value){
board[i][j]=value;
}
public void randomize(){
Random ran= new Random();
for(int i=0; i<board.length; i++){
for(int j=0; j<board.length; j++){
board[i][j]=ran.nextInt(2);
}
}
}
public void setcolor(){
for(int i=0; i<board.length; i++){
for(int j=0; j<board.length; j++){
if(i%2==j%2){
board[i][j]=0; //black
}
else{
board[i][j]=1; //white
}
}
}
}