Last active
January 27, 2020 18:22
-
-
Save pavlos-io/44e7c25654a4cc3565849e1406e67641 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Gets the value of a tile. | |
/** | |
* Given an X and Y coordinate, returns the value of the tile at that position. | |
* This function also marks that location as visited. Part of your grade on this | |
* assignment will be determined by how many tiles your solution visits. | |
* | |
* @param x The X coordinate. | |
* @param y The Y coordinate. | |
* @return The value of the tile at that location. | |
*/ | |
public double getTile(final int x, final int y){ | |
if(!validTile(x, y)){ | |
throw new IndexOutOfBoundsException("Tried to access (" + x + ", " + y + ") " + | |
"in a board of dimension " + Width + " x " + Height); | |
} | |
down(); | |
if(Uncovered[x][y] == 0){ | |
uncoveredCounter++; | |
Uncovered[x][y] = uncoveredCounter; | |
} | |
up(); | |
return Board[x][y] & 0xFF; | |
} | |
public double getCost(final Point p1, final Point p2){ | |
// Only use of the the following dependent on question | |
//return (double) (getTile(p1)) / ( (double) getTile(p2)+1.0); | |
return Math.pow(2.0, (getTile(p2) - getTile(p1))); | |
} | |
/// Aquires the semaphore. | |
private void down(){ | |
try{ | |
sem.acquire(); | |
} | |
catch(InterruptedException ex){ | |
throw new RuntimeException("down function was interupted"); | |
} | |
} | |
/// Release the semaphore. | |
private void up(){ | |
sem.release(); | |
} | |
// Board is a property defined like so: Board = terraGen.getTerrain(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment