From 62da4a9ea59af2f0b08b26292fc81e642bd2bbf2 Mon Sep 17 00:00:00 2001 From: peet Date: Fri, 14 Jun 2024 12:01:59 +0200 Subject: [PATCH] ahhhhhhhhh --- bin/uebung09/chess/Board.class | Bin 3418 -> 3201 bytes bin/uebung09/iterator/Array2dIterator.class | Bin 1145 -> 1145 bytes src/uebung09/chess/Board.java | 23 ++++++++++++-------- src/uebung09/iterator/Array2dIterator.java | 20 +++++++++++++++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/bin/uebung09/chess/Board.class b/bin/uebung09/chess/Board.class index 8dee0abad3d8fd1f824fb8c39b8e981d60883f9d..fe2a88c2555cd9fad422f0479cc0ef0bc7f81f2c 100644 GIT binary patch literal 3201 zcmaJ@YjYD-7=BKYcGIw>B~WQ;fj~jqv>{NjDyh{HEmYcq6hXk-cC)lgx4Ut(0jhXG z@qWK6UO(vc6Eo^)(K4faQD^)E{uhQ3pR=2^=>;-#cF*NK&w1YGeb2l3=fBzC0rcTp z1tEboMPsyRk8Qs@t&bapLVCBOxj6+9f%=o$DJ^Yj_E>uV=t)EO6jTeu=Vu2z!_`JD zL!jz}X;?Xd#^c8a7vUW+4c*8HRQH&+>GcYP+u9EcM6yoKh#`zx6*Y({h}M8ds$fr` zZqT%i;o{_|;T{T3hz~ltW*ydCQ;tiM5pUcq2;8#xOy38d8P;+n)zr3lJ>b-SIEF^7 zQ_!?j1>ZtNGg<_qV}|D=(!aL$#aO{v3N{FAu8_vEj4{pXbH|F4hV4CYMmO@F>DW;u z1Xi4O9eXS>DwU35JvK`TS_K-~2Imn*JlC|xG6Bi0DsIJX6p>U8I;VXR2PFG;70L2K z*0EyLuv0|}+XR%nRKCv>Sl2c%u!MJ@K@8i`rC`T`Xa`5DxE(tQb4s&{#{Lrmw^q^% zG9uHylyRKN)ve-A+$FGfQkyWcj;(9n5z`xIui$C6$CxbuEBm?>jH%_ju}qKy2N)jX zj9Kugl|b!?r|AlVpoHE(Wl_Pg^o@YJY!PDZe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void add(Piece piece) { @@ -19,7 +16,6 @@ public class Board implements Iterable{ if (existing != null) throw new IllegalArgumentException("already occupied by " + existing); field[piece.getRow() - 1][piece.getCol() - 1] = piece; - pieces.add(piece); } public void printBoard() { @@ -42,9 +38,9 @@ public class Board implements Iterable{ } public void check() { - for (Piece p1 : pieces) { + for (Piece p1 : this) { System.out.println(p1.toString()); - for (Piece p2 : pieces) + for (Piece p2 : this) if (p1 != p2) if (p1.canCapture(p2)) System.out.println(" can capture " + p2.toString()); @@ -54,13 +50,22 @@ public class Board implements Iterable{ } public String toString() { - return pieces.toString(); + // StringBuilder s = new StringBuilder("["); + + // for(Piece p : this) { + // s.append(p.toString()); + // } + + // s.append("]"); + + // return s.toString(); + return ""; } @Override public Iterator iterator() { // TODO Auto-generated method stub - return new Array2dIterator<>(null); - //throw new UnsupportedOperationException("Unimplemented method 'iterator'"); + return new Array2dIterator<>(field); + // throw new UnsupportedOperationException("Unimplemented method 'iterator'"); } } diff --git a/src/uebung09/iterator/Array2dIterator.java b/src/uebung09/iterator/Array2dIterator.java index 0310dee..8d9b507 100644 --- a/src/uebung09/iterator/Array2dIterator.java +++ b/src/uebung09/iterator/Array2dIterator.java @@ -1,6 +1,5 @@ package uebung09.iterator; -import java.util.ArrayList; import java.util.Iterator; import java.util.NoSuchElementException; @@ -14,15 +13,30 @@ public class Array2dIterator implements Iterator{ this.array = array; } + + /** + * Returns {@code true} if the iteration has more elements. + * (In other words, returns {@code true} if {@link #next} would + * return an element rather than throwing an exception.) + * + * @return {@code true} if the iteration has more elements + */ @Override public boolean hasNext() { + while(row < array.length && (array[row] == null || col >= array[row].length)) { row++; col = 0; } - return row > array.length; + return row < array.length; } + /** + * Returns the next element in the iteration. + * + * @return the next element in the iteration + * @throws NoSuchElementException if the iteration has no more elements + */ @Override public T next() { if (!hasNext()) { @@ -30,4 +44,6 @@ public class Array2dIterator implements Iterator{ } return array[row][col++]; } + + }