Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Saboteur/SaboteurBoardState.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class SaboteurBoardState extends BoardState {
this.board[hiddenPos[i][0]][hiddenPos[i][1]] = new SaboteurTile(list.remove(idx));
this.hiddenCards[i] = this.board[hiddenPos[i][0]][hiddenPos[i][1]];
}


//initialize the entrance
this.board[originPos][originPos] = new SaboteurTile("entrance");
//initialize the deck.
Expand Down Expand Up @@ -308,8 +310,8 @@ public int[][] getHiddenIntBoard() {
}
if(!isAnHiddenObjective) {
int[][] path = this.board[i][j].getPath();
for (int k = 0; i < 3; i++) {
for (int h = 0; i < 3; i++) {
for (int k = 0; k < 3; k++) {
for (int h = 0; h < 3; h++) {
this.intBoard[i * 3 + k][j * 3 + h] = path[h][2-k];
}
}
Expand Down Expand Up @@ -825,7 +827,6 @@ private boolean pathToHidden(SaboteurTile[] objectives){
For each hidden objectives:
We verify there is a path of cards between the start and the hidden objectives.
If there is one, we do the same but with the 0-1s matrix!

To verify a path, we use a simple search algorithm where we propagate a front of visited neighbor.
TODO To speed up: The neighbor are added ranked on their distance to the origin... (simply use a PriorityQueue with a Comparator)
*/
Expand Down Expand Up @@ -962,4 +963,4 @@ public static void main(String[] args) {
}
//pbs.printBoard();
}
}
}
3 changes: 2 additions & 1 deletion src/Saboteur/cardClasses/SaboteurTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
public class SaboteurTile extends SaboteurCard {
private int[][] path;
private String idx;

public SaboteurTile(String idx){
this.idx = idx;
this.path = SaboteurTile.initializePath(this.idx);

}

public String getName(){
return "Tile:"+this.idx;
}
Expand Down
5 changes: 3 additions & 2 deletions src/autoplay/Autoplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class Autoplay {
public static void main(String args[]) {
int n_games;
try {
n_games = Integer.parseInt(args[0]);
// n_games = Integer.parseInt(args[0]);
n_games = 15;
if (n_games < 1) {
throw new Exception();
}
Expand All @@ -46,7 +47,7 @@ public static void main(String args[]) {
client1_pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);

ProcessBuilder client2_pb = new ProcessBuilder("java", "-cp", "bin", "-Xms520m", "-Xmx520m",
"boardgame.Client", "Saboteur.RandomSaboteurPlayer");
"boardgame.Client", "student_player.StudentPlayer");
client2_pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);

for (int i = 0; i < n_games; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/boardgame/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class Server implements Runnable {
protected static final String VERSION = "0.08";
protected static final int DEFAULT_PORT = 8123;

public static final int DEFAULT_TIMEOUT = 20000;
public static final int DEFAULT_TIMEOUT = 2000;
private static final int DEFAULT_TIMEOUT_CUSHION = 1000;

public static final int FIRST_MOVE_TIMEOUT = 30000;
Expand Down
2 changes: 1 addition & 1 deletion src/boardgame/ServerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ServerGUI extends JFrame implements BoardPanel.BoardPanelListener {
/** The list of games for which servers can be launched */
protected static final String[] BOARD_CLASSES = { "Saboteur.SaboteurBoard" };
/** The list of players that can be launched */
protected static final String[] PLAYER_CLASSES = { "Saboteur.RandomSaboteurPlayer"}; // "alpha_beta.AlphaBetaPlayer" //"Saboteur.StudentPlayer"
protected static final String[] PLAYER_CLASSES = { "Saboteur.RandomSaboteurPlayer","student_player.StudentPlayer"}; // "alpha_beta.AlphaBetaPlayer" //"Saboteur.StudentPlayer"
private static final int BOARD_SIZE = 800;
private static final int LIST_WIDTH = 280;

Expand Down
66 changes: 66 additions & 0 deletions src/student_player/AndNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package student_player;

import java.util.ArrayList;

import Saboteur.SaboteurMove;
import Saboteur.cardClasses.SaboteurCard;
import Saboteur.cardClasses.SaboteurTile;

public class AndNode extends AndOrNode{
public SaboteurCard dealedCard;
public double prob;
public ORNode parent;
public ArrayList<ORNode> succesors;
public int depth;

public AndNode(String name, BoardState boardState,SaboteurCard dealedCard, double dealedCardProb) {
super(name,boardState);
this.dealedCard = dealedCard;
if(boardState.getTurnPlayer() == 1) {
boardState.player1Cards.add(dealedCard);
}else {
boardState.player2Cards.add(dealedCard);
}
this.prob = dealedCardProb;
ArrayList<SaboteurMove> moves = boardState.getAllLegalMoves();
int counter = 0;
this.succesors = new ArrayList<>();
for(SaboteurMove move: moves) {

String nodeName = "OR,"+(depth+1)+","+counter;

BoardState nodeBoardState = new BoardState(boardState);
nodeBoardState.processMove(move, false);
ORNode node = new ORNode(nodeName,nodeBoardState,move);
node.parent = this;
succesors.add(node);
}
}

public double getMinHeuristicVal(int[] goalPos,int depth, int maxDepth) {
double minHeuristicVal = Integer.MAX_VALUE;
for(ORNode node: succesors) {
if(node.move.getCardPlayed() instanceof SaboteurTile) {
if(!isGoodTile((SaboteurTile)node.move.getCardPlayed()))continue;
}
double curVal = node.getExpectedMinHeuistic(goalPos,depth+1, maxDepth);
if(curVal < minHeuristicVal) {
minHeuristicVal = curVal;
}
if(minHeuristicVal == Integer.MIN_VALUE)
break;
}
return minHeuristicVal;
}

public boolean isGoodTile(SaboteurTile tile) {
if(tile.getIdx().equals("0")||tile.getIdx().equals("5_flip")||tile.getIdx().equals("5")||tile.getIdx().equals("6")||
tile.getIdx().equals("6_flip")||tile.getIdx().equals("7_flip")||tile.getIdx().equals("7")
||tile.getIdx().equals("8")||tile.getIdx().equals("9")
||tile.getIdx().equals("9_flip")||tile.getIdx().equals("10")) {
return true;
}
return false;
}

}
46 changes: 46 additions & 0 deletions src/student_player/AndOrNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package student_player;

import java.util.ArrayList;
import Saboteur.cardClasses.SaboteurCard;
import Saboteur.cardClasses.SaboteurTile;

public class AndOrNode {
public BoardState boardState;
public ArrayList<SaboteurCard> player1Hands;
public ArrayList<SaboteurCard> player2Hands;
public String name;

public AndOrNode(String name, BoardState boardState) {
this.name = name;
this.boardState = boardState;
}

//Dir: 0 Up; 1 Right; 2 Down; 3 Left
public boolean checkOpenEnd(int[][] intBoard,SaboteurTile[][] tileBoard,int i,int j,int dir) {
switch(dir){
case 0:
if(intBoard[i][j]== 1&& i/3 == 0) return true;
if(intBoard[i][j]==1&&tileBoard[i/3-1][j/3]==null)
return true;
break;
case 1:
if(intBoard[i][j]== 1&& j/3 == 13) return true;
if(intBoard[i][j]==1&&tileBoard[i/3][j/3 + 1]==null)
return true;
break;
case 2:
if(intBoard[i][j]== 1&&i/3 == 13) return true;
if(intBoard[i][j]==1&&tileBoard[i/3+1][j/3]==null)
return true;
break;
case 3:
if(intBoard[i][j]== 1&&j/3 == 0) return true;
if(intBoard[i][j]==1&&tileBoard[i/3][j/3-1]==null)
return true;
break;
}
return false;
}


}
Loading