william #1

Merged
william merged 6 commits from william into master 2023-03-21 18:08:15 -04:00
7 changed files with 312 additions and 79 deletions
Showing only changes of commit ec7f3568e5 - Show all commits

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -4,12 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Player.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="MiniMax">
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Pushed.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Pusher.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/Pawn.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Pawn.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/PusherBoard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/PusherBoard.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -23,6 +24,13 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="alexis" />
</map>
</option>
</component>
<component name="MacroExpansionManager">
<option name="directoryName" value="x0367gi2" />
</component>
@ -44,19 +52,19 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "/home/william/Dev/Projects/Uni/Log320/LOG320_Lab4",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/william/Dev/Projects&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="laboratoire4.Client" />
@ -86,11 +94,25 @@
<option name="presentableId" value="Default" />
<updated>1679255648701</updated>
<workItem from="1679255649975" duration="1223000" />
<workItem from="1679261446095" duration="1908000" />
<workItem from="1679261446095" duration="1927000" />
<workItem from="1679281763874" duration="46000" />
<workItem from="1679344371350" duration="3857000" />
</task>
<task id="LOCAL-00001" summary="MiniMax">
<created>1679263366439</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1679263366439</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="MiniMax" />
<option name="LAST_COMMIT_MESSAGE" value="MiniMax" />
</component>
</project>

View File

