Why is the board displayed so strangely after the pawn movement?
I would be extremely grateful to each and every one of you if you could help me!
Hello everyone,
We've been tasked with implementing a very stripped-down version of the game of chess. That is, as my code currently stands, it's essentially complete in terms of functionality. However, two problems arise: First, in a JUnit test, the knight can't be moved from square [4][4] to square [6][5], and the pawn movement functions very poorly and irregularly.
This means that all black pawns move to [2][0], and all white pawns below are not allowed to move. Except for the [6][6], which then moves to the [5][0] square.
My code is basically structured in such a way that there is a ChessPiece superclass from which the individual game piece classes inherit and a ChessBoard class that maps the board and moves pieces.
I've been desperate for two days because neither I nor AI could help me. So I would be incredibly grateful if one of you could rescue me.
I try to show the most important implementations in the pictures.
The main method:
Creating the fields:
The method should roughly say whether a movement is true or false:
Output the field:
The executing movement method:
Example output:
Knight movement with JUnit test:
If you need anything else, let me know. I would be incredibly grateful if you could help me!
For the first time, you could upload the code somewhere as a text and then link, that would be easier.
To the first picture:
Why not an array for farmers? Or Why are you saving the peasants?
Figure two:
You confuse x and y coordinates.
Figure three:
The method must also return "false" if the farmer stands at the end of the chess field, since he cannot go out there.
It should also be noted that the farmer is converted to the last field and that there is "En passant".
Figure five:
The code is wrong.
It is not checked whether the king is put into chess or chessmate by the movement of the figure.
The design is badly chosen, since field and figure can clearly change the position independently of each other.
Both should only be changed together.
Figure six:
Look, you kind of formatting that it's uniform. For example, give each fogur a separate character (eg according to chess notation) and mark all empty fields of a color also with a specific symbol (so that a pattern results).
Figure seven:
Take the absolute value, then you have fewer cases to distinguish. For example, you can also simply see if the absolute sum of the differences 3 results and both are absolute values smaller than 3.
The indentations are not uniform again.
You may ask "targetPiece" or the position more often. One of the expenses is in the wrong place.
The method shouldn't take over the punch! Only check if the movement is allowed.
to the first image, I have let individual objects of the individual classes initialize again, because the otherwise no object of Chesspiece recognizes when I call in the main method movePiece.
picture two: I have seen, I have changed
picture three/five: as it is a bit spun, we don't have to do anything about say 10 moves out, so without chess, without turning, without en passant etc
picture six: we have the pretend that empty fields must be zero
picture seven: I had the Math.abs solution before, but I changed it because I hoped it worked then
the main problem with the field of play of the builders unfortunately still exists, you know maybe why?
I don't get along with it. The type of array should be clear, that shouldn't there be problems?
The fact that the peasant cannot pull out of the field (and also no other figure) must be taken into account.
In addition, I notice that you are partially attacking parts of the array without having verified that the indices you use are valid.
But you can vary the issue, right? So it looks beautiful?
And the other thing that you have implemented the blow in the method. Is it when you remove it?
Looked at it again. Problem seems to be the issue. You don't give up anything for empty fields, so the only figure of the line slips at the beginning.
You know if you don't mind, you know if you don't mind.
My proposal for the figures:
For the empty white fields a blank (additional to the separator), for the empty black fields a #.
You can distinguish different colors by big vs. small.
Example:
I found out that all the figures I move from the beginning towards the inside. that is, if I move the jumper, the other figures moved to the left into the array. That means if I move into the field, all slide into the 0. You know what it is
I got it with your hint that the characters slip in, I didn't know that. I have now added the empty fields when output — now works!!! "cheek" that will definitely help me, thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!