From 562d88d937d5514f40695a6c16c1a140b9c4995a Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Wed, 14 May 2025 20:10:01 -0400 Subject: [PATCH] These --- chess/src/chess/Main.java | 1 + .../src/twentyfortyeight/Main.java | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/chess/src/chess/Main.java b/chess/src/chess/Main.java index 6762b09..f8cd681 100644 --- a/chess/src/chess/Main.java +++ b/chess/src/chess/Main.java @@ -4,6 +4,7 @@ import tester.Tester; class Examples { void testItAll(Tester t) { new Game().run(); } + void testCoord(Tester t) { Coord coord = new Coord(1, 1); Coord cod = new Coord(1, 1); diff --git a/twentyfortyeight/src/twentyfortyeight/Main.java b/twentyfortyeight/src/twentyfortyeight/Main.java index f7ae9f6..5ef5744 100644 --- a/twentyfortyeight/src/twentyfortyeight/Main.java +++ b/twentyfortyeight/src/twentyfortyeight/Main.java @@ -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.