org/homelinux/largo/schach/Schach.java
changeset 16 55b0d5006e7b
parent 14 f12f77aa13b2
--- a/org/homelinux/largo/schach/Schach.java
+++ b/org/homelinux/largo/schach/Schach.java
@@ -22,214 +22,215 @@
 import org.homelinux.largo.utils.BrowserLaunch;
 
 public class Schach extends JFrame implements Runnable {
-    static final long serialVersionUID = 1L;
-    static final String helpURL = "http://largo.homelinux.org/cgi-bin/gitweb.cgi?p=games/Schach.git;a=summary";
+	static final long serialVersionUID = 1L;
+	static final String helpURL = "https://www.4customers.de/hg/Schach";
 
-    MouseListener listener;
-    KIBoard board;
-    Point p;
-    JLabel human = new JLabel("<html><font size='5' color='#FFFFFF'>Human</font></html>");
-    JLabel computer = new JLabel("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-    JButton neu = new JButton("Play");
-    JButton pconly = new JButton("PC-PC");
-    JButton back = new JButton("Back");
-    JButton forward = new JButton("For");
-    JButton help = new JButton("Source");
+	MouseListener listener;
+	KIBoard board;
+	Point p;
+	JLabel human = new JLabel("<html><font size='5' color='#FFFFFF'>Human</font></html>");
+	JLabel computer = new JLabel("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+	JButton neu = new JButton("Play");
+	JButton pconly = new JButton("PC-PC");
+	JButton back = new JButton("Back");
+	JButton forward = new JButton("For");
+	JButton help = new JButton("Source");
 
-    SpinnerNumberModel model = new SpinnerNumberModel(4, 1, 8, 1);
-    JSpinner combo = new JSpinner(model);
+	SpinnerNumberModel model = new SpinnerNumberModel(4, 1, 8, 1);
+	JSpinner combo = new JSpinner(model);
 
-    JPanel panel;
-    JPanel fpanel;
+	JPanel panel;
+	JPanel fpanel;
 
-    int search_depth;
+	int search_depth;
 
-    boolean pc_only;
+	boolean pc_only;
 
-    public Schach(int w, int h) {
-        super("Chess by Largo Enterprises");
-        setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
-        board = new KIBoard(w, h);
+	public Schach(int w, int h) {
+		super("Chess by 4customers.de");
+		setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
+		board = new KIBoard(w, h);
 
-        fpanel = new JPanel();
-        fpanel.add(back);
-        fpanel.add(neu);
-        fpanel.add(combo);
-        fpanel.add(pconly);
-        fpanel.add(help);
-        fpanel.add(forward);
+		fpanel = new JPanel();
+		fpanel.add(back);
+		fpanel.add(neu);
+		fpanel.add(combo);
+		fpanel.add(pconly);
+		fpanel.add(help);
+		fpanel.add(forward);
 
-        panel = new JPanel();
-        panel.setLayout(new BorderLayout());
-        panel.add(human, "West");
-        panel.add(fpanel, "Center");
-        panel.add(computer, "East");
+		panel = new JPanel();
+		panel.setLayout(new BorderLayout());
+		panel.add(human, "West");
+		panel.add(fpanel, "Center");
+		panel.add(computer, "East");
 
-        fpanel.setBackground(new Color(50, 100, 200));
-        panel.setBackground(new Color(50, 100, 200));
+		fpanel.setBackground(new Color(50, 100, 200));
+		panel.setBackground(new Color(50, 100, 200));
 
-        getContentPane().setLayout(new BorderLayout());
-        getContentPane().add(panel, "North");
-        getContentPane().add(board, "Center");
+		getContentPane().setLayout(new BorderLayout());
+		getContentPane().add(panel, "North");
+		getContentPane().add(board, "Center");
 
-        neu.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionevent) {
-                human.setText("<html><font size='5' color='#FFFFFF'>Human</font></html>");
-                computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                pc_only = false;
-                board.init();
-                board.negateEstimation(false);
-            }
-        });
+		neu.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent actionevent) {
+				human.setText("<html><font size='5' color='#FFFFFF'>Human</font></html>");
+				computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				pc_only = false;
+				board.init();
+				board.negateEstimation(false);
+			}
+		});
 
