board + move

This commit is contained in:
Storm-GH 2023-03-20 13:39:19 -04:00
parent 628263d95b
commit 456ed3f15b
5 changed files with 116 additions and 0 deletions

View File

@ -5,6 +5,11 @@ import java.util.Collection;
public class GameTree { public class GameTree {
private Node root; private Node root;
public Node buildTree(){
return null;
}
public Node getRoot() { public Node getRoot() {
return root; return root;
} }
@ -20,4 +25,5 @@ public class GameTree {
return childs; return childs;
} }
} }
} }

View File

@ -45,5 +45,6 @@ public class MiniMax {
private static int evaluate(GameTree.Node node) { private static int evaluate(GameTree.Node node) {
return 0;
} }
} }

View File

@ -0,0 +1,8 @@
package laboratoire4;
public enum Pawn {
R_PUSHER,
R_PUSHED,
B_PUSHER,
B_PUSHED
}

View File

@ -0,0 +1,87 @@
package laboratoire4;
public class PusherBoard {
private Pawn[][] board;
public PusherBoard() {
this.newGame();
}
public void newGame(){
this.board = new Pawn[8][8];
for(int i = 0 ;i<board.length;i++){
board[7][i] = Pawn.B_PUSHER;
}
for(int i = 0 ;i<board.length;i++){
board[6][i] = Pawn.B_PUSHED;
}
for(int i = 0 ;i<board.length;i++){
board[1][i] = Pawn.R_PUSHED;
}
for(int i = 0 ;i<board.length;i++){
board[0][i] = Pawn.R_PUSHER;
}
}
public int move (String move){
//FORMAT ex : D2-D3
String[] split = move.split("-");
return move(split[0],split[1]);
}
public int move (String from, String to){
//FORMAT ex : from {D2}, to {D3}
int from_i = (int) from.charAt(0) - 65;
int from_j = Integer.parseInt(String.valueOf(from.charAt(1)))-1;
int to_i = (int) to.charAt(0) - 65;
int to_j = Integer.parseInt(String.valueOf(to.charAt(1)))-1;
return move(from_i, from_j, to_i, to_j);
}
public int move(int from_i, int from_j, int to_i, int to_j){
//FORMAT ex : from_i {3}, from_j {2}, to_i {3}, to_j {3}
System.out.println("Move :" + from_i+""+from_j + "-"+ to_i+""+to_j);
if(isValid(from_i,from_j,to_i,to_j)){
Pawn pawn = this.getBoard()[from_j][from_i];
System.out.println("Pawn (0,0) :" + this.getBoard()[1][0]);
System.out.println("Pawn to move : " + pawn);
this.getBoard()[from_j][from_i] = null;
this.getBoard()[to_j][to_i] = pawn;
}
return -1;
}
private boolean isValid(int from_i, int from_j, int to_i, int to_j){
//TODO
return true;
}
public Pawn[][] getBoard() {
return board;
}
public void printBoard(){
for(int i=7; i>=0; i--){
for (int j = 0 ; j < this.board.length; j++){
if(this.board[i][j] != null){
System.out.print(this.board[i][j] + " | ");
}else{
System.out.print(" | ");
}
}
System.out.println();
System.out.println("----------------------------------------------------------------------------------------");
}
}
}

View File

@ -0,0 +1,14 @@
package laboratoire4;
public class Test {
public static void main(String[] args) {
PusherBoard pusherBoard = new PusherBoard();
//Move examples
pusherBoard.move("D2","D3");
pusherBoard.move("C2","C3");
pusherBoard.move("D1","D2");
pusherBoard.move("D2","E3");
pusherBoard.printBoard();
}
}