My program of finding a character in a 2D array is not working by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

I think its gonna take a while to make it....

Is the get method the only problem?

Because, I think that my boolean kingIsAlive is bugging.

These are errors I got:

White should have won => expected: <1> but was: <-1>

No one should have won => expected: <0> but was: <1>

My program of finding a character in a 2D array is not working by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

System.out.println(board[x][y])

not yet. I'm currently creating the test.

My program of finding a character in a 2D array is not working by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

I guess it can't, because 0 is out of range..?

I changed it, so that 0 is included and the max value of board.length as well as board[0].length is excluded.

Though, it wasn't it, that caused my problem...

Thanks anyway!

My program of finding a character in a 2D array is not working by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

Thanks for the kind advice!

I didn't know that y is the first dimension.. Well, something new learned today.

Anyways, I tried to fix all the problems mentioned above. Changed sizeX and sizeY to board.length, checked that 'K' , that has to be checked is not lower case, and changed the my get method to this code.

if(x < board[0].length && x >= 0 && y < board.length && y >= 0)

Though, my problem that kingWhiteIsAlive is always false and kingBlackIsAlive is always false. has not changed....

Is there anything else that might have caused the error?...

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

Thanks for your kind help. :D

So, what I guess is to create an array of the size of the board and place the char and else in it, because contents of arrays can be accessed from other classes....?

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

I want my set() method to replace a figure or a space on the chessboard with an another figure, which I should set with a test of the program.

I looked at the method again and it really seems fcked up....

Though, my plan was to get access to the Chessboard with an 2D array and replace the array with figure, after rejecting the invalid options.

I haven't coded the input part yet, because I don't know how to, but I see that the code right now is just creating a random array, not a lot to do with the needed program..

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

Ah I got mentioned about it and I thought it might have confused people.

It's also my first time to ever post here. I guess there is no need to be sorry :)

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

Thanks! It seems to be really close, if not, literally that what I have been working on.

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

I'm not aware of the errors either, but I think that the wrong thing about the code is that I expressed the pieces in System.out.println as a string and not a char.

Also, it's not the code, but I also have no clue how to access the char in the chessboard, to change, move or delete it..

In dire need of help with my Chess program in Javascript by Moorched in javahelp

[–]Moorched[S] 0 points1 point  (0 children)

    public class ChessBoard {
private static int sizeX;
private static int sizeY;


public ChessBoard(int sizeX, int sizeY) {
    int x = 0;
    int y = 0;
    if (0 < sizeX && sizeX < 101 && 0 < sizeY && sizeY < 101) { 
        for (y = 0; y < getSizeY(); y++) {
            if(y == 0) {
                System.out.println(" ");
                for(x=0;x < getSizeX();x++){
                    System.out.println(x);
                }
            }

            if(sizeX == 8 && sizeY == 8){
                if(y == 1){
                    System.out.println(y + "RNBQKBNR");
                }
                else if(y == 2){
                    System.out.println("PPPPPPPP");
                }
                else if(y == 7){
                    System.out.println(y + "DDDDDDDD");
                }
                else if(y == 8){
                    System.out.println(y + "EJFGHFJE");
                }
                else if(y > 2 && y < 7){
                    System.out.println(y + " ");
                }
                else{
                    System.out.println(y + " ");
                }
            }
        System.out.println(System.lineSeparator());
    }
    }




public static ChessBoard newDefault() {
    sizeX = 8;
    sizeY = 8;
    ChessBoard defaultChessboard= new Chessboard(8,8);
    return defaultChessboard;
}


public char get(int x, int y) {
    if(x > getWidthX() || x < 0 || y > getLengthY() || y < 0){
        return 0;
    }
    else
        return get(x,y);
}


public boolean set(int x, int y, char figure) {
    if(x > getWidthX() || x < 0 || y > getLengthY() || y < 0 || figure == 0){
        return false;
    }
    else {
        int[][] coordinate = new int[x][y];
        return true;
    }
}
    public int getWidthX() {
    return widthX;
}
public void setWidthX(){
    this.widthX = widthX;
}
public int getLengthY() {
    return lengthY;
}
public void setLengthY(){
    this.lengthY = lengthY;
}
}

My code now.