Advertisement
loloof64

TestOfChessPresso

Mar 27th, 2012
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.39 KB | None | 0 0
  1. package com.gmail.bernabe.laurent.j2se.chesspresso_test;
  2.  
  3. import javax.swing.JFrame;
  4.  
  5. import chesspresso.Chess;
  6. import chesspresso.game.Game;
  7. import chesspresso.game.view.GameBrowser;
  8. import chesspresso.move.IllegalMoveException;
  9. import chesspresso.position.Position;
  10.  
  11. public class ChessFrame extends JFrame {
  12.  
  13.     public ChessFrame(){
  14.         setTitle("Chesspresso gamebrowser test");
  15.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.        
  17.         add(gameBrowser);
  18.         pack();
  19.        
  20.         addMove(Chess.E2, Chess.E4, false, "Debut pour une partie ouverte");
  21.         addMove(Chess.E7, Chess.E5, false, "Reponse symetrique forte");
  22.         addMove(Chess.G1, Chess.F3, false, null);
  23.         addMove(Chess.B8, Chess.C6, false, null);
  24.         addMove(Chess.F1, Chess.A1, false, null);
  25.     }
  26.    
  27.     private void addMove(int fromSquareIndex, int toSquareIndex,
  28.             boolean isCapturingMove, String comment) {
  29.         Position position = chessGame.getPosition();
  30.         int pieceAtStartSquare = position.getStone(fromSquareIndex);
  31.         short move = position.getPieceMove(pieceAtStartSquare, Chess.sqiToCol(fromSquareIndex),
  32.                 Chess.sqiToRow(fromSquareIndex), toSquareIndex);
  33.         try {
  34.             position.doMove(move);
  35.         } catch (IllegalMoveException e) {
  36.             e.printStackTrace();
  37.         }
  38.     }
  39.    
  40.    
  41.     private Game chessGame = new Game();
  42.     private GameBrowser gameBrowser = new GameBrowser(chessGame);
  43.     private static final long serialVersionUID = -6856238414376776882L;
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement