william #1
|
@ -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>
|
|
@ -4,12 +4,13 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="">
|
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="MiniMax">
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Pushed.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Player.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Pusher.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -23,6 +24,13 @@
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||||
|
<map>
|
||||||
|
<entry key="$PROJECT_DIR$" value="alexis" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="MacroExpansionManager">
|
<component name="MacroExpansionManager">
|
||||||
<option name="directoryName" value="x0367gi2" />
|
<option name="directoryName" value="x0367gi2" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -44,19 +52,19 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"last_opened_file_path": "/home/william/Dev/Projects/Uni/Log320/LOG320_Lab4",
|
"last_opened_file_path": "/home/william/Dev/Projects",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="laboratoire4.Client" />
|
<option name="MAIN_CLASS_NAME" value="laboratoire4.Client" />
|
||||||
|
@ -86,11 +94,25 @@
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1679255648701</updated>
|
<updated>1679255648701</updated>
|
||||||
<workItem from="1679255649975" duration="1223000" />
|
<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>
|
||||||
|
<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 />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="MiniMax" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="MiniMax" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -5,8 +5,7 @@ import java.util.Collection;
|
||||||
public class GameTree {
|
public class GameTree {
|
||||||
private Node root;
|
private Node root;
|
||||||
|
|
||||||
|
public Node buildTree(PusherBoard board){
|
||||||
public Node buildTree(){
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,56 @@
|
||||||
package laboratoire4;
|
package laboratoire4;
|
||||||
|
|
||||||
public enum Pawn {
|
public abstract class Pawn {
|
||||||
R_PUSHER,
|
protected final PawnColor color;
|
||||||
R_PUSHED,
|
protected int col;
|
||||||
B_PUSHER,
|
protected int row;
|
||||||
B_PUSHED
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package laboratoire4;
|
package laboratoire4;
|
||||||
|
|
||||||
public class PusherBoard {
|
public class PusherBoard {
|
||||||
|
|
||||||
private Pawn[][] board;
|
private Pawn[][] board;
|
||||||
|
|
||||||
public PusherBoard() {
|
public PusherBoard() {
|
||||||
|
@ -11,20 +10,22 @@ public class PusherBoard {
|
||||||
public void newGame() {
|
public void newGame() {
|
||||||
this.board = new Pawn[8][8];
|
this.board = new Pawn[8][8];
|
||||||
|
|
||||||
|
// TODO: Construire depuis le serveur
|
||||||
for (int i = 0; i < board.length; i++) {
|
for (int i = 0; i < board.length; i++) {
|
||||||
board[7][i] = Pawn.B_PUSHER;
|
for (int j = 0; j < board.length; j++) {
|
||||||
|
Pawn pawn = null;
|
||||||
|
Pawn.PawnColor color = i < board.length / 2 ?
|
||||||
|
Pawn.PawnColor.RED :
|
||||||
|
Pawn.PawnColor.BLACK;
|
||||||
|
|
||||||
|
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[i][j] = pawn;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,11 +64,11 @@ 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();
|
Pawn[][] board = this.getBoard();
|
||||||
|
|
||||||
//out of bound?
|
//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?
|
//no pawn to move?
|
||||||
Pawn pawnToMove = board[from_row][from_col];
|
Pawn pawnToMove = board[from_row][from_col];
|
||||||
|
@ -94,19 +95,19 @@ public class PusherBoard {
|
||||||
//PUSHED is in front a PUSHER?
|
//PUSHED is in front a PUSHER?
|
||||||
if (pawnToMove.equals(Pawn.B_PUSHED)) {
|
if (pawnToMove.equals(Pawn.B_PUSHED)) {
|
||||||
if (from_col + 1 == to_col) {
|
if (from_col + 1 == to_col) {
|
||||||
if(board[from_row+1][from_col+1] != Pawn.B_PUSHER) return false;
|
return board[from_row + 1][from_col + 1] == Pawn.B_PUSHER;
|
||||||
} else if (from_col - 1 == to_col) {
|
} else if (from_col - 1 == to_col) {
|
||||||
if(board[from_row-1][from_col+1] != Pawn.B_PUSHER) return false;
|
return board[from_row - 1][from_col + 1] == Pawn.B_PUSHER;
|
||||||
} else if (from_col == to_col) {
|
} else if (from_col == to_col) {
|
||||||
if(board[from_row+1][from_col] != Pawn.B_PUSHER) return false;
|
return board[from_row + 1][from_col] == Pawn.B_PUSHER;
|
||||||
}
|
}
|
||||||
} else if (pawnToMove.equals(Pawn.R_PUSHED)) {
|
} else if (pawnToMove.equals(Pawn.R_PUSHED)) {
|
||||||
if (from_col + 1 == to_col) {
|
if (from_col + 1 == to_col) {
|
||||||
if(board[from_row+1][from_col-1] != Pawn.R_PUSHER) return false;
|
return board[from_row + 1][from_col - 1] == Pawn.R_PUSHER;
|
||||||
} else if (from_col - 1 == to_col) {
|
} else if (from_col - 1 == to_col) {
|
||||||
if(board[from_row-1][from_col-1] != Pawn.R_PUSHER) return false;
|
return board[from_row - 1][from_col - 1] == Pawn.R_PUSHER;
|
||||||
} else if (from_col == to_col) {
|
} else if (from_col == to_col) {
|
||||||
if(board[from_row-1][from_col] != Pawn.R_PUSHER) return false;
|
return board[from_row - 1][from_col] == Pawn.R_PUSHER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +119,6 @@ public class PusherBoard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printBoard() {
|
public void printBoard() {
|
||||||
|
|
||||||
for (int i = 7; i >= 0; i--) {
|
for (int i = 7; i >= 0; i--) {
|
||||||
for (int j = 0; j < this.board.length; j++) {
|
for (int j = 0; j < this.board.length; j++) {
|
||||||
if (this.board[i][j] != null) {
|
if (this.board[i][j] != null) {
|
||||||
|
|
Loading…
Reference in New Issue