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() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
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 y = 0; y < height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
|
// running a loop for all the position of the chess board
|
||||||
Piece found = null;
|
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) {
|
if (p.getX() == x && p.getY() == y) {
|
||||||
|
// checking for the matching position
|
||||||
found = p;
|
found = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ public class Piece {
|
||||||
|
|
||||||
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y =y;
|
this.y = y;
|
||||||
this.isWhite = isWhite;
|
this.isWhite = isWhite;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue