/media/sda-magnetic/david/Extern-Magnetic-2022-06-29/Extern01/Dokumente-2020-11-16/disk10-ab-2020-01-10/02-debian-pc2-work/informatik/java-real/chess/chessv2/Chess.java


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 (north, west, 1, 1)); 
                }
                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 setx(int x) { this.x = x;}
            void sety(int y) {this.y = y;} 
            void setxy (int x, int y) {this.y = y; this.x = x;}
            
            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 x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("pawn");
                setcolor (color);
                board [x][y] = this;
            }    
        }
        class Rook extends Figure {
            Rook(int x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("rook");
                setcolor (color);
                board [x][y] = this;
            }
        }
        class Knight extends Figure {
            Knight (int x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("knight");
                setcolor (color);
                board [x][y] = this;
            }    
        }
        class Bishop extends Figure {
            Bishop (int x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("bishop");
                setcolor (color);
                board [x][y] = this;
            }
            boolean make_a_move (int dirnorthsouth, int direastwest, int inorthsouth, int ieastwest) {
                boolean ok;
                int dirx = 1;
                int diry = 1;
                
                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);
                                        
                                        
                    if ((dirnorthsouth == south) && (direastwest == east))  {
                        if (((getx() + ieastwest) > xmax) || ((gety() + inorthsouth) > ymax))
                            ok = false;
                    }
                    else if ((dirnorthsouth == south) && (direastwest == west)) {
                        if (((getx() + ieastwest)  > xmax) || ((gety() - inorthsouth) < ymin))
                            ok = false;
                    }
                    else if ((dirnorthsouth == north) && (direastwest == east)) {
                        if (((getx() - ieastwest)  < xmin) || ((gety() + inorthsouth) > ymax))
                            ok = false;
                    }
                    else if ((dirnorthsouth == north) && (direastwest == west)) {
                        if (((getx() - ieastwest)  < xmin) || ((gety() - inorthsouth) < ymin))
                            ok = false;
                    }

                    int i;
                    int j;
                    
                        
                    /*for (i = gety(), j = getx(); (i < (diry*inorthsouth + gety())) && (j < (dirx*ieastwest + getx()));  i += diry, j += dirx)
                        if (board[i][j].getname().equals("empty") == true)
                            ok = false;
                    if (ok) {
                        if (board[i][j].getcolor() == getcolor())
                            ok = false;
                    }*/
                    if (ok) {
                        setxy (x,y);
                    }
                }
                else
                    ok = false;
                return ok;
            }
        }
        class King extends Figure {
            King (int x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("king");
                setcolor (color);
                board [x][y] = this;
            }
        }
        class Queen extends Figure {
            Queen (int x, int y, boolean color) {
                setalive();
                setx (x);
                sety (y);
                setname ("queen");
                setcolor (color);
                board [x][y] = this;
            }
        }
        class Empty extends Figure {
            Empty (int x, int y) {
                setalive();
                setx (x);
                sety (y);
                setname ("empty");
                board [x][y] = this;
            }
        }
    }
}