-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8abdcbc
commit 73bf2b4
Showing
17 changed files
with
920 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
strategy/StrategyIF.class | ||
strategy/StrategyNE.class | ||
strategy/StrategyNW.class | ||
strategy/StrategySE.class | ||
strategy/StrategySW.class | ||
unstable/Board.class | ||
unstable/Configuration.class | ||
unstable/Move.class | ||
unstable/Player.class | ||
unstable/Unstable.class | ||
unstable/Utility.class | ||
Unstable.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
# unstable | ||
# Unstable | ||
|
||
## Introduction | ||
AI playing the Unstable (Chain Reaction) game. | ||
|
||
https://brilliant.org/wiki/chain-reaction-game/ | ||
|
||
The project is implemented using the following AI techniques: Iterative Deepening, Negamax, Alpha-Beta Pruning. | ||
|
||
## Installation | ||
Clone and change directory: | ||
``` | ||
git clone https://github.com/tassoneroberto/unstable.git | ||
cd unstable | ||
``` | ||
(OPTION 1) Compile and run: | ||
``` | ||
javac -cp . unstable/Player.java | ||
java unstable/Player | ||
``` | ||
(OPTION 2) Make JAR file and run: | ||
``` | ||
jar cfe Unstable.jar unstable/Player . | ||
java -jar Unstable.jar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyEN implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyES implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package strategy; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
|
||
public interface StrategyIF { | ||
public Configuration[] generateAllNextMoves(int player, Board board); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyNE implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyNW implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategySE implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
for (j = board.boardValues[0].length - 1; j >= 0; j--) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategySW implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyWN implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
for (i = 0; i < board.boardValues.length; i++) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package strategy; | ||
|
||
import java.util.Arrays; | ||
|
||
import unstable.Board; | ||
import unstable.Configuration; | ||
import unstable.Utility; | ||
|
||
public class StrategyWS implements StrategyIF { | ||
|
||
@Override | ||
public Configuration[] generateAllNextMoves(int player, Board board) { | ||
Configuration[] moves = new Configuration[board.ownedCells[player] + board.ownedCells[0]]; | ||
int index = 0, i, j; | ||
if (player == 1) { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
if (board.boardValues[i][j] >= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[1][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} else { | ||
for (j = 0; j < board.boardValues[0].length; j++) { | ||
for (i = board.boardValues.length - 1; i >= 0; i--) { | ||
if (board.boardValues[i][j] <= 0) { | ||
moves[index] = new Configuration(Utility.MOVES[2][i][j], board); | ||
if (moves[index].heuristic == Utility.MAX_VALUE) | ||
return moves; | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
Arrays.sort(moves); | ||
return moves; | ||
} | ||
} |
Oops, something went wrong.