public class Chess {
static final int xmin = 0;
static final int ymin = 0;
static final int xmax = 7;
static final int ymax = 7;
static final int xn = 8;
static final int yn = 8;
static final int north = 0;
static final int east = 1;
static final int south = 2;
static final int west = 3;
static final boolean lives = true;
static final boolean death = false;
static final boolean black = true;
static final boolean white = false;
Chess() {
Board brd = new Board();
brd.printBoard();
}
class Board {
Figure [][] board = new Figure [yn][xn];
Gambler wht;
Gambler blk;
Board () {
int i, j;
for (i = ymin; i <= ymax; i++)
for (j = xmin; j <= xmax; j++)
new Empty (i, j);
this.wht = new Gambler (white);
this.blk = new Gambler (black);
}
void printBoard () {
int i, j;
for (i = ymin; i <= ymax; i++) {
for (j = xmin; j <= xmax; j++)
System.out.print(board[i][j].getfullname() + " ");
System.out.println ();
}
}
class Gambler {
boolean color;
Gambler (boolean color) {
this.color = color;
if (color == white) {
Rook rook1 = new Rook (0, 0, white);
Rook rook2 = new Rook (0, 7, white);
Knight knight1 = new Knight (0, 1, white);
Knight knight2 = new Knight (0, 6, white);
Bishop bishop1 = new Bishop (0, 2, white);
Bishop bishop2 = new Bishop (0, 5, white);
King king = new King (0, 3, white);;
Queen queen = new Queen (0, 4, white);
Pawn pawn1 = new Pawn (1, 0, white);
Pawn pawn2 = new Pawn (1, 1, white);
Pawn pawn3 = new Pawn (1, 2, white);
Pawn pawn4 = new Pawn (1, 3, white);
Pawn pawn5 = new Pawn (1, 4, white);
Pawn pawn6 = new Pawn (1, 5, white);
Pawn pawn7 = new Pawn (1, 6, white);
Pawn pawn8 = new Pawn (1, 7, white);
Bishop test = new Bishop (2, 2, white);
System.out.println (test.make_a_move (south, west, 3, 3));
}
else if (color == black) {
Rook rook1 = new Rook (7, 0, black);
Rook rook2 = new Rook (7, 7, black);
Knight knight1 = new Knight (7, 1, black);
Knight knight2 = new Knight (7, 6, black);
Bishop bishop1 = new Bishop (7, 2, black);
Bishop bishop2 = new Bishop (7, 5, black);
King king = new King (7, 3, black);;
Queen queen = new Queen (7, 4, black);
Pawn pawn1 = new Pawn (6, 0, black);
Pawn pawn2 = new Pawn (6, 1, black);
Pawn pawn3 = new Pawn (6, 2, black);
Pawn pawn4 = new Pawn (6, 3, black);
Pawn pawn5 = new Pawn (6, 4, black);
Pawn pawn6 = new Pawn (6, 5, black);
Pawn pawn7 = new Pawn (6, 6, black);
Pawn pawn8 = new Pawn (6, 7, black);
}
}
}
class Figure {
int x;
int y;
boolean alive;
boolean color;
String name;
int getx() {return x;}
int gety() {return y;}
boolean isalive() {return alive;}
void setdeath() {this.alive = death;}
void setalive() {this.alive = lives;}
void setxy (int y, int x) {this.y = y; this.x = x;board[y][x] = this;}
boolean isset () {return (!this.name.equals("empty"));}
int succx (int direastwest) {
if (direastwest == east)
return -1;
return +1;
}
int succy (int dirnorthsouth) {
if (dirnorthsouth == south)
return -1;
return +1;
}
String getname () {return name;}
String getfullname () {
String cl;
if (name.equals("empty"))
cl = "";
else if (color == white)
cl = "white";
else
cl = "black";
return cl + " " + name;
}
void setname (String name) {this.name = name;}
boolean getcolor () {return color;}
void setcolor (boolean color) {this.color = color;}
}
class Pawn extends Figure {
Pawn (int y, int x, boolean color) {
setalive();
setname ("pawn");
setcolor (color);
setxy (y, x);
}
}
class Rook extends Figure {
Rook(int y, int x, boolean color) {
setalive();
setname ("rook");
setcolor (color);
setxy (y, x);
}
}
class Knight extends Figure {
Knight (int y, int x, boolean color) {
setalive();
setname ("knight");
setcolor (color);
setxy (y, x);
}
}
class Bishop extends Figure {
Bishop (int y, int x, boolean color) {
setalive();
setname ("bishop");
setcolor (color);
setxy (y, x);
}
boolean make_a_move (int dirnorthsouth, int direastwest, int inorthsouth, int ieastwest) {
boolean ok;
int dirx = 1;
int diry = 1;
int newx;
int newy;
if (inorthsouth == ieastwest) {
ok = true;
if (dirnorthsouth == north)
diry = diry * (-1);
else if (dirnorthsouth == south)
diry = diry * 1;
if (direastwest == west)
dirx = dirx * 1;
else if (direastwest == east)
dirx = dirx * (-1);
newx = getx() + (ieastwest * dirx);
newy = gety() + (inorthsouth * diry);
if ((newx < xmin) || (newx > xmax) || (newy < ymin) || (newy > ymax))
ok = false;
if (ok) {
setxy (newx,newy);
System.out.println ("Hea");
}
}
else
ok = false;
return ok;
}
}
class King extends Figure {
King (int y, int x, boolean color) {
setalive();
setname ("king");
setcolor (color);
setxy (y, x);
}
}
class Queen extends Figure {
Queen (int y, int x, boolean color) {
setalive();
setname ("queen");
setcolor (color);
setxy (y, x);
}
}
class Empty extends Figure {
Empty (int x, int y) {
setalive();
setname ("empty");
setxy (y, x);
}
}
}
}