modifying the for loop styles but keep the same function, and add some
documentations
This commit is contained in:
parent
b1e2a261d6
commit
96cc2788c1
|
|
@ -87,12 +87,18 @@ public class Board {
|
|||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// A Java helper class for efficiently building up a string piece by piece.
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
// running a loop for all the position of the chess board
|
||||
Piece found = null;
|
||||
for (Piece p : Pieces) {
|
||||
for (int i = 0; i < Pieces.size(); i++) {
|
||||
// running a loop for all the elements in the list Pieces
|
||||
Piece p = Pieces.get(i);
|
||||
// cannot write Pieces(i) like Matlab
|
||||
if (p.getX() == x && p.getY() == y) {
|
||||
// checking for the matching position
|
||||
found = p;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class Piece {
|
|||
|
||||
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
||||
this.x = x;
|
||||
this.y =y;
|
||||
this.y = y;
|
||||
this.isWhite = isWhite;
|
||||
this.type = type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue