Skip to content

Commit

Permalink
DriftingDroids include: Automatic code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Barkow-Kuder <github@r.z11.de>
  • Loading branch information
rubo77 committed Dec 7, 2021
1 parent 1cfea98 commit e1dac9e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
9 changes: 4 additions & 5 deletions app/src/main/java/driftingdroids/model/Board.java
Expand Up @@ -20,6 +20,7 @@
import android.util.Base64;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -536,7 +537,7 @@ public static Board createBoardGameDump(final String dump) {
// 4. walls
for (int dir = 0; dir < board.walls.length; ++dir) {
for (int pos = 0; pos < board.walls[dir].length; ++pos) {
board.walls[dir][pos] = (0 != data[didx++] ? true : false);
board.walls[dir][pos] = (0 != data[didx++]);
}
}
// 5. list of goals
Expand Down Expand Up @@ -651,9 +652,7 @@ private static String zipb64(final byte[] input) {
final String b64Output = new String(Base64.encode(b64Input, 0));
//compute CRC of encoded data
final CRC32 crc32 = new CRC32();
try {
crc32.update(b64Output.getBytes("UTF-8"));
} catch (UnsupportedEncodingException ignored) { }
crc32.update(b64Output.getBytes(StandardCharsets.UTF_8));
final long crc32Value = crc32.getValue();
final String crc32String = new Formatter().format("%08X", Long.valueOf(crc32Value)).toString();
//build output string: starts and ends with "!", to be split at "!"
Expand All @@ -674,7 +673,7 @@ private static byte[] unb64unzip(final String input) {
//validate data
final long b64crc = Long.parseLong(inputSplit[2], 16); //throws NumberFormatException
final CRC32 crc32 = new CRC32();
crc32.update(inputSplit[3].getBytes("UTF-8"));
crc32.update(inputSplit[3].getBytes(StandardCharsets.UTF_8));
if (crc32.getValue() != b64crc) {
throw new IllegalArgumentException("data CRC mismatch");
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/driftingdroids/model/KeyDepthMap.java
Expand Up @@ -40,7 +40,7 @@ public interface KeyDepthMap {
* @return true if the specified value was placed in this map. false if the map already contained
* for this key a value that is greater than or equal to the specified value.
*/
public boolean putIfGreater(int key, int byteValue);
boolean putIfGreater(int key, int byteValue);

/**
* Associates the specified <code>unsigned byte</code> value with the specified
Expand All @@ -54,22 +54,22 @@ public interface KeyDepthMap {
* @return true if the specified value was placed in this map. false if the map already contained
* for this key a value that is greater than or equal to the specified value.
*/
public boolean putIfGreater(long key, int byteValue);
boolean putIfGreater(long key, int byteValue);

/**
* Returns the number of elements (key/value pairs) currently stored in this map.
* This is for information only; some implementations may return a wrong value.
*
* @return number of elements in this map
*/
public int size();
int size();

/**
* Returns the number of bytes that are allocated by this map's internal data structures.
* This is for information only; some implementations may return a wrong value.
*
* @return number of bytes allocated by this map (approximate)
*/
public long allocatedBytes();
long allocatedBytes();

}
Expand Up @@ -60,7 +60,7 @@ public static KeyDepthMap newInstance(Board board, Class<? extends KeyDepthMap>
} else if (KeyDepthMapTrieSpecial.class.equals(clazz)) {
return KeyDepthMapTrieSpecial.createInstance(board, true);
} else {
throw new IllegalArgumentException("unknown KeyDepthMap class: " + String.valueOf(clazz));
throw new IllegalArgumentException("unknown KeyDepthMap class: " + clazz);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/driftingdroids/model/Solver.java
Expand Up @@ -28,7 +28,7 @@ public abstract class Solver {
public enum SOLUTION_MODE {
MINIMUM("minimum", "solver.Minimum.text"), MAXIMUM("maximum", "solver.Maximum.text");
private final String name, l10nKey;
private SOLUTION_MODE(String name, String l10nKey) { this.name = name; this.l10nKey = l10nKey; }
SOLUTION_MODE(String name, String l10nKey) { this.name = name; this.l10nKey = l10nKey; }
public String getName() { return this.name; }
}

Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/driftingdroids/model/SolverIDDFS.java
Expand Up @@ -106,7 +106,7 @@ public List<Solution> execute() throws InterruptedException {


private void precomputeMinimumMovesToGoal() {
final boolean posToDo[] = new boolean[this.minimumMovesToGoal.length];
final boolean[] posToDo = new boolean[this.minimumMovesToGoal.length];
Arrays.fill(this.minimumMovesToGoal, Integer.MAX_VALUE);
this.minimumMovesToGoal[this.goalPosition] = 0;
posToDo[this.goalPosition] = true;
Expand Down Expand Up @@ -379,10 +379,7 @@ private boolean hasPerpendicularMove(final int depth, final int robot, final int
}
prevDir = thisDir;
}
if ((((lastDir + 1) & 3) == prevDir) || (((lastDir + 3) & 3) == prevDir)) {
return true;
}
return false;
return (((lastDir + 1) & 3) == prevDir) || (((lastDir + 3) & 3) == prevDir);
}


Expand Down

0 comments on commit e1dac9e

Please sign in to comment.