Linkedlists
__MACOSX/._sp21-homework-5-MueezOdusanya sp21-homework-5-MueezOdusanya/homework5.iml sp21-homework-5-MueezOdusanya/TestHexBoard.tst 984278095="NoSuchElementException" 890540989=2 1318093596="false" 1899087169="false" 1563298685="false" 363200885="null" 2013750705="true" 221027861="true" 1502452343="false" 2097102435="false" 171969021=1 924173642="NullPointerException" 948342169="true" __MACOSX/sp21-homework-5-MueezOdusanya/._test __MACOSX/sp21-homework-5-MueezOdusanya/._bin sp21-homework-5-MueezOdusanya/TestPieceCollection.tst 1442026135="true" 263759869="false" 48303607="true" 1928879295="NullPointerException" 330480954="true" 434214267="IllegalArgumentException" 1764796602="IllegalArgumentException" 636855615="NoSuchElementException" 479813527=2 sp21-homework-5-MueezOdusanya/.classpath sp21-homework-5-MueezOdusanya/.project homework5 org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature __MACOSX/sp21-homework-5-MueezOdusanya/._lib __MACOSX/sp21-homework-5-MueezOdusanya/._.git __MACOSX/sp21-homework-5-MueezOdusanya/._.idea __MACOSX/sp21-homework-5-MueezOdusanya/._src sp21-homework-5-MueezOdusanya/test/map.hex LAND<6,1,5> LAND<6,2,4> WATER<6,3,3> WATER<6,4,2> WATER<6,5,1> LAND<6,6,0> MOUNTAIN<7,1,6> LAND<7,7,0> WATER<7,4,3> WATER<7,5,2> CITY<7,6,1> LAND<7,3,4> LAND<7,2,5> DESERT<8,1,7> LAND<8,8,0> MOUNTAIN<8,2,6> MOUNTAIN<8,3,5> FOREST<8,4,4> LAND<8,7,1> LAND<8,6,2> LAND<8,5,3> MOUNTAIN<9,4,5> DESERT<9,1,8> LAND<9,9,0> FOREST<9,5,4> LAND<9,8,1> LAND<9,7,2> LAND<9,6,3> DESERT<9,3,6> DESERT<9,2,7> MOUNTAIN<10,4,6> LAND<10,1,9> LAND<10,10,0> FOREST<10,5,5> WATER<10,8,2> WATER<10,7,3> WATER<10,6,4> LAND<10,9,1> DESERT<10,3,7> DESERT<10,2,8> WATER<11,6,5> LAND<11,1,10> DESERT<11,3,8> LAND<11,2,9> WATER<11,11,0> MOUNTAIN<11,4,7> FOREST<11,5,6> WATER<11,10,1> WATER<11,9,2> LAND<11,7,4> LAND<11,8,3> FOREST<12,7,5> LAND<12,11,1> LAND<12,2,10> FOREST<12,5,7> FOREST<12,6,6> CITY<12,9,3> LAND<12,10,2> LAND<12,8,4> DESERT<12,3,9> DESERT<12,4,8> MOUNTAIN<13,6,7> LAND<13,11,2> DESERT<13,3,10> LAND<13,10,3> LAND<13,9,4> FOREST<13,7,6> LAND<13,8,5> DESERT<13,4,9> LAND<13,5,8> LAND<14,11,3> LAND<14,4,10> MOUNTAIN<14,7,7> LAND<14,10,4> FOREST<14,8,6> FOREST<14,9,5> FOREST<14,6,8> LAND<14,5,9> FOREST<15,11,4> WATER<15,5,10> MOUNTAIN<15,7,8> FOREST<15,10,5> WATER<15,6,9> FOREST<15,8,7> FOREST<15,9,6> WATER<16,11,5> WATER<16,6,10> WATER<16,7,9> WATER<16,8,8> WATER<16,9,7> WATER<16,10,6> sp21-homework-5-MueezOdusanya/test/sample.gam BLUE/BOAT<7,5,2> GREEN/TANK<8,4,4> GREEN/FOOT<9,4,5> RED/HORSE<10,3,7> RED/HORSE<11,3,8> BLUE/CAR<7,6,1> __MACOSX/sp21-homework-5-MueezOdusanya/bin/._edu sp21-homework-5-MueezOdusanya/bin/TestHexBoard.class sp21-homework-5-MueezOdusanya/bin/UnlockTests.class sp21-homework-5-MueezOdusanya/bin/TestInvariant.class sp21-homework-5-MueezOdusanya/bin/TestPieceCollection.class sp21-homework-5-MueezOdusanya/bin/TestEfficiency.class sp21-homework-5-MueezOdusanya/bin/TestCollection.class sp21-homework-5-MueezOdusanya/lib/car-compact-2.png sp21-homework-5-MueezOdusanya/lib/boat.png sp21-homework-5-MueezOdusanya/lib/relaxing-walk-2.png sp21-homework-5-MueezOdusanya/lib/relaxing-walk.png sp21-homework-5-MueezOdusanya/lib/boat-2.png sp21-homework-5-MueezOdusanya/lib/quiet-horse-side-view-silhouette.png sp21-homework-5-MueezOdusanya/lib/homework5.jar META-INF/MANIFEST.MF Manifest-Version: 1.0 Created-By: 11.0.9.1 (Debian) edu/uwm/cs351/util/ColoredIcon.class package edu.uwm.cs351.util; public synchronized class ColoredIcon { private static final int ALPHA_MASK = -16777216; public void ColoredIcon(); public static javax.swing.Icon color(javax.swing.Icon, java.awt.Color); } edu/uwm/cs351/util/ColoredIcon.java edu/uwm/cs351/util/ColoredIcon.java package edu.uwm.cs351.util; import java.awt.Color; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.Icon; import javax.swing.ImageIcon; public class ColoredIcon { private static final int ALPHA_MASK = 0xFF000000; public static Icon color(Icon icon, Color color) { if (!(icon instanceof ImageIcon)) throw new UnsupportedOperationException("can't handle"); ImageIcon ii = (ImageIcon)icon; Image i = ii.getImage(); int width = i.getWidth(null); int height = i.getHeight(null); BufferedImage newbi = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); newbi.getGraphics().drawImage(i, 0, 0, null); for (int x=0; x
< height; ++y) { int pixel =" newbi.getRGB(x,y);" int alpha =" pixel & ALPHA_MASK;" if (alpha !=" 0) {" pixel =" alpha |(color.getRGB() & ~ALPHA_MASK);" newbi.setrgb(x, y, pixel);="" }="" }="" }="" return new imageicon(newbi);="" }="" }="" edu/uwm/cs351/hexcoordinate.class="" package="" edu.uwm.cs351;="" public="" synchronized="" class="" hexcoordinate="" {="" private="" final="" int="" a;="" private="" final="" int="" b;="" private="" final="" int="" c;="" public="" static="" final="" float="" height_ratio;="" private="" static="" final="" float="" third="0.33333334;" private="" static="" final="" float="" twothird="0.6666667;" public="" void="" hexcoordinate(int,="" int);="" public="" void="" hexcoordinate(int,="" int,="" int)="" throws="" illegalargumentexception;="" public="" int="" a();="" public="" int="" b();="" public="" int="" c();="" public="" boolean="" equals(object);="" public="" int="" hashcode();="" public="" string="" tostring();="" public="" static="" hexcoordinate="" frompoint(java.awt.point,="" int);="" public="" java.awt.point="" topoint(int);="" private="" static="" java.awt.point="" topoint(int,="" float,="" float);="" public="" java.awt.polygon="" topolygon(int);="" public="" int="" distance(hexcoordinate);="" public="" static="" hexcoordinate="" fromstring(string)="" throws="" formatexception;="" static="" void=""> height; ++y) {>
(); } edu/uwm/cs351/HexCoordinate.java edu/uwm/cs351/HexCoordinate.java package edu.uwm.cs351; import java.awt.Point; import java.awt.Polygon; /** * Coordinates on a hexagon-filled game board. *
*- a
- left to right (0 = left edge, moving left half a hex each line down) *
- b
- top to bottom (0 = top edge) *
- c
- left to right (0 = top edge, moving right half a hex each line down) *
* The {@link #c()} coordinate is always the difference of the first two. */ public class HexCoordinate { private final int a, b, c; /** * Create a hexagonal coordinate by specifying the first two coordinates * and computing the third. * @param a first coordinate * @param b second coordinate */ public HexCoordinate(int a, int b) { // #( this.a = a; this.b = b; this.c = a - b; // #) // TODO: Very easy. See handout. } /** * Create a hexagonal coordinate by specifying all three coordinates, * which must be consistent. * @param a * @param b * @param c * @exception IllegalArgumentException if the coordinates are not consistent. */ public HexCoordinate(int a, int b, int c) throws IllegalArgumentException { // #( if (a - b != c) throw new IllegalArgumentException("c coordindate must be the difference of a and b: " + c + " != " + a + " + " + b); this.a = a; this.b = b; this.c = c; // #) // TODO: Check consistency and then assign fields. } /// three simple accessors /** Return the first coordinate (how far from left * plus more every line). * @return the first coordinate */ public int a() { return a; } /** * Return the second coordinate (how far from top). * @return the second coordinate */ public int b() { return b; } /** * Return the third coordinate (how far from left * minus more very line). * @return the third coordinate */ public int c() { return c; } /// Overrides // no need to give a documentation comment if overridden documentation still is valid. // return true iff x is another HexCoordinate with the same value @Override public boolean equals(Object x) { // #( if (x instanceof HexCoordinate) { HexCoordinate other = (HexCoordinate)x; if (other.a == a && other.b == b) return true; } return false; // #) // TODO } @Override public int hashCode() { return a ^ (b < 8); //return some combination of a, b and c that distinguishes similar coordinates="" }="" ="" ="" @override="" public string tostring() {="" // #(=""> 8);><"+a+","+b+","+c+">"; // #) // TODO: return a string of the form <3,2,1> } /** * Return the closest hex coordinate to this point. * If two are equally close, either may be returned. * @param p * @param width width of grid (must NOT be negative or zero) * @return closest hex coordinate */ public static HexCoordinate fromPoint(Point p, int width) { float height = width * HEIGHT_RATIO; float db = p.y/height; float da = (float)p.x/width + db/2.0f; float dc = da - db; int ac = (int)Math.floor((da+dc)); int ab = (int)Math.floor((da+db)); int bc = (int)Math.floor((db-dc)); int a = (int)Math.ceil((ab+ac)/3.0); int b = (int)Math.ceil((ab+bc)/3.0); return new HexCoordinate(a,b); } /// Other accessors //define HEIGHT_RATIO is the ration of height to width public static final float HEIGHT_RATIO = (float) (Math.sqrt(3.0)/2.0); // height of a row, given width = 1.0 private static final float THIRD = 1.0f/3.0f; private static final float TWOTHIRD = 2.0f/3.0f; /** * Return center of hexagon as a point on the two-dimensional AWT plane. * @param width width of hexagon * @return Point in the center of the hexagon */ public Point toPoint(int width) { // #( return toPoint(width, a, b); // #) // TODO: call the other toPoint method with the correct coordinates } /** * A generalization of {@link #toPoint(int)} that takes two floats, to permit * fractions into the coordinate space. * @param width width of hexagon in grid * @param a first coordinate * @param b second coordinate * @return [x,y] point for this location. */ private static Point toPoint(int width, float a, float b) { float height; // #( height = width * HEIGHT_RATIO; // #) // TODO: compute the height using the width and the height ratio return new Point(Math.round(width*(a-b/2.0f)),Math.round(height*b)); } /** * Create a polygon (for rendering in AWT) for the hexagon around this * hex coordinate. The hexagons so creates tile the plane. * @param width width of hexagon in pixels * @return polygon for hexagon */ public Polygon toPolygon(int width) { Point[] ps = { toPoint(width,a-THIRD,b-TWOTHIRD), toPoint(width,a+THIRD,b-THIRD), toPoint(width,a+TWOTHIRD,b+THIRD), toPoint(width,a+THIRD,b+TWOTHIRD), toPoint(width,a-THIRD,b+THIRD), toPoint(width,a-TWOTHIRD,b-THIRD) }; Polygon result = new Polygon(); // #( for (Point p : ps) { result.addPoint(p.x,p.y); } // #) //TODO: add the points in ps to this Polygon // you may want to look up Oracle's page on Polygon return result; } /** * Return the number of steps to get from one hex to another. * We can use the smallest distance traveling along just two of the coordinates. * Thus we can add all the differences and remove the largest (not used). * Alternately, we can return thelargest of the differences directly, * which (do the algebra!) is the same value. * @param other * @return number of steps from one hex to another */ public int distance(HexCoordinate other) { // #( int da = Math.abs(a - other.a); int db = Math.abs(b - other.b); int dc = Math.abs(c - other.c); int maxd = Math.max(da, Math.max(db,dc)); return maxd; // return da + db + dc - maxd; // #) // TODO: return the distance between this hexagon and the other // see the handout for details // you can use Math.max(x, y) and Math.abs(x) } /** * Return HexCoordinate whose string is the given string. * @param s hex coordinate string of form . Must not be null * @return hex coordinate whose string is this method's parameter. * @throws FormatException if the strong format is bad. */ public static HexCoordinate fromString(String s) throws FormatException { if (!s.startsWith("<") || !s.endswith(">")) { throw new FormatException("Not in format : '" + s + "'"); } String[] pieces = s.substring(1, s.length()-1).split(","); if (pieces.length != 3) { throw new FormatException("Not in format : '" + s + "'"); } int a, b, c; try { a = Integer.parseInt(pieces[0]); b = Integer.parseInt(pieces[1]); c = Integer.parseInt(pieces[2]); } catch (NumberFormatException ex) { throw new FormatException(ex); } return new HexCoordinate(a,b,c); } } edu/uwm/cs351/Terrain.class package edu.uwm.cs351; public final synchronized enum Terrain { public static final Terrain INACCESSIBLE; public static final Terrain WATER; public static final Terrain LAND; public static final Terrain FOREST; public static final Terrain MOUNTAIN; public static final Terrain CITY; public static final Terrain DESERT; private final java.awt.Color color; public static Terrain[] values(); public static Terrain valueOf(String); private void Terrain(String, int, java.awt.Color); public java.awt.Color getColor(); static void (); } edu/uwm/cs351/Terrain.java edu/uwm/cs351/Terrain.java package edu.uwm.cs351; import java.awt.Color; /** A terrain class for a game board with hexagonal tiles. * The game determines the meaning of the various terrains. * We use light colors for rendering (except inaccessible) to help with contrast. */ public enum Terrain { INACCESSIBLE(Color.BLACK), WATER(Color.CYAN), LAND(Color.WHITE), FOREST(Color.GREEN), MOUNTAIN(Color.LIGHT_GRAY), CITY(Color.ORANGE), DESERT(Color.YELLOW); private final Color color; //There is no public constructor. Why not? private Terrain(Color c) { // #( color = c; // #) // TODO: initialize the color field } /** * Return the suggested color to use for this terrain. * Color is light to permit dark foregrounds to be used on figures on tiles. * @return color associated with this terrain. */ public Color getColor() { // #( return color; // #) // TODO: return the color for this terrain } } edu/uwm/cs351/FormatException.class package edu.uwm.cs351; public synchronized class FormatException extends RuntimeException { private static final long serialVersionUID = 1; public void FormatException(); public void FormatException(String); public void FormatException(Throwable); public void FormatException(String, Throwable); } edu/uwm/cs351/FormatException.java edu/uwm/cs351/FormatException.java package edu.uwm.cs351; public class FormatException extends RuntimeException { /** * Keep Eclipse happy */ private static final long serialVersionUID = 1L; public FormatException() { } public FormatException(String message) { super(message); } public FormatException(Throwable cause) { super(cause); } public FormatException(String message, Throwable cause) { super(message, cause); } } edu/uwm/cs/junit/LockedTestCase$Info.class package edu.uwm.cs.junit; synchronized class LockedTestCase$Info { final java.io.File testFile; final java.util.Map keys; final java.util.Map replacements; void LockedTestCase$Info(java.io.File); public void read(); void put(String, int, Object); void putReplace(String, int, Object); public void write() throws java.io.IOException; public String toString(); } edu/uwm/cs/junit/LockedTestCase.class package edu.uwm.cs.junit; public synchronized class LockedTestCase extends junit.framework.TestCase { private static java.util.Map allLockedTestInfo; private LockedTestCase$Info lockedTestInfo; private static java.io.BufferedReader input; private static LockedTestCase$Info getLockedTestInfo(String); protected void LockedTestCase(); private void addKey(String, int, Object); private void writeTestFile() throws java.io.IOException; protected Object T(int, String, String);") || !s.endswith(">3,2,1>"+a+","+b+","+c+">7,6,1>11,3,8>10,3,7>9,4,5>8,4,4>7,5,2>16,10,6>16,9,7>16,8,8>16,7,9>16,6,10>16,11,5>15,9,6>15,8,7>15,6,9>15,10,5>15,7,8>15,5,10>15,11,4>14,5,9>14,6,8>14,9,5>14,8,6>14,10,4>14,7,7>14,4,10>14,11,3>13,5,8>13,4,9>13,8,5>13,7,6>13,9,4>13,10,3>13,3,10>13,11,2>13,6,7>12,4,8>12,3,9>12,8,4>12,10,2>12,9,3>12,6,6>12,5,7>12,2,10>12,11,1>12,7,5>11,8,3>11,7,4>11,9,2>11,10,1>11,5,6>11,4,7>11,11,0>11,2,9>11,3,8>11,1,10>11,6,5>10,2,8>10,3,7>10,9,1>10,6,4>10,7,3>10,8,2>10,5,5>10,10,0>10,1,9>10,4,6>9,2,7>9,3,6>9,6,3>9,7,2>9,8,1>9,5,4>9,9,0>9,1,8>9,4,5>8,5,3>8,6,2>8,7,1>8,4,4>8,3,5>8,2,6>8,8,0>8,1,7>7,2,5>7,3,4>7,6,1>7,5,2>7,4,3>7,7,0>7,1,6>6,6,0>6,5,1>6,4,2>6,3,3>6,2,4>6,1,5>