@ -5,8 +5,7 @@ import java.util.Collection;
public class GameTree {
private Node root;
public Node buildTree(){
public Node buildTree(PusherBoard board){
return null;
}

View File

@ -1,8 +1,56 @@
package laboratoire4;
public enum Pawn {
R_PUSHER,
R_PUSHED,
B_PUSHER,
B_PUSHED
public abstract class Pawn {
protected final PawnColor color;
protected int col;
protected int row;
public Pawn(PawnColor color, int col, int row) {
this.color = color;
this.col = col;
this.row = row;
}
public PawnColor getColor() {
return color;
}
public int getCol() {
return col;
}
public int getRow() {
return row;
}
public void setCol(int col) {
this.col = col;
}
public void setRow(int row) {
this.row = row;
}
public abstract boolean isMoveValid(PusherBoard board, PawnMovement movement);
enum PawnColor {
RED,
BLACK
}
enum PawnMovement {
STRAIGHT(0),
LEFT_DIAGONAL(-1),
RIGHT_DIAGONAL(1);
private final int move;
PawnMovement(int move) {
this.move = move;
}
public int getMove() {
return move;
}
}
}

View File

@ -0,0 +1,26 @@
package laboratoire4;
public class Pushed extends Pawn {
public Pushed(PawnColor color, int col, int row) {
super(color, col, row);
}
@Override
public boolean isMoveValid(PusherBoard game, PawnMovement movement) {
Pawn[][] board = game.getBoard();
Pawn pusher = null;
Pawn to = board[row + 1][col + movement.getMove()];
if (col > 0 && movement == PawnMovement.RIGHT_DIAGONAL) {
pusher = board[row - 1][col - 1];
} else if (col < board.length - 1 && movement == PawnMovement.LEFT_DIAGONAL) {
pusher = board[row - 1][col + 1];
} else if (movement == PawnMovement.STRAIGHT) {
pusher = board[row - 1][col];
}
boolean pusherValid = pusher != null;
boolean destinationValid = to == null || to.color != this.color;
return pusherValid && destinationValid;
}
}

View File

@ -0,0 +1,14 @@
package laboratoire4;
public class Pusher extends Pawn {
public Pusher(PawnColor color, int col, int row) {
super(color, col, row);
}
@Override
public boolean isMoveValid(PusherBoard game, PawnMovement movement) {
Pawn to = game.getBoard()[row + 1][col + movement.getMove()];
return to == null || to.color != this.color;
}
}

View File

@ -1,57 +1,58 @@
package laboratoire4;
public class PusherBoard {
private Pawn[][] board;
public PusherBoard() {
this.newGame();
}
public void newGame(){
public void newGame() {
this.board = new Pawn[8][8];
for(int i = 0 ;i<board.length;i++){
board[7][i] = Pawn.B_PUSHER;
}
// TODO: Construire depuis le serveur
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board.length; j++) {
Pawn pawn = null;
Pawn.PawnColor color = i < board.length / 2 ?
Pawn.PawnColor.RED :
Pawn.PawnColor.BLACK;
for(int i = 0 ;i<board.length;i++){
board[6][i] = Pawn.B_PUSHED;
}
if (i == 0 || i == board.length - 1) {
pawn = new Pusher(color, i, j);
} else if (i == 1 || i == board.length - 2) {
pawn = new Pushed(color, i, j);
}
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;
board[i][j] = pawn;
}
}
}
public int move (String move){
public int move(String move) {
//FORMAT ex : D2-D3
String[] split = move.split("-");
return move(split[0],split[1]);
return move(split[0], split[1]);
}
public int move (String from, String to){
public int move(String from, String to) {
//FORMAT ex : from {D2}, to {D3}
int from_col = (int) from.charAt(0) - 65;
int from_row = Integer.parseInt(String.valueOf(from.charAt(1)))-1;
int from_row = Integer.parseInt(String.valueOf(from.charAt(1))) - 1;
int to_col = (int) to.charAt(0) - 65;
int to_row = Integer.parseInt(String.valueOf(to.charAt(1)))-1;
int to_row = Integer.parseInt(String.valueOf(to.charAt(1))) - 1;
return move(from_col, from_row, to_col, to_row);
}
public int move(int from_col, int from_row, int to_col, int to_row){
public int move(int from_col, int from_row, int to_col, int to_row) {
//FORMAT ex : from_col {3}, from_row {2}, to_col {3}, to_row {3}
//System.out.println("Move :" + from_col+""+from_row + "-"+ to_col+""+to_row);
//System.out.println("Move is valid : " + isValid(from_col,from_row,to_col,to_row));
if(isValid(from_col,from_row,to_col,to_row)){
if (isValid(from_col, from_row, to_col, to_row)) {
Pawn pawn = this.getBoard()[from_row][from_col];
//System.out.println("Pawn to move : " + pawn);
this.getBoard()[from_row][from_col] = null;
@ -62,54 +63,54 @@ public class PusherBoard {
}
private boolean isValid(int from_col, int from_row, int to_col, int to_row){
private boolean isValid(int from_col, int from_row, int to_col, int to_row) {
Pawn[][] board = this.getBoard();
//out of bound?
if((from_col >7 || from_col<0)||((from_row >7 || from_row<0))||((to_col >7 || to_col<0))||((to_row >7 || to_row<0))) return false;
if ((from_col > 7 || from_col < 0) || ((from_row > 7 || from_row < 0)) || ((to_col > 7 || to_col < 0)) || ((to_row > 7 || to_row < 0)))
return false;
//no pawn to move?
Pawn pawnToMove = board[from_row][from_col];
if(pawnToMove == null) return false;
if (pawnToMove == null) return false;
//Pawn at destination is our own pawn?
Pawn destination = board[to_row][to_col];
char source_color = pawnToMove.name().charAt(0);
if(destination != null){
if (destination != null) {
char destination_color = destination.name().charAt(0);
if(source_color == destination_color) return false;
if (source_color == destination_color) return false;
}
//Pawn goes back? or move is in valid range?
if(source_color == 'R'){
if(from_row>to_row) return false;
if(from_row+1 != to_row) return false;
}else if(source_color == 'B'){
if(from_row<to_row) return false;
if(from_row-1 != to_row) return false;
if (source_color == 'R') {
if (from_row > to_row) return false;
if (from_row + 1 != to_row) return false;
} else if (source_color == 'B') {
if (from_row < to_row) return false;
if (from_row - 1 != to_row) return false;
}
//PUSHED is in front a PUSHER?
if(pawnToMove.equals(Pawn.B_PUSHED)){
if(from_col+1==to_col){
if(board[from_row+1][from_col+1] != Pawn.B_PUSHER) return false;
}else if(from_col-1==to_col){
if(board[from_row-1][from_col+1] != Pawn.B_PUSHER) return false;
}else if(from_col==to_col){
if(board[from_row+1][from_col] != Pawn.B_PUSHER) return false;
if (pawnToMove.equals(Pawn.B_PUSHED)) {
if (from_col + 1 == to_col) {
return board[from_row + 1][from_col + 1] == Pawn.B_PUSHER;
} else if (from_col - 1 == to_col) {
return board[from_row - 1][from_col + 1] == Pawn.B_PUSHER;
} else if (from_col == to_col) {
return board[from_row + 1][from_col] == Pawn.B_PUSHER;
}
}else if(pawnToMove.equals(Pawn.R_PUSHED)){
if(from_col+1 == to_col){
if(board[from_row+1][from_col-1] != Pawn.R_PUSHER) return false;
}else if(from_col-1 == to_col){
if(board[from_row-1][from_col-1] != Pawn.R_PUSHER) return false;
}else if(from_col == to_col){
if(board[from_row-1][from_col] != Pawn.R_PUSHER) return false;
} else if (pawnToMove.equals(Pawn.R_PUSHED)) {
if (from_col + 1 == to_col) {
return board[from_row + 1][from_col - 1] == Pawn.R_PUSHER;
} else if (from_col - 1 == to_col) {
return board[from_row - 1][from_col - 1] == Pawn.R_PUSHER;
} else if (from_col == to_col) {
return board[from_row - 1][from_col] == Pawn.R_PUSHER;
}
}
return true;
}
@ -117,13 +118,12 @@ public class PusherBoard {
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){
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{
} else {
System.out.print(" | ");
}
}