This commit is contained in:
Jacob Signorovitch
2025-05-14 20:10:01 -04:00
parent 5ffd1dd3cc
commit 562d88d937
2 changed files with 15 additions and 13 deletions

View File

@@ -37,9 +37,10 @@ class Util {
// Convert a movement to a displacement vector.
static Coord moveDisp(Move move) {
if (move.equals(Move.LEFT)) return new Coord(-1, 0);
else if (move.equals(Move.DOWN)) return new Coord(0, -1);
else if (move.equals(Move.UP)) return new Coord(0, 1);
else return new Coord(0, 1);
else if (move.equals(Move.DOWN)) return new Coord(0, 1);
else if (move.equals(Move.UP)) return new Coord(0, -1);
else if (move.equals(Move.RIGHT)) return new Coord(1, 0);
else return null;
}
}
@@ -85,9 +86,6 @@ class Game extends World {
void run() { this.bigBang(this.width, this.width, 0.01); }
}
// The possible movements.
enum Move { UP, LEFT, RIGHT, DOWN }
// The board on which the game is played.
class Board {
int sz; // The side length of the board grid square.
@@ -150,13 +148,12 @@ class Board {
// Move cell as much as possible.
void fullCellMove(Coord coord, Move move) {
Cell cell = this.get(coord);
Coord current = coord;
Coord disp = Util.moveDisp(move);
if (!cell.isMoveable()) return;
while (this.get(current.add(Util.moveDisp(move))).isReplaceable()) {
this.tryCellMove(current, current.add(Util.moveDisp(move)));
current = current.add(Util.moveDisp(move));
for () {
this.tryCellMove(coord, coord.add(disp));
}
}
@@ -177,8 +174,8 @@ class Board {
}
else if (move.equals(Move.RIGHT)) {
for (int x = 0; x < this.sz - 1; x++) {
this.tryCellMove(new Coord(x, i), new Coord(x + 1, i));
for (int x = this.sz - 2; x >= 0; x--) {
this.fullCellMove(new Coord(x, i), move);
}
}
@@ -190,6 +187,9 @@ class Board {
}
}
// The possible movements.
enum Move { UP, LEFT, RIGHT, DOWN }
// A cell on the board.
abstract class Cell {
// Generate the color of the tile.
@@ -204,7 +204,7 @@ abstract class Cell {
// Is this moveable?
boolean isMoveable() { return false; }
boolean isReplaceable() { return true;}
boolean isReplaceable() { return false;}
}
// A moveable tile on the board.
@@ -234,6 +234,7 @@ class Tile extends Cell {
// An empty space on the board.
class Space extends Cell {
Color col() { return Color.LIGHT_GRAY; }
boolean isReplaceable() { return true; }
}
// Board coordinates.