Added a method to get the pieces in order.

This commit is contained in:
Jonathan Turner 2024-02-03 12:39:07 -05:00
parent 0a05da12bb
commit cd266d583d

View File

@ -129,6 +129,29 @@ public class Board {
return false; return false;
} }
/**
* Gets the pieces in order in a single array of size 8.
*
* @precondition none
* @postcondition none
*
* @return the ordered list of values.
*/
public Piece[] getPiecesInOrder() {
Piece[] ordered = new Piece[8];
boolean foundSpace = false;
for (Piece curr : this.pieces) {
if (curr == null) {
foundSpace = true;
} else if (!foundSpace) {
ordered[curr.getLoc()] = curr;
} else {
ordered[curr.getLoc()-1] = curr;
}
}
return ordered;
}
/** /**
* Hashes the board by adding the pieces to an array and hashes the array. * Hashes the board by adding the pieces to an array and hashes the array.
* *