This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

TestOfChessPresso

By: loloof64 on Mar 27th, 2012  |  syntax: Java 5  |  size: 1.39 KB  |  views: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data