Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a11850

Browse files
Chapter 08 completed.
1 parent 5a1d4d7 commit 0a11850

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed
1.44 MB
Binary file not shown.

‎08-Move-the-Box-Solver/Optional-01-Move-the-Box-Solver-with-Interactions/src/Board.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ private void drop(){
136136
int cur = N-1;
137137
for(int i = N-1 ; i >= 0 ; i --)
138138
if(data[i][j] != EMPTY){
139-
data[cur][j] = data[i][j];
139+
swap(cur, j, i, j);
140140
cur--;
141141
}
142-
for(; cur >= 0 ; cur --)
143-
data[cur][j] = EMPTY;
144142
}
145143

146144
return;

‎08-Move-the-Box-Solver/Optional-01-Move-the-Box-Solver-with-Interactions/src/GameData.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ public boolean inArea(int x, int y){
6666

6767
public boolean solve(){
6868

69-
if(maxTurn <= 0)
69+
if(maxTurn < 0)
7070
return false;
7171

72-
return solve(newBoard(starterBoard), maxTurn);
72+
return solve(starterBoard, maxTurn);
7373
}
7474

75-
private static int d[][] = {{-1, 0}, {0, 1}, {0,-1}};
75+
private static int d[][] = {{1, 0}, {0, 1}, {0,-1}};
7676
private boolean solve(Board board, int turn){
7777

78-
if(board == null)
78+
if(board == null || turn < 0)
7979
throw new IllegalArgumentException("board can not be null in solve function!");
8080

8181
if(turn == 0)

‎08-Move-the-Box-Solver/Optional-02-Move-the-Box-Solver-Using-HashSet/src/Board.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ private void drop(){
136136
int cur = N-1;
137137
for(int i = N-1 ; i >= 0 ; i --)
138138
if(data[i][j] != EMPTY){
139-
data[cur][j] = data[i][j];
139+
swap(cur, j, i, j);
140140
cur--;
141141
}
142-
for(; cur >= 0 ; cur --)
143-
data[cur][j] = EMPTY;
144142
}
145143

146144
return;

‎08-Move-the-Box-Solver/Optional-02-Move-the-Box-Solver-Using-HashSet/src/GameData.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ public boolean solve(){
7575
long startTime = System.currentTimeMillis();
7676

7777
searchedBoards.add(starterBoard);
78-
boolean ret = solve(newBoard(starterBoard), maxTurn);
78+
boolean ret = solve(starterBoard, maxTurn);
7979

8080
long endTime = System.currentTimeMillis();
8181
System.out.println( "Time : " + (endTime-startTime) + "ms" );
8282

8383
return ret;
8484
}
8585

86-
private static int d[][] = {{-1, 0}, {0, -1}, {0, 1}};
86+
private static int d[][] = {{1, 0}, {0, -1}, {0, 1}};
8787
private boolean solve(Board board, int turn){
8888

89-
if(board == null)
89+
if(board == null || turn < 0)
9090
throw new IllegalArgumentException("board can not be null in solve function!");
9191

9292
if(turn == 0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /