From cd266d583d3eca53dfa346f8eaf426d38b568352 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 3 Feb 2024 12:39:07 -0500 Subject: [PATCH] Added a method to get the pieces in order. --- src/Assignments/A1/models/Board.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Assignments/A1/models/Board.java b/src/Assignments/A1/models/Board.java index a5bb737..416c3ce 100644 --- a/src/Assignments/A1/models/Board.java +++ b/src/Assignments/A1/models/Board.java @@ -129,6 +129,29 @@ public class Board { 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. *