-        pconly.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionevent) {
-                human.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                pc_only = true;
-            }
-        });
+		pconly.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent actionevent) {
+				human.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				pc_only = true;
+			}
+		});
 
-        back.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionevent) {
-                board.backwards();
-            }
-        });
+		back.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent actionevent) {
+				board.backwards();
+			}
+		});
 
-        forward.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionevent) {
-                board.forward();
-            }
-        });
+		forward.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent actionevent) {
+				board.forward();
+			}
+		});
 
-        help.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionevent) {
-                BrowserLaunch browser = new BrowserLaunch();
-                browser.openURL(helpURL);
-            }
-        });
+		help.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent actionevent) {
+				BrowserLaunch browser = new BrowserLaunch();
+				browser.openURL(helpURL);
+			}
+		});
 
-        listener = board.getMouseListener();
+		listener = board.getMouseListener();
 
-        pc_only = false;
-        search_depth = 3;
-        pack();
-    }
+		pc_only = false;
+		search_depth = 3;
+		pack();
+	}
 
-    public void computer_play() {
-        while (pc_only) {
-            search_depth = model.getNumber().intValue() - 1;
+	public void computer_play() {
+		while (pc_only) {
+			search_depth = model.getNumber().intValue() - 1;
 
-            if (!board.isBlacksTurn()) {
-                human.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
-                board.negateEstimation(true);
-                if (!board.doBestMove(search_depth)) {
-                    pc_only = false;
-                    return;
-                }
-                board.negateEstimation(false);
-                human.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                board.setBlacksTurn(true);
-            } else {
-                computer.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
-                if (!board.doBestMove(search_depth)) {
-                    pc_only = false;
-                    return;
-                }
-                computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                board.setBlacksTurn(false);
+			if (!board.isBlacksTurn()) {
+				human.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
+				board.negateEstimation(true);
+				if (!board.doBestMove(search_depth)) {
+					pc_only = false;
+					return;
+				}
+				board.negateEstimation(false);
+				human.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				board.setBlacksTurn(true);
+			} else {
+				computer.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
+				if (!board.doBestMove(search_depth)) {
+					pc_only = false;
+					return;
+				}
+				computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				board.setBlacksTurn(false);
 
-                if (board.simu_debug()) {
-                    for (int i = 0; i < 64; i++) {
-                        if ((i + 1) % 8 == 0)
-                            System.err.printf("%2d=%d%n", i, board.getValue(i));
-                        else
-                            System.err.printf("%2d=%d ", i, board.getValue(i));
-                    }
-                }
+				if (board.simu_debug()) {
+					for (int i = 0; i < 64; i++) {
+						if ((i + 1) % 8 == 0)
+							System.err.printf("%2d=%d%n", i, board.getValue(i));
+						else
+							System.err.printf("%2d=%d ", i, board.getValue(i));
+					}
+				}
 
-                try {
-                    Thread.sleep(10);
-                } catch (InterruptedException e) {
-                    System.err.println("computer_play: " + e.getLocalizedMessage());
-                    System.err.println("========================================================================");
-                    e.printStackTrace();
-                    System.err.println("========================================================================");
-                    return;
-                }
-            }
-        }
-    }
+				try {
+					Thread.sleep(10);
+				} catch (InterruptedException e) {
+					System.err.println("computer_play: " + e.getLocalizedMessage());
+					System.err.println("========================================================================");
+					e.printStackTrace();
+					System.err.println("========================================================================");
+					return;
+				}
+			}
+		}
+	}
 
-    public void run() {
-        for (;;) {
+	public void run() {
+		for (;;) {
 
-            /* is this thread safe */
-            search_depth = model.getNumber().intValue() - 1;
+			/* is this thread safe */
+			search_depth = model.getNumber().intValue() - 1;
 
-            if (pc_only) {
-                computer_play();
-            }
+			if (pc_only) {
+				computer_play();
+			}
 
-            if (!board.isBlacksTurn()) {
-                if (listener.isSelected()) {
-                    p = listener.getSelection();
-                    if (board.move(p))
-                        board.setBlacksTurn(true);
-                }
-                try {
-                    Thread.sleep(50);
-                } catch (InterruptedException e) {
-                    System.err.println("Schach::run: " + e.getLocalizedMessage());
-                    System.err.println("========================================================================");
-                    e.printStackTrace();
-                    System.err.println("========================================================================");
-                    return;
-                }
-            } else {
-                human.setText("<html><font size='5' color='#FFFFFF'>Human</font></html>");
-                computer.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
-                board.doBestMove(search_depth);
-                human.setText("<html><font size='5' color='#FF3333'>Human</font></html>");
-                computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
-                board.setBlacksTurn(false);
+			if (!board.isBlacksTurn()) {
+				if (listener.isSelected()) {
+					p = listener.getSelection();
+					if (board.move(p))
+						board.setBlacksTurn(true);
+				}
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+					System.err.println("Schach::run: " + e.getLocalizedMessage());
+					System.err.println("========================================================================");
+					e.printStackTrace();
+					System.err.println("========================================================================");
+					return;
+				}
+			} else {
+				human.setText("<html><font size='5' color='#FFFFFF'>Human</font></html>");
+				computer.setText("<html><font size='5' color='#FF3333'>Computer</font></html>");
+				board.doBestMove(search_depth);
+				human.setText("<html><font size='5' color='#FF3333'>Human</font></html>");
+				computer.setText("<html><font size='5' color='#FFFFFF'>Computer</font></html>");
+				board.setBlacksTurn(false);
 
-                if (board.simu_debug()) {
-                    for (int i = 0; i < 64; i++) {
-                        if ((i + 1) % 8 == 0)
-                            System.out.printf("%2d=%d%n", i, board.getValue(i));
-                        else
-                            System.out.printf("%2d=%d ", i, board.getValue(i));
-                    }
-                }
-            }
-        }
-    }
+				if (board.simu_debug()) {
+					for (int i = 0; i < 64; i++) {
+						if ((i + 1) % 8 == 0)
+							System.out.printf("%2d=%d%n", i, board.getValue(i));
+						else
+							System.out.printf("%2d=%d ", i, board.getValue(i));
+					}
+				}
+			}
+		}
+	}
 
-    public static void main(String args[]) {
-        Schach s = new Schach(74, 74);
+	public static void main(String args[]) {
+		Schach s = new Schach(74, 74);
 
-        s.setResizable(false);
-        s.setVisible(true);
+		s.setResizable(false);
+		s.setVisible(true);
+		s.pack();
 
-        if (args.length == 1) {
-            if (args[0].equals("full"))
-                s.board.setDebug(true, true);
-            else if (args[0].equals("simu"))
-                s.board.setDebug(true, false);
-            else if (args[0].equals("undo"))
-                s.board.setDebug(false, true);
-            else if (args[0].equals("none"))
-                s.board.setDebug(false, false);
-            else {
-                System.out.println("   Chess: java -jar games.jar [full|simu|undo|none]");
-                System.out
-                        .println("Checkers: java -cp games.jar org.homelinux.largo.checkers.Checkers [full|simu|undo|none]");
-            }
-        }
+		if (args.length == 1) {
+			if (args[0].equals("full"))
+				s.board.setDebug(true, true);
+			else if (args[0].equals("simu"))
+				s.board.setDebug(true, false);
+			else if (args[0].equals("undo"))
+				s.board.setDebug(false, true);
+			else if (args[0].equals("none"))
+				s.board.setDebug(false, false);
+			else {
+				System.out.println("   Chess: java -jar games.jar [full|simu|undo|none]");
+				System.out.println(
+						"Checkers: java -cp games.jar org.homelinux.largo.checkers.Checkers [full|simu|undo|none]");
+			}
+		}
 
-        Thread t = new Thread(s);
-        t.setPriority(Thread.NORM_PRIORITY - 1);
-        t.start();
-    }
+		Thread t = new Thread(s);
+		t.setPriority(Thread.NORM_PRIORITY - 1);
+		t.start();
+	}
 }