Reformatted

This commit is contained in:
Topher Lamey
2021-02-28 00:47:50 -07:00
parent 90e2adde76
commit 57a5bad47d

View File

@@ -5,27 +5,40 @@ import java.util.Scanner;
import static java.lang.System.in; import static java.lang.System.in;
import static java.lang.System.out; import static java.lang.System.out;
/**
* Core algorithm copied from amazing.py
*/
public class Amazing { public class Amazing {
final static int FIRST_COL = 0;
final static int FIRST_ROW = 0;
final static int EXIT_UNSET = 0;
final static int EXIT_DOWN = 1;
final static int EXIT_RIGHT = 2;
private final Scanner kbScanner; private final Scanner kbScanner;
public Amazing() { public Amazing() {
kbScanner = new Scanner(in); kbScanner = new Scanner(in);
} }
enum Direction { private static int getDelimitedValue(String text, int pos) {
GO_LEFT, String[] tokens = text.split(",");
GO_UP, try {
GO_RIGHT, return Integer.parseInt(tokens[pos]);
GO_DOWN, } catch (Exception ex) {
return 0;
}
} }
final static int FIRST_COL = 0; private static String tab(int spaces) {
final static int FIRST_ROW = 0; char[] spacesTemp = new char[spaces];
Arrays.fill(spacesTemp, ' ');
return new String(spacesTemp);
}
final static int EXIT_UNSET = 0; public static int random(int min, int max) {
final static int EXIT_DOWN = 1; Random random = new Random();
final static int EXIT_RIGHT = 2; return random.nextInt(max - min) + min;
}
public void play() { public void play() {
out.println(tab(28) + "AMAZING PROGRAM"); out.println(tab(28) + "AMAZING PROGRAM");
@@ -138,24 +151,11 @@ public class Amazing {
return kbScanner.next(); return kbScanner.next();
} }
private static int getDelimitedValue(String text, int pos) { enum Direction {
String[] tokens = text.split(","); GO_LEFT,
try { GO_UP,
return Integer.parseInt(tokens[pos]); GO_RIGHT,
} catch (Exception ex) { GO_DOWN,
return 0;
}
}
private static String tab(int spaces) {
char[] spacesTemp = new char[spaces];
Arrays.fill(spacesTemp, ' ');
return new String(spacesTemp);
}
public static int random(int min, int max) {
Random random = new Random();
return random.nextInt(max - min) + min;
} }
public static class Cell { public static class Cell {
@@ -186,7 +186,7 @@ public class Amazing {
this.width = width; this.width = width;
this.cells = new Cell[length][width]; this.cells = new Cell[length][width];
for (int i=0; i < length; i++) { for (int i = 0; i < length; i++) {
this.cells[i] = new Cell[width]; this.cells[i] = new Cell[width];
for (int j = 0; j < width; j++) { for (int j = 0; j < width; j++) {
this.cells[i][j] = new Cell(i, j); this.cells[i][j] = new Cell(i, j);
@@ -228,12 +228,15 @@ public class Amazing {
public Cell getPrevCol(Cell cell) { public Cell getPrevCol(Cell cell) {
return cells[cell.row][cell.col - 1]; return cells[cell.row][cell.col - 1];
} }
public Cell getPrevRow(Cell cell) { public Cell getPrevRow(Cell cell) {
return cells[cell.row - 1][cell.col]; return cells[cell.row - 1][cell.col];
} }
public Cell getNextCol(Cell cell) { public Cell getNextCol(Cell cell) {
return cells[cell.row][cell.col + 1]; return cells[cell.row][cell.col + 1];
} }
public Cell getNextRow(Cell cell) { public Cell getNextRow(Cell cell) {
return cells[cell.row + 1][cell.col]; return cells[cell.row + 1][cell.col];
} }
@@ -256,5 +259,4 @@ public class Amazing {
return newCell; return newCell;
} }
} }
} }