Remove AIConfigDialog, simplify some lambdas
This commit is contained in:
parent
9fb60ab0ae
commit
d56ed98304
@ -1,81 +0,0 @@
|
|||||||
package dev.kske.chess.ui;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Project: <strong>Chess</strong><br>
|
|
||||||
* File: <strong>AIConfigDialog.java</strong><br>
|
|
||||||
* Created: <strong>16.07.2019</strong><br>
|
|
||||||
*
|
|
||||||
* @since Chess v0.1-alpha
|
|
||||||
* @author Kai S. K. Engelbart
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("javadoc")
|
|
||||||
public class AIConfigDialog extends JDialog {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8047984368152479992L;
|
|
||||||
|
|
||||||
private int maxDepth;
|
|
||||||
private int alphaBetaThreshold;
|
|
||||||
private boolean startGame = false;
|
|
||||||
|
|
||||||
public AIConfigDialog() {
|
|
||||||
setSize(new Dimension(337, 212));
|
|
||||||
setModal(true);
|
|
||||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
|
||||||
setTitle("AI Configuration");
|
|
||||||
getContentPane().setLayout(null);
|
|
||||||
|
|
||||||
JSpinner spAlphaBetaThreshold = new JSpinner();
|
|
||||||
spAlphaBetaThreshold.setBounds(222, 68, 95, 28);
|
|
||||||
getContentPane().add(spAlphaBetaThreshold);
|
|
||||||
spAlphaBetaThreshold.setModel(new SpinnerNumberModel(-10, -100, 100, 5));
|
|
||||||
|
|
||||||
JSpinner spMaxDepth = new JSpinner();
|
|
||||||
spMaxDepth.setBounds(222, 6, 95, 28);
|
|
||||||
getContentPane().add(spMaxDepth);
|
|
||||||
spMaxDepth.setModel(new SpinnerNumberModel(4, 1, 10, 1));
|
|
||||||
|
|
||||||
JLabel lblAlphabetaThreshold = new JLabel("Alpha-Beta Threshold:");
|
|
||||||
lblAlphabetaThreshold.setBounds(16, 68, 194, 28);
|
|
||||||
getContentPane().add(lblAlphabetaThreshold);
|
|
||||||
|
|
||||||
JButton btnOk = new JButton("OK");
|
|
||||||
btnOk.setBounds(16, 137, 84, 28);
|
|
||||||
getContentPane().add(btnOk);
|
|
||||||
btnOk.addActionListener((evt) -> {
|
|
||||||
maxDepth = ((Integer) spMaxDepth.getValue());
|
|
||||||
alphaBetaThreshold = ((Integer) spAlphaBetaThreshold.getValue());
|
|
||||||
startGame = true;
|
|
||||||
dispose();
|
|
||||||
});
|
|
||||||
btnOk.setToolTipText("Start the game");
|
|
||||||
|
|
||||||
JButton btnCancel = new JButton("Cancel");
|
|
||||||
btnCancel.setBounds(222, 137, 95, 28);
|
|
||||||
getContentPane().add(btnCancel);
|
|
||||||
btnCancel.addActionListener((evt) -> dispose());
|
|
||||||
btnCancel.setToolTipText("Cancel the game start");
|
|
||||||
|
|
||||||
JLabel lblMaximalRecursionDepth = new JLabel("Maximal Recursion Depth:");
|
|
||||||
lblMaximalRecursionDepth.setBounds(16, 12, 194, 16);
|
|
||||||
getContentPane().add(lblMaximalRecursionDepth);
|
|
||||||
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxDepth() { return maxDepth; }
|
|
||||||
|
|
||||||
public void setMaxDepth(int maxDepth) { this.maxDepth = maxDepth; }
|
|
||||||
|
|
||||||
public int getAlphaBetaThreshold() { return alphaBetaThreshold; }
|
|
||||||
|
|
||||||
public void setAlphaBetaThreshold(int alphaBetaThreshold) { this.alphaBetaThreshold = alphaBetaThreshold; }
|
|
||||||
|
|
||||||
public boolean isStartGame() { return startGame; }
|
|
||||||
|
|
||||||
public void setStartGame(boolean startGame) { this.startGame = startGame; }
|
|
||||||
}
|
|
@ -177,7 +177,7 @@ public class GamePane extends JComponent {
|
|||||||
if (game.getBoard().getLog() == null) return;
|
if (game.getBoard().getLog() == null) return;
|
||||||
|
|
||||||
DefaultListModel<MoveNode> model = new DefaultListModel<>();
|
DefaultListModel<MoveNode> model = new DefaultListModel<>();
|
||||||
game.getBoard().getLog().forEach(node -> model.addElement(node));
|
game.getBoard().getLog().forEach(model::addElement);
|
||||||
pgnList.setModel(model);
|
pgnList.setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class MainWindow extends JFrame {
|
|||||||
*
|
*
|
||||||
* @param args command line arguments are ignored
|
* @param args command line arguments are ignored
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) { SwingUtilities.invokeLater(() -> new MainWindow()); }
|
public static void main(String[] args) { SwingUtilities.invokeLater(MainWindow::new); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the application.
|
* Create the application.
|
||||||
@ -185,7 +185,7 @@ public class MainWindow extends JFrame {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
"Failed to save the file " + file.getName() + ": " + e.toString(),
|
"Failed to save the file " + file.getName() + ": " + e,
|
||||||
"File saving error",
|
"File saving error",
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user