Question: JAVA CODE ---------------------------------------------------------------------------------------------------------------------------------------- public void test() { HexCoordinate h = new HexCoordinate(2,1); assertEquals(Ts(572530722),h.toString()); // Look at the picture on the first page: assertEquals(Ti(2091651564),h.distance(new HexCoordinate(2,2,0))); assertEquals(Ti(83653195),h.distance(h));
JAVA CODE ---------------------------------------------------------------------------------------------------------------------------------------- public void test() { HexCoordinate h = new HexCoordinate(2,1); assertEquals(Ts(572530722),h.toString()); // Look at the picture on the first page: assertEquals(Ti(2091651564),h.distance(new HexCoordinate(2,2,0))); assertEquals(Ti(83653195),h.distance(h)); assertEquals(Ti(330722134),h.distance(new HexCoordinate(4,2,2))); // no sqrt(3) stuff for this one: assertEquals(Ti(832991396),h.toPoint(1000).x); // NB: sqrt(3)/2 = 0.8660... // And look at the homework page 2 assertEquals(Ti(542975482),h.toPoint(1000).y); }-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Can I get the correct values for the "Ts(s) and Ti(s) in the test?
In this assignment, you will implement an ADT for a hexagonal coordinate system for creating games that operate on hexagon-tile boards. You will also implement a simple "enumerated class for various kinds of terrains. 1 ADT: HexCoordinate For this homework, you are creating an immutable data type to represent hexagon coordi- nates. Each coordinate represents the center of a hexagon in a tiling of the plane: 0,2.0 1,0,1 2.0,2 3.0.3 4,0,4 1,1,0 2,1,1 3,1,2 4,1,3 1,2,-1 2,2,0 3,2,1 4,2,2 5,2,3 2,3,-1 3,3,0 4,3,1 5,3,2 Each hexagon has three coordinates: the first increases as you go to the right (and down), the second as you go down, the third as you go right (and up). In the electronic version of this document, you can see that a band of hexagons with first coordinate equal to two have been highlighted in yellow. If you have a paper copy of this document, we recommend that you highlight in three contrasting colors bands of hexagons with the same coordinate equal to two. (There are a number of different hexagonal grids used in practice, but you should use thisone for this homework.) The third coordinate can always be computed from the other two? For example, if you know a and b, you can subtract one from the other to get c, as you can see in the diagram. We therefore often use just the first two numbers to create a coordinate. Two hexagonal coordinates are equal exactly when they have the same numbers in the same order. The "distance" from one hex coordinate is the minimum number of moves to adjacent hexagons needed to get from one to another. Thus the distance from (3, 0, 3) to (5, 2, 3) is two, and the distance from (2,2,0) to (3,0, 3) is three. The distance from any hex coordinate to itself is zero. As it happens, the shortest path only requires travel along two of the three "dimensions, and thus you can compute the minimum distance by testing each possible pair of dimensions and choosing the shortest. For example, assuming we use a, b, and "c" for our three coordinates, then to compute the shortest path from (2,2,0) to (3,0,3), we can try all three pairs of dimensions to travel on: ac Travel first along the a dimension, keeping the "c" dimension constant: (2,2,0) to (3,3,0) and then along the c dimension while keeping the a dimension constant: (3,3,0) to (3, 2, 1) to (3, 1, 2) to (3,0,3). Total travel: 1+3 = 4. bc Travel first along the b dimension, keeping the "c" dimension constant: (2,2,0) to (1,1,0) to (0,0,0), and then along the c dimension while keeping the b dimension constant: (0,0,0) to (1,0, 1) to (2,0, 2) to (3,0,3). Total travel: 2+3 = 5. ab Travel first along the a dimension, keeping the b dimension constant: (2,2,0) to (3,2,1) and then along the "b" dimension while keeping the a dimension constant: (3,2,1) to (3, 1, 2) to (3,0,3). Total travel: 1+2 = 3. The shortest distance is the sum of the two smaller distances in each of the three dimensions (a, b, c). An easy way to compute the shortest distance is to add the three distances and then subtract the maximum distance: 1+ 2+ 3 3 = 3; think about why this works. (Of course, you must use the absolute value of the difference: e.g.: 2 3 = 1 11 = 1). In order to render a hexagon in a Java graphics context, we have to decide how big the hexagons are going to be. This might change and so we use a "width" parameter. For those of you who don't recall your hexagonal geometry, here's a helpful diagram (not quite to scale) of a hexagon with "width" = w: U2 w w3 V3 6 Thus if w = 30 and the hexagon is centered at (0,0), then (15,573) is one of the corners. Once you figure out how to create the Polygon for the hexagon at the hex coordinate (0,0,0), you need to see how much the (x, y) points should shift for other coordinate. The first coordinate is easy; it shifts the hexagon right increasing x) by w. The second is trickier since it shifts the hexagon down (increasing y) by w and back to the left (decreasing 2) by In all, you must implement the following methods: HexCoordinate(int,int) Main constructor. Spring 2021 page 2 of 4 @Override public String toString() { // TODO: return a string of the form return ""; } In this assignment, you will implement an ADT for a hexagonal coordinate system for creating games that operate on hexagon-tile boards. You will also implement a simple "enumerated class for various kinds of terrains. 1 ADT: HexCoordinate For this homework, you are creating an immutable data type to represent hexagon coordi- nates. Each coordinate represents the center of a hexagon in a tiling of the plane: 0,2.0 1,0,1 2.0,2 3.0.3 4,0,4 1,1,0 2,1,1 3,1,2 4,1,3 1,2,-1 2,2,0 3,2,1 4,2,2 5,2,3 2,3,-1 3,3,0 4,3,1 5,3,2 Each hexagon has three coordinates: the first increases as you go to the right (and down), the second as you go down, the third as you go right (and up). In the electronic version of this document, you can see that a band of hexagons with first coordinate equal to two have been highlighted in yellow. If you have a paper copy of this document, we recommend that you highlight in three contrasting colors bands of hexagons with the same coordinate equal to two. (There are a number of different hexagonal grids used in practice, but you should use thisone for this homework.) The third coordinate can always be computed from the other two? For example, if you know a and b, you can subtract one from the other to get c, as you can see in the diagram. We therefore often use just the first two numbers to create a coordinate. Two hexagonal coordinates are equal exactly when they have the same numbers in the same order. The "distance" from one hex coordinate is the minimum number of moves to adjacent hexagons needed to get from one to another. Thus the distance from (3, 0, 3) to (5, 2, 3) is two, and the distance from (2,2,0) to (3,0, 3) is three. The distance from any hex coordinate to itself is zero. As it happens, the shortest path only requires travel along two of the three "dimensions, and thus you can compute the minimum distance by testing each possible pair of dimensions and choosing the shortest. For example, assuming we use a, b, and "c" for our three coordinates, then to compute the shortest path from (2,2,0) to (3,0,3), we can try all three pairs of dimensions to travel on: ac Travel first along the a dimension, keeping the "c" dimension constant: (2,2,0) to (3,3,0) and then along the c dimension while keeping the a dimension constant: (3,3,0) to (3, 2, 1) to (3, 1, 2) to (3,0,3). Total travel: 1+3 = 4. bc Travel first along the b dimension, keeping the "c" dimension constant: (2,2,0) to (1,1,0) to (0,0,0), and then along the c dimension while keeping the b dimension constant: (0,0,0) to (1,0, 1) to (2,0, 2) to (3,0,3). Total travel: 2+3 = 5. ab Travel first along the a dimension, keeping the b dimension constant: (2,2,0) to (3,2,1) and then along the "b" dimension while keeping the a dimension constant: (3,2,1) to (3, 1, 2) to (3,0,3). Total travel: 1+2 = 3. The shortest distance is the sum of the two smaller distances in each of the three dimensions (a, b, c). An easy way to compute the shortest distance is to add the three distances and then subtract the maximum distance: 1+ 2+ 3 3 = 3; think about why this works. (Of course, you must use the absolute value of the difference: e.g.: 2 3 = 1 11 = 1). In order to render a hexagon in a Java graphics context, we have to decide how big the hexagons are going to be. This might change and so we use a "width" parameter. For those of you who don't recall your hexagonal geometry, here's a helpful diagram (not quite to scale) of a hexagon with "width" = w: U2 w w3 V3 6 Thus if w = 30 and the hexagon is centered at (0,0), then (15,573) is one of the corners. Once you figure out how to create the Polygon for the hexagon at the hex coordinate (0,0,0), you need to see how much the (x, y) points should shift for other coordinate. The first coordinate is easy; it shifts the hexagon right increasing x) by w. The second is trickier since it shifts the hexagon down (increasing y) by w and back to the left (decreasing 2) by In all, you must implement the following methods: HexCoordinate(int,int) Main constructor. Spring 2021 page 2 of 4 @Override public String toString() { // TODO: return a string of the form return ""; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts



