Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.bernabe.laurent.j2se.chesspresso_test;
- import javax.swing.JFrame;
- import chesspresso.Chess;
- import chesspresso.game.Game;
- import chesspresso.game.view.GameBrowser;
- import chesspresso.move.IllegalMoveException;
- import chesspresso.move.Move;
- import chesspresso.position.Position;
- public class ChessFrame extends JFrame {
- public ChessFrame(){
- setTitle("Chesspresso gamebrowser test");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- add(gameBrowser);
- pack();
- try {
- addMove(Chess.E2, Chess.E4, "Debut pour une partie ouverte");
- addMove(Chess.E7, Chess.E5, "Reponse symetrique forte");
- addMove(Chess.G1, Chess.F3, null);
- addMove(Chess.B8, Chess.C6, null);
- addMove(Chess.F1, Chess.B5, null);
- } catch (IllegalMoveException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private void addMove(int fromSquareIndex, int toSquareIndex, String comment)
- throws IllegalMoveException {
- Position position = chessGame.getPosition();
- short [] legalMoves = position.getAllMoves();
- for (int moveIndex = 0; moveIndex < legalMoves.length; moveIndex++){
- short testedMove = legalMoves[moveIndex];
- if (Move.getFromSqi(testedMove) == fromSquareIndex
- && Move.getToSqi(testedMove) == toSquareIndex){
- try {
- position.doMove(testedMove);
- chessGame.addComment(comment);
- } catch (IllegalMoveException e) {
- e.printStackTrace();
- }
- return;
- }
- }
- throw new IllegalMoveException("");
- }
- private Game chessGame = new Game();
- private GameBrowser gameBrowser = new GameBrowser(chessGame);
- private static final long serialVersionUID = -6856238414376776882L;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement