PK 5S: META-INF/PK 4S:7;META-INF/MANIFEST.MFManifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 10.0-b19 (Sun Microsystems Inc.) Main-Class: Checkers Class-Path: X-COMMENT: Main-Class will be added automatically by build PK @\:$ػeNN Board$1.class1*      $SwitchMap$Square[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFile Board.javaEnclosingMethod!" #$ %& '(java/lang/NoSuchFieldError )&Board$1 InnerClassesjava/lang/ObjectBoardSquarevalues ()[LSquare; BLACK_PAWNLSquare;ordinal()I WHITE_PAWN    l( OKOK #&c' PK @\:,G; ; Board.class1 #ST U V W X Y Z [ \ ] ^_ ^`a S ^b cd e f g hi hjk l $m n o p q rs S tu(vw InnerClassessquares [LSquare;()VCodeLineNumberTableLocalVariableTablethisLBoard; setupBoardiIundoMove (LBoard;)VnewBoard executeMove (LMove;)Vri$Ljava/util/Iterator;removeLjava/util/Vector;moveLMove;startsqLSquare;lastLocalVariableTypeTable'Ljava/util/Vector;squareAt (I)LSquare;indexsquareBelongsTo(ILPlayerColor;)Zpc LPlayerColor; squareIsEmpty(I)Zcopy ()LBoard;b SourceFile Board.java )*Square '( 0* xA yA zA {A |* }* EF~ E java/util/Vector    java/lang/Integer A A Board( java/util/ObservableBoard$1BORDEREMPTY WHITE_PAWN BLACK_PAWN setChangednotifyObserversMove(I)I includesJump()Zlength()Ijava/lang/MathabsvalueOf(I)Ljava/lang/Integer;add(Ljava/lang/Object;)Ziterator()Ljava/util/Iterator;java/util/IteratorhasNextnext()Ljava/lang/Object;intValue$SwitchMap$Square[Iordinal BLACK_KING WHITE_KING belongsTo(LPlayerColor;)ZisEmptyclone!#'()*+H**7*,$ %&- ./0*+<7*S <-*S <*S <-*S*S*S*$S* * ,J,-,. /)./081A0G2P3Y2_4i5s6}789-41212212J12./34+t"=7*+ S* * ,<=<?@!A- 12"./"5/67+F4+ =*2N*S+ *+ -S* * Y:6+W+ +d `l6W*+ -S* * +d*+ S:'6*S* * ++d 6 (K-.@.*S* * *S* * , HI JKL(M,N3P<QHR^SiTuUyV}WXQ[\]^abc efgh!j+k/l3p-f ^882?]1212.9:<;<4./4=>.?2 '@AWB2C <;DEF+;*2,x-./G2HI+I *2,,-  ./ G2 JKLM+> *2,- ./ G2NO+WY L+*!""+,-./P/QR& $PK @\:yـuu Board.java import java.util.Observable; import java.util.Vector; /** * This class represents a checkerboard. A checkerboard consists of 64 squares * of which only 32 are used. Instead of standard notation an internal representation * is used for easier move calculation. * * Standard Internal * representation representation * * White White * 32 31 30 29 10 11 12 13 * 28 27 26 25 14 15 16 17 * 24 23 22 21 19 20 21 22 * 20 19 18 17 23 24 25 26 * 16 15 14 13 28 29 30 31 * 12 11 10 9 32 33 34 35 * 8 7 6 5 37 38 39 40 * 4 3 2 1 41 42 43 44 * Black Black * * @author Aswin F. van Woudenberg */ public class Board extends Observable { /** * The array of Piece's represent a checkerboard. An internal representation * is used for easy Move generation. */ private Square squares[] = new Square[55]; /** * This constructor simply initializes the board */ public Board() { setupBoard(); } /** * This method initializes the board */ public void setupBoard() { for (int i=0;i<55;i++) squares[i] = Square.BORDER; for (int i=10;i<45;i++) squares[i] = Square.EMPTY; for (int i=10;i<23;i++) squares[i] = Square.WHITE_PAWN; for (int i=32;i<45;i++) squares[i] = Square.BLACK_PAWN; squares[18] = Square.BORDER; squares[27] = Square.BORDER; squares[36] = Square.BORDER; setChanged(); notifyObservers(); } public void undoMove(Board newBoard) { for (int i=0; i<55; i++) { squares[i] = newBoard.squareAt(i); } setChanged(); notifyObservers(); } /** * This method executes a move updating the checkerboard. * @param move The move to be executed. */ public void executeMove(Move move) { int start = move.squareAt(0); Square sq = squares[start]; squares[start] = Square.EMPTY; if (!move.includesJump()) { squares[move.squareAt(1)] = sq; setChanged(); notifyObservers(); } else { Vector remove = new Vector(); for (int i=1; i40) { switch(sq) { case BLACK_PAWN: squares[last] = Square.BLACK_KING; setChanged(); notifyObservers(); break; case WHITE_PAWN: squares[last] = Square.WHITE_KING; setChanged(); notifyObservers(); break; } } } /** * This method returns the square at a specific index * @param index The index of the square * @return The square enum constant */ public Square squareAt(int index) { return squares[index]; } /** * This method can be used to find out if a square belongs to a specific player * @param index The index of the square * @param pc A PlayerColor enum value * @return A boolean indicating whether the square belongs to this player. */ public boolean squareBelongsTo(int index, PlayerColor pc) { return squares[index].belongsTo(pc); } /** * This method returns true if a square has no pieces on it and it isn't the border. * @param index The index of the square. * @return A boolean indicating whether the square is empty. */ public boolean squareIsEmpty(int index) { return squares[index].isEmpty(); } /** * This method creates a copy of this Move object and returns it. * @return The return value is a copy of this move object. */ public Board copy() { Board b = new Board(); b.squares = (Square[])squares.clone(); return b; } } PK @\:CheckerBoard$1.class10        !$$SwitchMap$Square[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFileCheckerBoard.javaEnclosingMethod%& '( )* +,java/lang/NoSuchFieldError -* .* /*CheckerBoard$1 InnerClassesjava/lang/Object CheckerBoardSquarevalues ()[LSquare; WHITE_KINGLSquare;ordinal()I BLACK_KING WHITE_PAWN BLACK_PAWN   F OKOKOKOK #&'256ADs*'6E#  PK @\:4CheckerBoard.class1 `a ` bc d e fg h i j k l m n o p qr qs t u v "w xy z{ q| } q~  InnerClassesinvertedZboardLBoard; selectedColorLjava/awt/Color;selectedFieldsLjava/util/HashSet; Signature(Ljava/util/HashSet;()VCodeLineNumberTableLocalVariableTablethisLCheckerBoard; selectField(I)VfieldIgetSelectedFields()Ljava/util/Set; unselectFieldunselectAllFields isSelected(I)ZsetBoard (LBoard;)Vb setInverted(Z)Vvalue isInverted()ZpaintComponent(Ljava/awt/Graphics;)VxygLjava/awt/Graphics; squareWidth squareHeightgetFieldByPixelCoord(II)Imxmy calcIndexindexArr[[I indexArrInvupdate+(Ljava/util/Observable;Ljava/lang/Object;)VoLjava/util/Observable;argLjava/lang/Object; SourceFileCheckerBoard.java /0java/util/HashSet +,java/awt/Color / )* 0 '( %& * TQ >? *   * [I 0 CheckerBoardjavax/swing/JPaneljava/util/ObserverCheckerBoard$1(III)Vjava/lang/IntegervalueOf(I)Ljava/lang/Integer;add(Ljava/lang/Object;)ZremoveclearcontainsgetWidth()I getHeightWHITEjava/awt/GraphicssetColor(Ljava/awt/Color;)VfillRect(IIII)VGRAY$SwitchMap$SquareBoardsquareAt (I)LSquare;SquareordinalfillOvalBLACKdrawOvalrepaint! !%&'()*+,-. /01X"**Y*Y2!3 "45671E * W2 ! "3 45 89:;1/*2)3 45<71E * W2 1 23 45 89=016* 2 893 45>?1@ * 2B3 45 89@A1>*+ 2 JK345B(CD1>*2 RS345E&FG1/*2Z3 45HI1*l=*l>66`p++hh**+* ++hh* \* *.Cu ++h`h`dd++h`h`dd+h `h `dd++h`h`dd++h`h`dd+h `h `ddz++h`h`dd++h`h`dd=++h`h`dd++h`h`ddE52%cdfg$h.i5jFlUm`ogqur|suvwxyz|}$~+A[^e{gf3>J9K945LMN9O9PQ1b*l>*l66H68h*`h h`h *DŽ2& %KTZ`3H<J9LK9b45bR9bS9ZN9QO9TQ1WY YOY OYOY OYOY OYOY OSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY Y OYOY!OYOY"OYOY#OYOSY YOY%OYOY&OYOY'OYOY(OSY Y)OYOY*OYOY+OYOY,OYOSNY YOY,OYOY+OYOY*OYOY)OSY Y(OYOY'OYOY&OYOY%OYOSY YOY#OYOY"OYOY!OYOY OSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY YOYOYOYOYOYOYOYOSY Y OYOY OYOY OYOY OYOS:* 2.-2.2p3445J9K9pUVWVXY1S +* *2 3  45 Z[ \]^_$ "PK @\:ܔ0PPCheckerBoard.javaimport java.awt.Color; import java.awt.Graphics; import java.util.HashSet; import java.util.Observable; import java.util.Observer; import java.util.Set; import javax.swing.JPanel; /** * This class is responsible for painting the checkerboard. * @author Aswin F. van Woudenberg */ public class CheckerBoard extends JPanel implements Observer { private boolean inverted; private Board board; private Color selectedColor; private HashSet selectedFields; /** * The constructor */ public CheckerBoard() { selectedFields = new HashSet(); selectedColor = new Color(255,128,0); } /** * This method adds a selected field to the set. If the field is already * selected, nothing happens. * @param field The field to select */ public void selectField(int field) { selectedFields.add(field); } /** * Return the selected fields as a Set * @return A Set containing the selected fields. */ public Set getSelectedFields() { return selectedFields; } /** * This method removes a field from the selected set. * @param field The field to unselect */ public void unselectField(int field) { selectedFields.remove(field); } /** * This method unselects all selected fields. */ public void unselectAllFields() { selectedFields.clear(); } /** * This method returns a boolean if the field is part of the set of selected * fields. * @param field An int denoting the field. * @return A boolean that indicates whether the field is selected. */ public boolean isSelected(int field) { return selectedFields.contains(field); } /** * Set the model board. * @param b The Board object. */ public void setBoard(Board b) { board = b; } /** * Set inverted, which means draw the checkerboard from a certain point of view. * @param value A boolean indicating whether the checkerboard should be drawn inverted. */ public void setInverted(boolean value) { inverted = value; } /** * This method returns true if the checkerboard is being drawn inverted. * @return A boolean indicating whether the checkerboard is being drawn inverted. */ public boolean isInverted() { return inverted; } /** * This overridden method draws the checkerboard. * @param g The graphics object. */ @Override public void paintComponent(Graphics g) { int squareWidth = getWidth() / 8; int squareHeight = getHeight() / 8; for (int y=0; y<8; y++) { for (int x=0; x<8; x++) { if ((x+y)%2 == 0) { g.setColor(Color.WHITE); g.fillRect(x*squareWidth, y*squareHeight, squareWidth, squareHeight); } else { if (isSelected(calcIndex(x,y))) { g.setColor(selectedColor); } else { g.setColor(Color.GRAY); } g.fillRect(x*squareWidth, y*squareHeight, squareWidth, squareHeight); if (board!=null) { switch(board.squareAt(calcIndex(x,y))) { case WHITE_KING: g.setColor(Color.WHITE); g.fillOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.setColor(Color.BLACK); g.drawOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.fillOval(x*squareWidth+9, y*squareHeight+9, squareWidth-19, squareHeight-19); break; case BLACK_KING: g.setColor(Color.BLACK); g.fillOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.setColor(Color.WHITE); g.drawOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.fillOval(x*squareWidth+9, y*squareHeight+9, squareWidth-19, squareHeight-19); break; case WHITE_PAWN: g.setColor(Color.WHITE); g.fillOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.setColor(Color.BLACK); g.drawOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); break; case BLACK_PAWN: g.setColor(Color.BLACK); g.fillOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); g.setColor(Color.WHITE); g.drawOval(x*squareWidth+2, y*squareHeight+2, squareWidth-5, squareHeight-5); break; } } } } } } /** * This method returns the field index value by pixel coordinates. This method * will most likely be called from the mouseClick event. * @return The index value */ public int getFieldByPixelCoord(int mx, int my) { int squareWidth = getWidth() / 8; int squareHeight = getHeight() / 8; for (int y=0; y<8; y++) { for (int x=0; x<8; x++) { if (mx>=x*squareWidth && mx<(x+1)*squareWidth && my>=y*squareHeight && my<(y+1)*squareHeight ) { return calcIndex(x,y); } } } return 0; } /** * Calculate the x and y coordinates to the index value for the internal board * representation. * @param x The x coordinate ranging from 0 to 7 * @param y The y coordinate ranging from 0 to 7 * @return The index value */ private int calcIndex(int x, int y) { int indexArr[][] = new int[][] { {0,10,0,11,0,12,0,13}, {14,0,15,0,16,0,17,0}, {0,19,0,20,0,21,0,22}, {23,0,24,0,25,0,26,0}, {0,28,0,29,0,30,0,31}, {32,0,33,0,34,0,35,0}, {0,37,0,38,0,39,0,40}, {41,0,42,0,43,0,44,0} }; int indexArrInv[][] = new int[][] { {0,44,0,43,0,42,0,41}, {40,0,39,0,38,0,37,0}, {0,35,0,34,0,33,0,32}, {31,0,30,0,29,0,28,0}, {0,26,0,25,0,24,0,23}, {22,0,21,0,20,0,19,0}, {0,17,0,16,0,15,0,14}, {13,0,12,0,11,0,10,0} }; if (inverted) { return indexArrInv[y][x]; } return indexArr[y][x]; } public void update(Observable o, Object arg) { if (o == board) { repaint(); } } } PK @\:#xLؑCheckers$1.class1$   this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$1; windowClosing(Ljava/awt/event/WindowEvent;)VevtLjava/awt/event/WindowEvent; SourceFile Checkers.javaEnclosingMethod !  ! "# Checkers$1java/awt/event/WindowAdapterCheckersinitComponents()V access$000)(LCheckers;Ljava/awt/event/WindowEvent;)V   4 *+* N   A *+ PQ    PK @\: FCheckers$10.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$10;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$10java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$900)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\: MR*Checkers$11.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$11;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$11java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1000)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:]ԯCheckers$12.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$12;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$12java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1100)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:9FRCheckers$13.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$13;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$13java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1200)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:HCheckers$14.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$14;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$14java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1300)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:Checkers$15.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$15;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$15java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1400)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:'Checkers$16.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$16;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$16java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$1500)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:*dWCheckers$17.class1   ()VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$17;run SourceFile Checkers.javaEnclosingMethod   Checkers  Checkers$17java/lang/Objectjava/lang/Runnablemain([Ljava/lang/String;)V setVisible(Z)V0  /*     : Y     PK @\:䧌Checkers$2.class1$   this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$2; mouseClicked(Ljava/awt/event/MouseEvent;)VevtLjava/awt/event/MouseEvent; SourceFile Checkers.javaEnclosingMethod !  ! "# Checkers$2java/awt/event/MouseAdapterCheckersinitComponents()V access$100((LCheckers;Ljava/awt/event/MouseEvent;)V   4 *+* U   A *+ WX    PK @\:%xCheckers$3.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$3;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$3java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$200)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+* l   A *+ no    PK @\: ;Checkers$4.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$4;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$4java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$300)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+* w   A *+ yz    PK @\:{.Checkers$5.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$5;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$5java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$400)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:9Checkers$6.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$6;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$6java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$500)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:.#Checkers$7.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$7;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$7java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$600)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:Checkers$8.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$8;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$8java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$700)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:M 5Checkers$9.class1&    this$0 LCheckers; (LCheckers;)VCodeLineNumberTableLocalVariableTablethis InnerClasses LCheckers$9;actionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent; SourceFile Checkers.javaEnclosingMethod! "#  # $% Checkers$9java/lang/Objectjava/awt/event/ActionListenerCheckersinitComponents()V access$800)(LCheckers;Ljava/awt/event/ActionEvent;)V   4 *+*    A *+     PK @\:Q99Checkers.class1 e f g h i j k l m n o p q r s t u v w x "w y "y z{ u | } ~ "    "u $u  'u  *u  -u      4u      ;u              K          X  [ " ^ " a "  a  a a ' '  * * * q * ' ' w 4 4 4  4    ; ; ;  ;        $           ; " "          " "    "  "      "   "! " #$ u % & ' () u *+ *, - . / 0 K1 " 2 34 5678 checkersGameLCheckersGame; possibleMovesLjava/util/Vector; SignatureLjava/util/Vector;gameHasEndedDialogShownZaverageMenuItem"Ljavax/swing/JRadioButtonMenuItem;beginnerMenuItemblackComputerMenuItemblackHumanMenuItem blackMenuLjavax/swing/JMenu; checkerBoardLCheckerBoard; exitMenuItemLjavax/swing/JMenuItem;expertMenuItemgameMenu goodMenuIteminvertedMenuItemLjavax/swing/JCheckBoxMenuItem; levelMenumasterMenuItemmenuBarLjavax/swing/JMenuBar; newMenuItemnoviceMenuItem playersMenu separator1Ljavax/swing/JSeparator; separator2 separator3 separator4 undoMenuItemwhiteComputerMenuItemwhiteHumanMenuItem whiteMenu()VCodeLineNumberTableLocalVariableTablethis LCheckers;initComponentscheckerBoardLayoutLjavax/swing/GroupLayout;layout!blackHumanMenuItemActionPerformed(Ljava/awt/event/ActionEvent;)VevtLjava/awt/event/ActionEvent;$blackComputerMenuItemActionPerformed!whiteHumanMenuItemActionPerformed$whiteComputerMenuItemActionPerformedinvertedMenuItemActionPerformednoviceMenuItemActionPerformedaverageMenuItemActionPerformedbeginnerMenuItemActionPerformedgoodMenuItemActionPerformedexpertMenuItemActionPerformedmasterMenuItemActionPerformedexitMenuItemActionPerformedformWindowClosing(Ljava/awt/event/WindowEvent;)VLjava/awt/event/WindowEvent;newMenuItemActionPerformedcheckerBoardMouseClicked(Ljava/awt/event/MouseEvent;)VmLMove;i$Ljava/util/Iterator;indexILjava/awt/event/MouseEvent;undoMenuItemActionPerformedpossibleSelectSquares()Ljava/util/Set;squaresLjava/util/HashSet;selectedFieldsLjava/util/Set;LocalVariableTypeTable(Ljava/util/HashSet;$Ljava/util/Set;possibleUnselectSquaresmain([Ljava/lang/String;)Vargs[Ljava/lang/String;update+(Ljava/util/Observable;Ljava/lang/Object;)VoLjava/util/Observable;argLjava/lang/Object; access$000)(LCheckers;Ljava/awt/event/WindowEvent;)Vx0x1 access$100((LCheckers;Ljava/awt/event/MouseEvent;)V access$200)(LCheckers;Ljava/awt/event/ActionEvent;)V access$300 access$400 access$500 access$600 access$700 access$800 access$900 access$1000 access$1100 access$1200 access$1300 access$1400 access$1500 SourceFile Checkers.java + * ) ( & % ' $ # " !  9 / 01 ,-   9: ;: <= CheckersGame >? @A BCD EF HI CheckerBoardjavax/swing/JMenuBar javax/swing/JMenu javax/swing/JMenuItem javax/swing/JSeparator        javax/swing/JRadioButtonMenuItem   javax/swing/JCheckBoxMenuItem         G?Checkers HIjava/awt/Cursor ? JKL MNO PQ checkers.gifR ST UV WX YZ checkersFrame [I \Z Checkers$1 InnerClasses ] ^_java/awt/Dimension = `a Checkers$2 bcjavax/swing/GroupLayout d efg ij kmn op qt ut vwGame xIy z{ |}New Checkers$3 ~  Undo Checkers$4PlayersBlack ZHuman Checkers$5Computer Checkers$6White Checkers$7 Checkers$8Inverted Checkers$9LevelBeginner Checkers$10Novice Checkers$11Average Checkers$12Good Checkers$13Expert Checkers$14Master Checkers$15Exit Checkers$16            Z   ?Are you sure you want to exit? *Are you sure you want to start a new game?   : :   C;   ? :; ?    Move  ;    java/util/HashSet : :   Checkers$17  Z :     Black has won this game. White has won this game.javax/swing/JFramejava/util/ObservergetWidth()I getHeightsetSize(II)VsetLevel(I)VgetBoard ()LBoard;setBoard (LBoard;)VBoard addObserver(Ljava/util/Observer;)VsetDefaultCloseOperationsetTitle(Ljava/lang/String;)V setCursor(Ljava/awt/Cursor;)Vjava/awt/ToolkitgetDefaultToolkit()Ljava/awt/Toolkit;java/lang/ObjectgetClass()Ljava/lang/Class;java/lang/Class getResource"(Ljava/lang/String;)Ljava/net/URL;getImage (Ljava/net/URL;)Ljava/awt/Image; setIconImage(Ljava/awt/Image;)VsetLocationByPlatform(Z)VsetName setResizable (LCheckers;)VaddWindowListener"(Ljava/awt/event/WindowListener;)VsetPreferredSize(Ljava/awt/Dimension;)VaddMouseListener!(Ljava/awt/event/MouseListener;)V(Ljava/awt/Container;)V setLayout(Ljava/awt/LayoutManager;)V!javax/swing/GroupLayout$Alignment AlignmentLEADING#Ljavax/swing/GroupLayout$Alignment;createParallelGroup ParallelGroupL(Ljavax/swing/GroupLayout$Alignment;)Ljavax/swing/GroupLayout$ParallelGroup;%javax/swing/GroupLayout$ParallelGroupaddGap,(III)Ljavax/swing/GroupLayout$ParallelGroup;setHorizontalGroupGroup"(Ljavax/swing/GroupLayout$Group;)VsetVerticalGroup setMnemonic(C)VsetTextjavax/swing/KeyStroke getKeyStroke(II)Ljavax/swing/KeyStroke;setAccelerator(Ljavax/swing/KeyStroke;)VaddActionListener"(Ljava/awt/event/ActionListener;)Vadd0(Ljavax/swing/JMenuItem;)Ljavax/swing/JMenuItem;*(Ljava/awt/Component;)Ljava/awt/Component; setSelected((Ljavax/swing/JMenu;)Ljavax/swing/JMenu; setJMenuBar(Ljavax/swing/JMenuBar;)VgetContentPane()Ljava/awt/Container;java/awt/Container addComponent@(Ljava/awt/Component;III)Ljavax/swing/GroupLayout$ParallelGroup;pack PlayerColorBLACK LPlayerColor; PlayerTypeHUMAN LPlayerType; setPlayerType(LPlayerColor;LPlayerType;)VCOMPUTERWHITE isSelected()Z setInvertedrepaintisInitialStatejava/lang/Systemexitjavax/swing/JOptionPaneshowConfirmDialog<(Ljava/awt/Component;Ljava/lang/Object;Ljava/lang/String;I)InewGamegetCurrentPlayerType()LPlayerType;java/awt/event/MouseEventgetXgetYgetFieldByPixelCoord(II)I(I)Zjava/lang/IntegervalueOf(I)Ljava/lang/Integer; java/util/Setcontains(Ljava/lang/Object;)Z unselectField selectFieldjava/util/Vectoriterator()Ljava/util/Iterator;java/util/IteratorhasNextnext()Ljava/lang/Object; getSquares()Ljava/util/Vector;getSelectedFields containsAll(Ljava/util/Collection;)ZunselectAllFields executeMove (LMove;)VundoMovelengthsizesquareAt(I)Ijava/awt/EventQueue invokeLater(Ljava/lang/Runnable;)V setEnabledgetLevel getPlayerType(LPlayerColor;)LPlayerType; isGameOvergetPredefinedCursor(I)Ljava/awt/Cursor;generatePossibleMovesisWinner(LPlayerColor;)ZshowMessageDialog<(Ljava/awt/Component;Ljava/lang/Object;Ljava/lang/String;I)Vjavax/swing/GroupLayout$Group!        &n*****dd**dd*Y* ****** **!* ,7@N\ d!m# n*"Y#*$Y%&*'Y()**Y+,*-Y./**Y+0*-Y.1*'Y(2*'Y(3*4Y56*4Y57*'Y(8*4Y59*4Y5:*;Y<=*-Y.>*'Y(?*4Y5@*4Y5A*4Y5B*4Y5C*4Y5D*4Y5E*-Y.F**Y+G*H*IJ*KYLM*N*OPQRS*T*UV*W*XY*YZ*[Y\]*^Y*_`aY*bL*+c++defg++de fh*)gi*)jk*,Nlm*,nn*,op*,qY*rs*)*,tW*)*/uW*0Zlm*0un*0vp*0wY*xs*)*0tW*)*1uW*2pi*2yk*3bi*3zk*6h{*6|*6}~*6Y**3*6tW*7c{*7~*7Y**3*7tW*2*3tW*8wi*8k*9h{*9}~*9Y**8*9tW*:c{*:|*:~*:Y**8*:tW*2*8tW*)*2tW*=Il*=i*=*=Y**)*=tW*)*>uW*?li*?k*@b{*@~*@Y**?*@tW*Ao{*A~*AY**?*AtW*Ba{*B~*BY**?*BtW*Cg{*C~*CY**?*CtW*De{*D~*DY**?*DtW*Em{*E|*E~*EY**?*EtW*)*?tW*)*FuW*Gxn*Gp*GY*s*)*GtW*&*)W**&aY*bM*,,,de*g,,de* h*- ./!0,172B3M4X5c6n7y89:;<=>?@ABCDEGHI*J=KBLHMMNYTmU|[\]afgijklqrtu(v1w@|L}Xajs|)2:CR^jv (1:IU^gv)5= I Q j I?F*   !F*   "F*  ! #F* $ % $R**=*()* %A * -.   &A * 12   'A * 56   (B * 9 :   )B * = >   *B *  A B   +f"* *IE FHJ!M"" ,-f"* *IP QSU!X""./^**I *[ \^a 01B**++=**{*çp*`**ƶN-G-:*̶͙'*˹**Ч*:d ef!g,h<iGlWm_o{prsx{4{623gM456789@*ѱ ~ :;^YL*M*ƶN->-:,͙$,+,ָW+,F\4,-23D45^V<=N>?@V<AN>BC;[YL*M*ƶN-;-:,͙!,+,dָW+,AY4,*23A45[S<=K>?@S<AK>B DE9 Yٸڱ    FGHI7+**0**@*|*A*|*B*|*C*|*D*|*E* |*9*ݲ|*:*ݲ|*6*ݲ|*7*ݲ|*ޚ=*** **ƧJ*<**ߚ***I *I*߱f5Lc{%*7CQ_jq~ JKLMNO:*+PQ.RS:*+PQ8TU:*+PQ VU:*+ PQ WU:*+ PQ XU:*+ PQ YU:*+ PQ ZU:*+ PQ [U:*+PQ \U:*+PQ ]U:*+PQ ^U:*+PQ _U:*+PQ `U:*+PQ aU:*+PQ bU:*+PQ cdX^qwah@alrasPK @\: O9O9 Checkers.form
PK @\:vcBWBW Checkers.javaimport java.awt.Cursor; import java.awt.Toolkit; import java.util.HashSet; import java.util.Observable; import java.util.Observer; import java.util.Set; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * This class implements the Swing UI of the checkers program. * @author Aswin F. van Woudenberg */ public class Checkers extends JFrame implements Observer { private CheckersGame checkersGame; private Vector possibleMoves; private boolean gameHasEndedDialogShown; /** Creates new form Checkers */ public Checkers() { initComponents(); // adjust the form so that checkerBoard is 240x240 setSize(getWidth()-(checkerBoard.getWidth()-240), getHeight()-(checkerBoard.getHeight()-240)); checkersGame = new CheckersGame(); checkersGame.setLevel(9); // set Master level checkerBoard.setBoard(checkersGame.getBoard()); checkersGame.getBoard().addObserver(checkerBoard); checkersGame.addObserver(this); update(checkersGame,null); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { checkerBoard = new CheckerBoard(); menuBar = new javax.swing.JMenuBar(); gameMenu = new javax.swing.JMenu(); newMenuItem = new javax.swing.JMenuItem(); separator1 = new javax.swing.JSeparator(); undoMenuItem = new javax.swing.JMenuItem(); separator2 = new javax.swing.JSeparator(); playersMenu = new javax.swing.JMenu(); blackMenu = new javax.swing.JMenu(); blackHumanMenuItem = new javax.swing.JRadioButtonMenuItem(); blackComputerMenuItem = new javax.swing.JRadioButtonMenuItem(); whiteMenu = new javax.swing.JMenu(); whiteHumanMenuItem = new javax.swing.JRadioButtonMenuItem(); whiteComputerMenuItem = new javax.swing.JRadioButtonMenuItem(); invertedMenuItem = new javax.swing.JCheckBoxMenuItem(); separator3 = new javax.swing.JSeparator(); levelMenu = new javax.swing.JMenu(); beginnerMenuItem = new javax.swing.JRadioButtonMenuItem(); noviceMenuItem = new javax.swing.JRadioButtonMenuItem(); averageMenuItem = new javax.swing.JRadioButtonMenuItem(); goodMenuItem = new javax.swing.JRadioButtonMenuItem(); expertMenuItem = new javax.swing.JRadioButtonMenuItem(); masterMenuItem = new javax.swing.JRadioButtonMenuItem(); separator4 = new javax.swing.JSeparator(); exitMenuItem = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("Checkers"); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("checkers.gif"))); setLocationByPlatform(true); setName("checkersFrame"); // NOI18N setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); checkerBoard.setPreferredSize(new java.awt.Dimension(240, 240)); checkerBoard.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { checkerBoardMouseClicked(evt); } }); javax.swing.GroupLayout checkerBoardLayout = new javax.swing.GroupLayout(checkerBoard); checkerBoard.setLayout(checkerBoardLayout); checkerBoardLayout.setHorizontalGroup( checkerBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 264, Short.MAX_VALUE) ); checkerBoardLayout.setVerticalGroup( checkerBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 265, Short.MAX_VALUE) ); gameMenu.setMnemonic('g'); gameMenu.setText("Game"); newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); newMenuItem.setMnemonic('n'); newMenuItem.setText("New"); newMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newMenuItemActionPerformed(evt); } }); gameMenu.add(newMenuItem); gameMenu.add(separator1); undoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK)); undoMenuItem.setMnemonic('u'); undoMenuItem.setText("Undo"); undoMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { undoMenuItemActionPerformed(evt); } }); gameMenu.add(undoMenuItem); gameMenu.add(separator2); playersMenu.setMnemonic('p'); playersMenu.setText("Players"); blackMenu.setMnemonic('b'); blackMenu.setText("Black"); blackHumanMenuItem.setMnemonic('h'); blackHumanMenuItem.setSelected(true); blackHumanMenuItem.setText("Human"); blackHumanMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { blackHumanMenuItemActionPerformed(evt); } }); blackMenu.add(blackHumanMenuItem); blackComputerMenuItem.setMnemonic('c'); blackComputerMenuItem.setText("Computer"); blackComputerMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { blackComputerMenuItemActionPerformed(evt); } }); blackMenu.add(blackComputerMenuItem); playersMenu.add(blackMenu); whiteMenu.setMnemonic('w'); whiteMenu.setText("White"); whiteHumanMenuItem.setMnemonic('h'); whiteHumanMenuItem.setText("Human"); whiteHumanMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { whiteHumanMenuItemActionPerformed(evt); } }); whiteMenu.add(whiteHumanMenuItem); whiteComputerMenuItem.setMnemonic('c'); whiteComputerMenuItem.setSelected(true); whiteComputerMenuItem.setText("Computer"); whiteComputerMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { whiteComputerMenuItemActionPerformed(evt); } }); whiteMenu.add(whiteComputerMenuItem); playersMenu.add(whiteMenu); gameMenu.add(playersMenu); invertedMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK)); invertedMenuItem.setMnemonic('i'); invertedMenuItem.setText("Inverted"); invertedMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { invertedMenuItemActionPerformed(evt); } }); gameMenu.add(invertedMenuItem); gameMenu.add(separator3); levelMenu.setMnemonic('l'); levelMenu.setText("Level"); beginnerMenuItem.setMnemonic('b'); beginnerMenuItem.setText("Beginner"); beginnerMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { beginnerMenuItemActionPerformed(evt); } }); levelMenu.add(beginnerMenuItem); noviceMenuItem.setMnemonic('o'); noviceMenuItem.setText("Novice"); noviceMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { noviceMenuItemActionPerformed(evt); } }); levelMenu.add(noviceMenuItem); averageMenuItem.setMnemonic('a'); averageMenuItem.setText("Average"); averageMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { averageMenuItemActionPerformed(evt); } }); levelMenu.add(averageMenuItem); goodMenuItem.setMnemonic('g'); goodMenuItem.setText("Good"); goodMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { goodMenuItemActionPerformed(evt); } }); levelMenu.add(goodMenuItem); expertMenuItem.setMnemonic('e'); expertMenuItem.setText("Expert"); expertMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { expertMenuItemActionPerformed(evt); } }); levelMenu.add(expertMenuItem); masterMenuItem.setMnemonic('m'); masterMenuItem.setSelected(true); masterMenuItem.setText("Master"); masterMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { masterMenuItemActionPerformed(evt); } }); levelMenu.add(masterMenuItem); gameMenu.add(levelMenu); gameMenu.add(separator4); exitMenuItem.setMnemonic('x'); exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitMenuItemActionPerformed(evt); } }); gameMenu.add(exitMenuItem); menuBar.add(gameMenu); setJMenuBar(menuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(checkerBoard, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(checkerBoard, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE) ); pack(); }// //GEN-END:initComponents private void blackHumanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blackHumanMenuItemActionPerformed checkersGame.setPlayerType(PlayerColor.BLACK, PlayerType.HUMAN); }//GEN-LAST:event_blackHumanMenuItemActionPerformed private void blackComputerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blackComputerMenuItemActionPerformed checkersGame.setPlayerType(PlayerColor.BLACK, PlayerType.COMPUTER); }//GEN-LAST:event_blackComputerMenuItemActionPerformed private void whiteHumanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_whiteHumanMenuItemActionPerformed checkersGame.setPlayerType(PlayerColor.WHITE, PlayerType.HUMAN); }//GEN-LAST:event_whiteHumanMenuItemActionPerformed private void whiteComputerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_whiteComputerMenuItemActionPerformed checkersGame.setPlayerType(PlayerColor.WHITE, PlayerType.COMPUTER); }//GEN-LAST:event_whiteComputerMenuItemActionPerformed private void invertedMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertedMenuItemActionPerformed checkerBoard.setInverted(invertedMenuItem.isSelected()); checkerBoard.repaint(); }//GEN-LAST:event_invertedMenuItemActionPerformed private void noviceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noviceMenuItemActionPerformed checkersGame.setLevel(2); }//GEN-LAST:event_noviceMenuItemActionPerformed private void averageMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_averageMenuItemActionPerformed checkersGame.setLevel(4); }//GEN-LAST:event_averageMenuItemActionPerformed private void beginnerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_beginnerMenuItemActionPerformed checkersGame.setLevel(1); }//GEN-LAST:event_beginnerMenuItemActionPerformed private void goodMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goodMenuItemActionPerformed checkersGame.setLevel(6); }//GEN-LAST:event_goodMenuItemActionPerformed private void expertMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_expertMenuItemActionPerformed checkersGame.setLevel(8); }//GEN-LAST:event_expertMenuItemActionPerformed private void masterMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_masterMenuItemActionPerformed checkersGame.setLevel(9); }//GEN-LAST:event_masterMenuItemActionPerformed private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed if (checkersGame.isInitialState()) { System.exit(0); } else { if (JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Checkers", JOptionPane.OK_CANCEL_OPTION) == 0) { System.exit(0); } } }//GEN-LAST:event_exitMenuItemActionPerformed private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing if (checkersGame.isInitialState()) { System.exit(0); } else { if (JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Checkers", JOptionPane.OK_CANCEL_OPTION) == 0) { System.exit(0); } } }//GEN-LAST:event_formWindowClosing private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed if (!checkersGame.isInitialState()) { if (JOptionPane.showConfirmDialog(this, "Are you sure you want to start a new game?", "Checkers", JOptionPane.OK_CANCEL_OPTION) == 0) { checkersGame.newGame(); } } }//GEN-LAST:event_newMenuItemActionPerformed private void checkerBoardMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkerBoardMouseClicked if (checkersGame.getCurrentPlayerType() == PlayerType.HUMAN) { int index = checkerBoard.getFieldByPixelCoord(evt.getX(), evt.getY()); if (index!=0) { if (checkerBoard.isSelected(index)) { if (possibleUnselectSquares().contains(index)) { checkerBoard.unselectField(index); } } else { if (possibleSelectSquares().contains(index)) { checkerBoard.selectField(index); // Check if a move is complete now.. for (final Move m : possibleMoves) { if (m.getSquares().containsAll(checkerBoard.getSelectedFields()) && checkerBoard.getSelectedFields().containsAll(m.getSquares())) { checkerBoard.unselectAllFields(); checkersGame.executeMove(m); } } } } checkerBoard.repaint(); } } }//GEN-LAST:event_checkerBoardMouseClicked private void undoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoMenuItemActionPerformed checkersGame.undoMove(); }//GEN-LAST:event_undoMenuItemActionPerformed /** * Return in a set all index numbers of squares that can be selected. This * method is to be called from the checkBoardMouseClicked event handler. * @return Set containing all selectable squares. */ private Set possibleSelectSquares() { HashSet squares = new HashSet(); Set selectedFields = checkerBoard.getSelectedFields(); for (Move m : possibleMoves) { if (m.getSquares().containsAll(selectedFields) && m.length() > selectedFields.size()) { squares.add(m.squareAt(selectedFields.size())); } } return squares; } /** * Return in a set all index numbers of squares that can be unselected. This * method is to be called from the checkBoardMouseClicked event handler. * @return Set containing all unselectable squares. */ private Set possibleUnselectSquares() { HashSet squares = new HashSet(); Set selectedFields = checkerBoard.getSelectedFields(); for (Move m : possibleMoves) { if (m.getSquares().containsAll(selectedFields) && selectedFields.size()>0) { squares.add(m.squareAt(selectedFields.size()-1)); } } return squares; } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Checkers().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButtonMenuItem averageMenuItem; private javax.swing.JRadioButtonMenuItem beginnerMenuItem; private javax.swing.JRadioButtonMenuItem blackComputerMenuItem; private javax.swing.JRadioButtonMenuItem blackHumanMenuItem; private javax.swing.JMenu blackMenu; private CheckerBoard checkerBoard; private javax.swing.JMenuItem exitMenuItem; private javax.swing.JRadioButtonMenuItem expertMenuItem; private javax.swing.JMenu gameMenu; private javax.swing.JRadioButtonMenuItem goodMenuItem; private javax.swing.JCheckBoxMenuItem invertedMenuItem; private javax.swing.JMenu levelMenu; private javax.swing.JRadioButtonMenuItem masterMenuItem; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem newMenuItem; private javax.swing.JRadioButtonMenuItem noviceMenuItem; private javax.swing.JMenu playersMenu; private javax.swing.JSeparator separator1; private javax.swing.JSeparator separator2; private javax.swing.JSeparator separator3; private javax.swing.JSeparator separator4; private javax.swing.JMenuItem undoMenuItem; private javax.swing.JRadioButtonMenuItem whiteComputerMenuItem; private javax.swing.JRadioButtonMenuItem whiteHumanMenuItem; private javax.swing.JMenu whiteMenu; // End of variables declaration//GEN-END:variables public void update(Observable o, Object arg) { if (o == checkersGame) { // Update undo menu undoMenuItem.setEnabled(!checkersGame.isInitialState()); // Update level menu beginnerMenuItem.setSelected(checkersGame.getLevel()==1); noviceMenuItem.setSelected(checkersGame.getLevel()==2); averageMenuItem.setSelected(checkersGame.getLevel()==4); goodMenuItem.setSelected(checkersGame.getLevel()==6); expertMenuItem.setSelected(checkersGame.getLevel()==8); masterMenuItem.setSelected(checkersGame.getLevel()==9); // Update playertype menu whiteHumanMenuItem.setSelected(checkersGame.getPlayerType(PlayerColor.WHITE)==PlayerType.HUMAN); whiteComputerMenuItem.setSelected(checkersGame.getPlayerType(PlayerColor.WHITE)==PlayerType.COMPUTER); blackHumanMenuItem.setSelected(checkersGame.getPlayerType(PlayerColor.BLACK)==PlayerType.HUMAN); blackComputerMenuItem.setSelected(checkersGame.getPlayerType(PlayerColor.BLACK)==PlayerType.COMPUTER); if (!checkersGame.isGameOver()) { gameHasEndedDialogShown = false; // Update the mouse cursor and generate vector of possible moves if (checkersGame.getCurrentPlayerType()==PlayerType.HUMAN) { checkerBoard.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); possibleMoves = checkersGame.generatePossibleMoves(); //possibleMoves = MoveGen.generatePossibleMoves(checkersGame.getBoard(), checkersGame.getCurrentPlayerColor()); } else { checkerBoard.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } } else { checkerBoard.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); if (!gameHasEndedDialogShown) { if (checkersGame.isWinner(PlayerColor.BLACK)) { JOptionPane.showMessageDialog(this, "Black has won this game.", "Checkers", JOptionPane.PLAIN_MESSAGE); } else { JOptionPane.showMessageDialog(this, "White has won this game.", "Checkers", JOptionPane.PLAIN_MESSAGE); } gameHasEndedDialogShown = true; } } } } } PK @\:踏mmCheckersGame$1.class1*      $SwitchMap$PlayerColor[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFileCheckersGame.javaEnclosingMethod!" #$ %& '(java/lang/NoSuchFieldError )&CheckersGame$1 InnerClassesjava/lang/Object CheckersGame PlayerColorvalues()[LPlayerColor;BLACK LPlayerColor;ordinal()IWHITE    l( OKOK #&=' PK @\:c/CheckersGame.class1 .pq p -rs p -tu -v w x yz -{| p -} -~  / y - ( (   - - -     y    - - ( (   InnerClassesboardLBoard;searchLSearch;players [LPlayerType; currentPlayer LPlayerColor;historyLjava/util/Stack; SignatureLjava/util/Stack;workerLCheckersSearchWorker; gameHasEndedZ()VCodeLineNumberTableLocalVariableTablethisLCheckersGame; isGameOver()ZisInitialStategetCurrentPlayerColor()LPlayerColor;getCurrentPlayerType()LPlayerType;newGamegeneratePossibleMoves()Ljava/util/Vector; possibleMovesLjava/util/Vector; executeMove (LMove;)VmLMove;undoMovebisWinner(LPlayerColor;)ZpcisLoserdoComputerMoveIfNeededsetLevel(I)VdepthIgetLevel()I getPlayerType(LPlayerColor;)LPlayerType; setPlayerType(LPlayerColor;LPlayerType;)Vpt LPlayerType;getBoard ()LBoard; SourceFileCheckersGame.java BCBoard 23Search 45 PlayerType 67 k k 9 89java/util/Stack :; @A J e >? J C C C C _C Q m UV M J Y LM NOCheckersSearchWorker B C a e CheckersGamejava/util/ObservableCheckersGame$1HUMANCOMPUTER PlayerColorBLACKisEmpty$SwitchMap$PlayerColor[IordinalisDonecancel(Z)Z setupBoardclear setChangednotifyObserversMoveGen((LBoard;LPlayerColor;)Ljava/util/Vector;java/util/Vectorcopypush&(Ljava/lang/Object;)Ljava/lang/Object;opponentemptypop()Ljava/lang/Object; (LBoard;)V(LSearch;LCheckersGame;)VexecutesetSearchDepthgetSearchDepth!-.23456789:;<=>?@ABCDL**Y*Y* *  S*  S* *Y*E* "+4;FKF LGHIJD/*E%F GHKJD2*E-F GHLMD/* E5F GHNOD\** .* 2* 2E=?#AF *GHPCDF***W**** ****E. ILMO$P+Q2R9S=TAUEVF FGHQRDj"** L+***+E^ _`ab dF"GH STUVDC+4** W*+!** " ******E. lmno&p*q.r5t:u>vBxFCGHCWXYCDY*#Q***W**$L*+%** " ****E2 { |$)4<GLPTXF4$Z3YGH[\Dg'*&+"**+"E#%F'GH']9^\Da!*&+**+EF!GH!]9_CD_)*' !**(Y**)**E!(F )GH`aD4***W**+***E"'+/3F4GH4bcdeD2*,EF GHfgDf*+.* 2* 2E#F*GH*]9hiD^***W*+.*#* ,S * ,S***E. @GJQUY]F ^GH^]9^jklmD/*EF GHno1 /-PK @\:kkCheckersGame.javaimport java.util.Observable; import java.util.Stack; import java.util.Vector; /** * This class manages a checkers game. * @author Aswin F. van Woudenberg */ public class CheckersGame extends Observable { private Board board; private Search search; private PlayerType players[]; private PlayerColor currentPlayer; private Stack history; private CheckersSearchWorker worker; private boolean gameHasEnded; /** * The constructor. */ public CheckersGame() { board = new Board(); search = new Search(); players = new PlayerType[2]; players[0] = PlayerType.HUMAN; players[1] = PlayerType.COMPUTER; currentPlayer = PlayerColor.BLACK; history = new Stack(); gameHasEnded = false; } /** * This method returns true if the game has ended. * @return A boolean indicating whether the game is over. */ public boolean isGameOver() { return gameHasEnded; } /** * Method that returns if the board is in it's initial state. * @return Boolean indicating the initial state. */ public boolean isInitialState() { return history.isEmpty(); } /** * This method returns the current player who is to move. * @return A PlayerColor type indicating which player's turn it is. */ public PlayerColor getCurrentPlayerColor() { return currentPlayer; } /** * This method returns is the current player is human or a computer. * @return PlayerType denoting COMPUTER or HUMAN. */ public PlayerType getCurrentPlayerType() { switch (currentPlayer) { case BLACK: return players[0]; default: // WHITE return players[1]; } } /** * Start a new game. */ public void newGame() { if (worker != null && !worker.isDone()) { // Cancel current search to begin a new one. // You want only one search at a time. worker.cancel(true); worker = null; } gameHasEnded = false; board.setupBoard(); currentPlayer = PlayerColor.BLACK; history.clear(); setChanged(); notifyObservers(); doComputerMoveIfNeeded(); } /** * Generate all possible moves for the current player and the current board * situation. * @return A vector with all possible moves. */ public Vector generatePossibleMoves() { Vector possibleMoves = MoveGen.generatePossibleMoves(board, currentPlayer); if (possibleMoves.isEmpty()) { gameHasEnded = true; setChanged(); notifyObservers(); } return possibleMoves; } /** * Execute a move and give turn to the opponent. * @param m The move to be executed. */ public void executeMove(Move m) { if (m!=null) { history.push(board.copy()); board.executeMove(m); currentPlayer = currentPlayer.opponent(); setChanged(); notifyObservers(); doComputerMoveIfNeeded(); } else { gameHasEnded = true; setChanged(); notifyObservers(); } } public void undoMove() { if (!history.empty()) { if (worker != null && !worker.isDone()) { // Cancel current search to begin a new one. // You want only one search at a time. worker.cancel(true); worker = null; } Board b = history.pop(); board.undoMove(b); currentPlayer = currentPlayer.opponent(); gameHasEnded = false; setChanged(); notifyObservers(); doComputerMoveIfNeeded(); } } /** * This method returns true if a certain player has won this game. * @param pc The PlayerColor, BLACK or WHITE * @return A boolean indicating if a player has won. */ public boolean isWinner(PlayerColor pc) { if (getCurrentPlayerColor()==pc.opponent() && gameHasEnded) { if (MoveGen.generatePossibleMoves(board, pc.opponent()).isEmpty()) { return true; } } return false; } /** * This method returns true if a certain player has lost this game. * @param pc The player for which to find out. * @return A boolean indicating if the player has lost. */ public boolean isLoser(PlayerColor pc) { if (getCurrentPlayerColor()==pc && gameHasEnded) { if (MoveGen.generatePossibleMoves(board, pc).isEmpty()) { return true; } } return false; } /** * This method checks if the current player is the computer, and if this is * the case, it find a good move. */ private void doComputerMoveIfNeeded() { if (getCurrentPlayerType()==PlayerType.COMPUTER && !gameHasEnded) { worker = new CheckersSearchWorker(search, this); worker.execute(); } } /** * Set the searchdepth. * @param depth The searchdepth a.k.a. level. */ public void setLevel(int depth) { if (worker != null && !worker.isDone()) { // Cancel current search to begin a new one. // You want only one search at a time. worker.cancel(true); worker = null; } search.setSearchDepth(depth); setChanged(); notifyObservers(); doComputerMoveIfNeeded(); } /** * Get the searchdepth * @return The searchdepth a.k.a. level. */ public int getLevel() { return search.getSearchDepth(); } /** * This method returns the PlayerType for a specific PlayerColor. * @param pc The PlayerColor for which the PlayerType is wanted. * @return The PlayerType, HUMAN or COMPUTER. */ public PlayerType getPlayerType(PlayerColor pc) { switch(pc) { case BLACK: return players[0]; default: // WHITE: return players[1]; } } /** * This method sets the PlayerType for PlayerColor black or white * @param pc The PlayerType, HUMAN or COMPUTER * @param pt The PlayerColor, BLACK or WHITE */ public void setPlayerType(PlayerColor pc, PlayerType pt) { if (worker != null && !worker.isDone()) { // Cancel current search to begin a new one. // You want only one search at a time. worker.cancel(true); worker = null; } switch(pc) { case BLACK: players[0] = pt; break; case WHITE: players[1] = pt; break; } setChanged(); notifyObservers(); doComputerMoveIfNeeded(); } /** * This method returns the board representation of the game. * @return The board */ public Board getBoard() { return board; } } PK @\:0tCheckersSearchWorker.class1K , - . /0 /1 23 4 56 /78 9 :;<searchLSearch; checkersGameLCheckersGame;(LSearch;LCheckersGame;)VCodeLineNumberTableLocalVariableTablethisLCheckersSearchWorker;scgdoInBackground()LMove;resultLMove;done()VmexLjava/lang/Exception;()Ljava/lang/Object; Exceptions Signature1Ljavax/swing/SwingWorker; SourceFileCheckersSearchWorker.java "  = >? @AB CD EF G&Move HIjava/lang/Exception J" CheckersSearchWorkerjavax/swing/SwingWorker CheckersGamegetBoard ()LBoard;getCurrentPlayerColor()LPlayerColor;SearchgetComputerMove(LBoard;LPlayerColor;)LMove; isCancelled()Zget executeMove (LMove;)VprintStackTrace!Y**+*,  P***L+  !"!** L*+ L+   " "#&$% ' # $%!A&/*  ' ()*+PK @\:8`CheckersSearchWorker.javaimport javax.swing.SwingWorker; /** * This class subclasses the SwingWorker class and encapsulates the search algorithm * in a seperate Thread. * @author Aswin F. van Woudenberg */ public class CheckersSearchWorker extends SwingWorker { private Search search; private CheckersGame checkersGame; /** * The constructor * @param s The search class * @param cg The CheckersGame class */ public CheckersSearchWorker(Search s, CheckersGame cg) { search = s; checkersGame = cg; } @Override public Move doInBackground() { Move result = search.getComputerMove(checkersGame.getBoard(), checkersGame.getCurrentPlayerColor()); return result; } @Override public void done() { try { if (isCancelled()) { return; } Move m = get(); checkersGame.executeMove(m); } catch (Exception ex) { ex.printStackTrace(); } } } PK @\:SPP Move.class1h AB A C D EF A G H IJ K LMNO A P QR S TUVsquaresLjava/util/Vector; Signature'Ljava/util/Vector;()VCodeLineNumberTableLocalVariableTablethisLMove;([I)ViIarr$[Ilen$i$sqcopy()LMove;m getSquares()Ljava/util/Vector; addSquare(I)Vsquarelength()IsquareAt(I)Iindex finalSquare includesJump()ZtoString()Ljava/lang/String;resultLjava/lang/String; SourceFile Move.java java/util/Vector  WX YZMove [\ ]4 ^_java/lang/Integer `4a b6java/lang/StringBuilder cde f6 cg ;<-java/lang/ObjectvalueOf(I)Ljava/lang/Integer;add(Ljava/lang/Object;)Zclone()Ljava/lang/Object;size elementAt(I)Ljava/lang/Object;intValuejava/lang/Mathabsappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;UtilsquareIndexToNotation(I)Ljava/lang/StringBuilder;! B**Y !"#7**Y+M,>6,.6*W#06 ># $%%&'"(%)%7!"7*'+,TYL+* +$%& !"-".//*. !"01E *W 6 7  !" 2%342* > !"56C* G !"7%84A** d O !"9:w=* * ** d dW X Y9Z;[ =!";<rL* eY+* LY+LY+** d L+def1gEhpj r!"o=>?@PK @\:5z Move.java/** * This class represents a checkers move. A checkers move consists of a sequence * of squares. The square numbers follow that of an internal representation. * @author Aswin F. van Woudenberg */ import java.util.Vector; public class Move { /** * The vector of Integer objects represents the move sequence. */ private Vector squares; /** * This constructor creates a new move. */ public Move() { squares = new Vector(); } /** * This constructor creates a new move with new square values */ public Move(int...sq) { squares = new Vector(); for (int i: sq) { squares.add(i); } } /** * This method creates a copy of this Move object and returns it. * @return The return value is a copy of this move object. */ public Move copy() { Move m = new Move(); m.squares = (Vector)squares.clone(); return m; } /** * This method returns as a Vector the squares the move consists of. * @return A vector representing the move sequence. */ public Vector getSquares() { return squares; } /** * Add a new square to the move sequence. * @param square This is the location one wants to add to the move sequence. */ public void addSquare(int square) { squares.add(square); } /** * This method is used to determine the number of squares in a move sequence. * @return The number of squares in a move. */ public int length() { return squares.size(); } /** * This method returns the square at a particular index of the move sequence. * @param index The index of the move sequence * @return The square sollicited. */ public int squareAt(int index) { return squares.elementAt(index); } /** * This method returns the final square of the move sequence. * @return An integer donating the final square where the move finishes. */ public int finalSquare() { return squares.elementAt(squares.size()-1); } /** * This method checks if the move contains one or more jumps * @return A boolean indicates is the move contains a jump. */ public boolean includesJump() { if (squares.size() > 2) return true; if (Math.abs(squares.elementAt(0) - squares.elementAt(squares.size()-1)) > 5) return true; return false; } /** * This method returns a string representation of the move in standard checkers notation. * @return The string representing the move. */ @Override public String toString() { String result = ""; if (squares.size()>=2) { result += Util.squareIndexToNotation(squares.elementAt(0)); result += "-"; result += Util.squareIndexToNotation(squares.elementAt(squares.size()-1)); } return result; } } PK @\:tMoveGen$1.class10        !$$SwitchMap$Square[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFile MoveGen.javaEnclosingMethod%& '( )* +,java/lang/NoSuchFieldError -* .* /* MoveGen$1 InnerClassesjava/lang/ObjectMoveGenSquarevalues ()[LSquare; WHITE_PAWNLSquare;ordinal()I BLACK_PAWN WHITE_KING BLACK_KING   F OKOKOKOK #&'256AD*'6E#  PK @\:.$ $ MoveGen.class1 OP O Q R ST O UV W X UY Z U[\ ] ^ _ `a bc Ud Ue `f `g h i j k !l `mnop InnerClasses()VCodeLineNumberTableLocalVariableTablethis LMoveGen;generatePossibleMoves((LBoard;LPlayerColor;)Ljava/util/Vector;boardLBoard;pc LPlayerColor;resultLjava/util/Vector;LocalVariableTypeTableLjava/util/Vector;generatePossibleMovesAuxiIgeneratePossibleMovesOnePiece(LBoard;I)Ljava/util/Vector;arr$[Ilen$i$indexgeneratePossibleJumpsgeneratePossibleJumpsOnePiece extResultmLMove;b#generatePossibleJumpsOnePieceExtend!(LBoard;LMove;)Ljava/util/Vector;move jumpsSoFar moveValues (LSquare;)[IsqLSquare; SourceFile MoveGen.java $%java/lang/AssertionError ?, qr 5,java/util/Vectors tu 89 vw xy IJ z{Move $| }~ @9  r r EF ; MoveGenjava/lang/Object MoveGen$1isEmpty()ZBoardsquareBelongsTo(ILPlayerColor;)ZaddAll(Ljava/util/Collection;)ZsquareAt (I)LSquare; squareIsEmpty(I)Z([I)Vadd(Ljava/lang/Object;)ZSquare belongsTo()LPlayerColor; PlayerColoropponentcopy ()LBoard; executeMove (LMove;)VisPawnisKing finalSquare()I()LMove; addSquare(I)V$SwitchMap$Squareordinal! $%&: *Y'  (  )* +,&q*+M, *+,' ( -./0123 14 5,&+YM>7*+ ,* W,')*+,#*)/(* 67+-.+/0#123 #14 89&RYM* N-664-.6*`,Y YOY`OW,':;%<0=J;P@(H%%67?:;;<78=7R-.R>7J123 J14 ?,&+YM>7*+ ,* W,'KLMN#L)Q(* 67+-.+/0#123 #14 @9& ƻYM* N* :66.6*`- *``sY YOY``O:*:  *  `` ( :   ,W , W ,Wb,'B\]^1_N`hanbudefgikl^p(p A2 hVBCnPD. 167:; <7#=7-.>712/03A4 14 EF& ߻YM+>* :* :66.6*` *``+:  ``Y YOY``O: *:   *  `` (  :   , W , W , WO,'N{| }~7U[g~( A2 [|GC VBC PD. 767!:;&<7)=7-.HC12 >7/03A4 14 IJ&\*.P ,:: YOYO YOYO YOYOYOYO '(4BX( \KLMN# !PK @\:x MoveGen.javaimport java.util.Vector; /** * This class generates checkers moves. * @author Aswin F. van Woudenberg */ public class MoveGen { /** * This class contains only static methods. Thus, the caller should * be prevented from constructing objects of this class, by declaring this * private constructor. */ private MoveGen() { // prevents even the native class from calling constuctor. throw new AssertionError(); } /** * This method generates possible moves for a specific PlayerColor. * @param board The board state * @param pc The current PlayerColor who's to move * @return A vector with all possible moves. It only returns standard moves * when there are no captures. */ public static Vector generatePossibleMoves(Board board, PlayerColor pc) { Vector result = generatePossibleJumps(board,pc); if (result.isEmpty()) { return generatePossibleMovesAux(board,pc); } return result; } /** * This auxiliary method generates all possible moves, but not captures for * a specific PlayerColor. * @param board The board state * @param pc The current PlayerColor * @return A vector with all possible moves that are not captures. */ private static Vector generatePossibleMovesAux(Board board, PlayerColor pc) { Vector result = new Vector(); for (int i=0; i<55; i++) { if (board.squareBelongsTo(i, pc)) { result.addAll(generatePossibleMovesOnePiece(board,i)); } } return result; } /** * This method returns a Vector with all possible moves starting from a * particular square. * @param board The current board state * @param index The square to start from * @return A vector containing all moves starting from a particular square. */ private static Vector generatePossibleMovesOnePiece(Board board, int index) { Vector result = new Vector(); for (int i : moveValues(board.squareAt(index))) { if (board.squareIsEmpty(index + i)) { result.add(new Move(index,index+i)); } } return result; } /** * This method generates a Vector with all possible jumps or captures for * a particular PlayerColor * @param board The current board state * @param pc The current PlayerColor * @return A vector containing all possible jumps. */ private static Vector generatePossibleJumps(Board board, PlayerColor pc) { Vector result = new Vector(); for (int i=0; i<55; i++) { if (board.squareBelongsTo(i, pc)) { result.addAll(generatePossibleJumpsOnePiece(board,i)); } } return result; } /** * This method generates a Vector with all possible jumps or captures starting * from a particular square. * @param board The current board state * @param index The starting square * @return A vector containing all possible jumps. */ private static Vector generatePossibleJumpsOnePiece(Board board, int index) { Vector result = new Vector(); PlayerColor pc = board.squareAt(index).belongsTo(); for (int i : moveValues(board.squareAt(index))) { if (board.squareBelongsTo(index+i,pc.opponent()) && board.squareIsEmpty(index+i+i)) { Move m = new Move(index,index+i+i); Board b = board.copy(); b.executeMove(m); if (!(board.squareAt(index).isPawn() && b.squareAt(index+i+i).isKing())) { Vector extResult = generatePossibleJumpsOnePieceExtend(b, m); if (extResult.isEmpty()) { result.add(m); } else { result.addAll(extResult); } } else { result.add(m); } } } return result; } /** * This method generates a Vector with all possible jumps or captures that * can follow a sequence of jumps. * @param board The current board state * @param jumpsSoFar The move so far * @return A vector containing all possible jumps. */ private static Vector generatePossibleJumpsOnePieceExtend(Board board, Move jumpsSoFar) { Vector result = new Vector(); int index = jumpsSoFar.finalSquare(); PlayerColor pc = board.squareAt(index).belongsTo(); for (int i : moveValues(board.squareAt(index))) { if (board.squareBelongsTo(index+i,pc.opponent()) && board.squareIsEmpty(index+i+i)) { Move move = jumpsSoFar.copy(); move.addSquare(index+i+i); Move m = new Move(index,index+i+i); Board b = board.copy(); b.executeMove(m); if (!(board.squareAt(index).isPawn() && b.squareAt(index+i+i).isKing())) { Vector extResult = generatePossibleJumpsOnePieceExtend(b, move); if (extResult.isEmpty()) { result.add(move); } else { result.addAll(extResult); } } else { result.add(move); } } } return result; } /** * This method returns an array with integers representing possible steps * for a specific piece. * @param sq The square the piece is on. * @return An array with possible steps. */ private static int[] moveValues(Square sq) { switch(sq) { case WHITE_PAWN: return new int[]{4, 5}; case BLACK_PAWN: return new int[]{-4, -5}; case WHITE_KING: case BLACK_KING: return new int[]{4, 5, -4, -5}; default: return new int[]{}; } } } PK @\:8PlayerColor.class13 & '() * + , - ./BLACK LPlayerColor;WHITE$VALUES[LPlayerColor;values()[LPlayerColor;CodeLineNumberTablevalueOf!(Ljava/lang/String;)LPlayerColor;LocalVariableTablenameLjava/lang/String;(Ljava/lang/String;I)Vthis Signature()Vopponent()LPlayerColor;Ljava/lang/Enum; SourceFilePlayerColor.java  01 PlayerColor 2    java/lang/Enumclone()Ljava/lang/Object;5(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;@1 @ @ "  5 *  1*+  !;*   "J.Y  Y  YSYS #$%PK @\:0IIPlayerColor.java/** * This enum defines the colors BLACK and WHITE * @author Aswin F. van Woudenberg */ public enum PlayerColor { BLACK, WHITE; /** * This method returns the opponents color * @return The opponents enum value */ public PlayerColor opponent() { return (this==BLACK?WHITE:BLACK); } } PK @\:\ssPlayerType.class11 $ %&' ( ) * + ,-HUMAN LPlayerType;COMPUTER$VALUES [LPlayerType;values()[LPlayerType;CodeLineNumberTablevalueOf (Ljava/lang/String;)LPlayerType;LocalVariableTablenameLjava/lang/String;(Ljava/lang/String;I)Vthis Signature()VLjava/lang/Enum; SourceFilePlayerType.java  ./ PlayerType 0    java/lang/Enumclone()Ljava/lang/Object;5(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;@1 @ @ "  5 *  1*+  J.Y Y  Y SY S !"#PK @\:fPlayerType.java/** * This enum defines the values HUMAN and COMPUTER. * @author Aswin F. van Woudenberg */ public enum PlayerType { HUMAN, COMPUTER; } PK @\:5Search$1.class10        !$$SwitchMap$Square[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFile Search.javaEnclosingMethod%& '( )* +,java/lang/NoSuchFieldError -* .* /*Search$1 InnerClassesjava/lang/ObjectSearchSquarevalues ()[LSquare; WHITE_PAWNLSquare;ordinal()I BLACK_PAWN WHITE_KING BLACK_KING   F OKOKOKOK #&'256AD:*'6E#  PK @\: EI} } Search.class1 S T U VW XY XZ X[ \] ^_ `a `b c Vd `ef Vg \h i jklm InnerClasses PAWNS_WORTHI ConstantValued KINGS_WORTHBACKRANKS_WORTH INFINITY' MAX_DEPTH( searchDepth()VCodeLineNumberTableLocalVariableTablethisLSearch;setSearchDepth(I)VdepthgetSearchDepth()I evaluation(LBoard;LPlayerColor;)IiboardLBoard;pc LPlayerColor;scorecountWhiteKingscountBlackKingscountWhitePawnscountBlackPawns blackMaterial whiteMaterial alphaBeta(LBoard;ILPlayerColor;III)Ibdlowesthighest realDepth possibleMovesLjava/util/Vector;bestLocalVariableTypeTableLjava/util/Vector;(LBoard;ILPlayerColor;)LMove;bestMoveLMove;getComputerMove(LBoard;LPlayerColor;)LMove; SourceFile Search.java &' % nop qrs t1 uv wvx y8z {|} ~ 1 23 Move @A @LSearchjava/lang/ObjectSearch$1$SwitchMap$Square[IBoardsquareAt (I)LSquare;Squareordinal WHITE_PAWNLSquare; BLACK_PAWN PlayerColorBLACKMoveGengeneratePossibleMoves((LBoard;LPlayerColor;)Ljava/util/Vector;java/util/VectorisEmpty()Zsizecopy ()LBoard; elementAt(I)Ljava/lang/Object; executeMove (LMove;)Vopponent()LPlayerColor;! !"#$%&'(< **) *  +,-.(>*) $%*+,/01(/*),* +,23( >6666 6-I+.3$*0 + +  +,+*  hdh`6hdh`6  dh `l`> d`>,t)V679:D<G=J?M@PBSCVEY9_J}KLMOPRSU*p M4+,56789:; <=6>(? @A( +- :6  `d     ' *+- 6 6   V O+ : * d-tt`t6    6   6  )Nef hik*l-n:oArFsZt`uovwxyzs~* 9 `F56I]4 +,B6C78DEFGH / FcI J GK@L(r 6'6+- :6: 6   ^W+ : *d-ttt6   6 :  6  )B !5;Jahlx*z a"9 ;N56$e4 +,B6/78D E{GHvI!kMN J {GKOP(++, N- -  -*+*,)  **++,+56+78%GHJ %GKQR PK @\: Search.java import java.util.Vector; /** * This class implements the minimax with alpha-beta pruning algoritm for Checkers * @author Aswin F. van Woudenberg */ public class Search { // Used by the evaluate method to determine the board situation. private static final int PAWNS_WORTH = 100; private static final int KINGS_WORTH = 130; private static final int BACKRANKS_WORTH = 10; // Used by the minimax with alpha-beta pruning algorithm private static final int INFINITY = 10000; private static final int MAX_DEPTH = 40; /** * This variable defines how deep the algorithm searches for an optimal solution. */ private int searchDepth; /** * The constructor */ public Search() { searchDepth = 5; } /** * This method sets the search depth for the alpha-beta algorithm * @param depth The search depth */ public void setSearchDepth(int depth) { searchDepth = depth; } /** * This method returns the search depth used by the alpha-beta algorithm * @return The search depth */ public int getSearchDepth() { return searchDepth; } /** * This method evaluates the current board situation for a specific player. * @param board The current board situation * @param pc The current player * @return An integer evaluating the board situation. */ private int evaluation(Board board, PlayerColor pc) { int score=0; int countWhiteKings=0, countBlackKings=0, countWhitePawns=0, countBlackPawns=0; for (int i=10; i<45; i++) { switch(board.squareAt(i)) { case WHITE_PAWN: countWhitePawns++; break; case BLACK_PAWN: countBlackPawns++; break; case WHITE_KING: countWhiteKings++; break; case BLACK_KING: countBlackKings++; break; } } if (board.squareAt(10)==Square.WHITE_PAWN && board.squareAt(12)==Square.WHITE_PAWN && countBlackPawns>1) score -= BACKRANKS_WORTH; if (board.squareAt(44)==Square.BLACK_PAWN && board.squareAt(42)==Square.BLACK_PAWN && countWhitePawns>1) score += BACKRANKS_WORTH; int blackMaterial = countBlackKings*KINGS_WORTH + countBlackPawns*PAWNS_WORTH; int whiteMaterial = countWhiteKings*KINGS_WORTH + countWhitePawns*PAWNS_WORTH; score += ((blackMaterial-whiteMaterial)*200)/(blackMaterial+whiteMaterial); score += blackMaterial-whiteMaterial; return pc==PlayerColor.BLACK?score:-score; } /** * The minimax alpha-beta pruning algorithm * @param b The board situation * @param d The search depth * @param pc The current player color * @param lowest The low cut-off value * @param highest The high cut-off value * @param realDepth The actual search depth * @return An int evaluating the board potential situation. */ private int alphaBeta(Board b, int d, PlayerColor pc, int lowest, int highest, int realDepth) { Board board; Vector possibleMoves; possibleMoves = MoveGen.generatePossibleMoves(b, pc); int depth = d; if (possibleMoves.isEmpty()) { return -INFINITY+realDepth-1; } if (depth<1 && possibleMoves.size()==1) { depth++; } if (depth<1 || realDepth>=MAX_DEPTH-1) { return evaluation(b, pc); } int best = -INFINITY; for (int i=0; ibest) { best = score; if (score possibleMoves; possibleMoves = MoveGen.generatePossibleMoves(b, pc); int best = -INFINITY; Move bestMove = possibleMoves.elementAt(0); for (int i=0; ibest) { best = score; bestMove = possibleMoves.elementAt(i); if (score>lowest) { lowest = best; } } } return bestMove; } /** * This method calls the minimax alpha beta pruning function to calculate the * best move to make next. This method should not be called when the game has * already ended. * @param board The current board state. * @param pc The PlayerColor who is to move. * @return The most optimal move to take next. */ public Move getComputerMove(Board board, PlayerColor pc) { Vector possibleMoves; possibleMoves = MoveGen.generatePossibleMoves(board, pc); if (possibleMoves.isEmpty()) { return null; } else if (possibleMoves.size()==1) { return possibleMoves.elementAt(0); } else { return alphaBeta(board,searchDepth,pc); } } } PK @\:kKSquare$1.class11        !"%$SwitchMap$Square[I()VCodeLineNumberTableLocalVariableTableexLjava/lang/NoSuchFieldError; SourceFile Square.javaEnclosingMethod& '( )* +,java/lang/NoSuchFieldError -* .* /* 0*Square$1 InnerClassesjava/lang/ObjectSquarevalues ()[LSquare; WHITE_KINGLSquare;ordinal()I BLACK_KING WHITE_PAWN BLACK_PAWNEMPTY  U OKOKOKOK OK #&'256ADEPSH4'6ET$  PK @\::2&& Square.class1r L MN-O !P !Q RS T U V W X RY Z [ \ "] ^_`abc#% d'()*+ efg InnerClasses WHITE_KINGLSquare; BLACK_KING WHITE_PAWN BLACK_PAWNEMPTYBORDER$VALUES [LSquare;values ()[LSquare;CodeLineNumberTablevalueOf(Ljava/lang/String;)LSquare;LocalVariableTablenameLjava/lang/String;(Ljava/lang/String;I)Vthis Signature()V belongsTo(LPlayerColor;)Zpc LPlayerColor;()LPlayerColor;isEmpty()ZisPawnisKingisPiecetoString()Ljava/lang/String;Ljava/lang/Enum; SourceFile Square.java ,-- hiSquare 2j 78k l? )& '& (& %& <= m? *& DB CB no pqWBwb: 78 +&java/lang/EnumSquare$1clone()Ljava/lang/Object;5(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum; PlayerColorBLACKWHITE$SwitchMap$Square[Iordinal()I@1!@%&@'&@(&@)&@*&@+&,- ./0" 1 2305 *14  567805*+1 N4 9&:;<=0k/+* * * * 14/9&/>?<@0@*  1 4 9&AB07 *1'4  9&CB0>* * 1/4 9&DB0>* * 174 9&EB0>* *1?4 9&FG0>*.3$'*-01H,I/J2K5L8M;N4 >9&H;0{Y Y Y YYY Y SY SY SYSYSY S1 N:IJK$ "PK @\:PXq  Square.java/** * This enum represents a checkers square. * @author Aswin F. van Woudenberg */ public enum Square { WHITE_KING, BLACK_KING, WHITE_PAWN, BLACK_PAWN, EMPTY, BORDER; /** * This method returns true if the square belongs to a particular color. * @param pc A PlayerColor enum. * @return true if piece on square corresponds to PlayerColor. */ public boolean belongsTo(PlayerColor pc) { if (pc == PlayerColor.BLACK) { return (this == BLACK_PAWN || this == BLACK_KING); } else { return (this == WHITE_PAWN || this == WHITE_KING); } } /** * This method returns the PlayerColor the square belongs to. If the square * is empty or doesn't belong to any PlayerColor otherwise, the result is * always PlayerColor.WHITE. Therefor one should always check whether the * square contains a pawn or a king. * @return The PlayerColor the square belongs to, if the square represents a * pawn or a king. */ public PlayerColor belongsTo() { if (belongsTo(PlayerColor.BLACK)) return PlayerColor.BLACK; return PlayerColor.WHITE; } /** * This method determines if the current square is empty. * @return true if there is no piece on the square. */ public boolean isEmpty() { return (this == EMPTY); } /** * This method checks if the square is occupied by a pawn. * @return A boolean indicating whether the square is a pawn. */ public boolean isPawn() { return (this == BLACK_PAWN || this == WHITE_PAWN); } /** * This method checks if the square is occupied by a king. * @return A boolean indicating whether the square is a king. */ public boolean isKing() { return (this == BLACK_KING || this == WHITE_KING); } /** * This method determines if the square is occupied by a king or a pawn. * @return A boolean is the square is not empty or represents a border. */ public boolean isPiece() { return isKing() || isPawn(); } /** * This method returns a string representation of the square. * @return The character representing the piece. */ @Override public String toString() { switch(this) { case WHITE_KING: return "W"; case BLACK_KING: return "B"; case WHITE_PAWN: return "w"; case BLACK_PAWN: return "b"; case EMPTY: return ":"; default: return ""; } } } PK @\:Nqq Util.class1L () ( *+, -./0 (1 2 34 5678 69:;<=()VCodeLineNumberTableLocalVariableTablethisLUtil;squareIndexToNotation(I)IsquareIn printBoard (LBoard;)VboardLBoard; SourceFile Util.java java/lang/AssertionError> ?@ WHITEA BC!+---+---+---+---+---+---+---+---+java/lang/StringBuilder| |: DEF GHI JK:| |::||::| | BLACKUtiljava/lang/Objectjava/lang/SystemoutLjava/io/PrintStream;java/io/PrintStreamprintln(Ljava/lang/String;)Vappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;BoardsquareAt (I)LSquare;SquaretoString()Ljava/lang/String;!: *Y     f"-d<$ " !  "#!Y  *  *  *  *  Y  *  *  *  *  Y  *  *  *  *  Y  *  *  *  *  Y  *  *  *  *  Y  *  *!  *"  *#  Y  *%  *&  *'  *(  Y  *)  **  *+  *,  R$%&i*q+/0+4359:>?NCVDHIMN O !$%&'PK @\: %% Util.java /** * This class defines various useful functions * @author Aswin F. van Woudenberg */ public class Util { /** * This class contains only static utility methods. Thus, the caller should * be prevented from constructing objects of this class, by declaring this * private constructor. */ private Util() { // prevents even the native class from calling constuctor. throw new AssertionError(); } /** * This private method converts an internal square representation to an external * one and is used by the toString method. * @param square The internal representation of the square. * @return The external representation of a square according to standard checkers notation. */ public static int squareIndexToNotation(int square) { int n = 45 - square; if (square<36) n--; if (square<27) n--; if (square<18) n--; return n; } /** * Print the checkerboard. * @param board The board to be printed. */ public static void printBoard(Board board) { System.out.println(" WHITE"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("| |:" + board.squareAt(10).toString() + ":| |:" + board.squareAt(11).toString() + ":| |:" + board.squareAt(12).toString() + ":| |:" + board.squareAt(13).toString() + ":|"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("|:" + board.squareAt(14).toString() + ":| |:" + board.squareAt(15).toString() + ":| |:" + board.squareAt(16).toString() + ":| |:" + board.squareAt(17).toString() + ":| |"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("| |:" + board.squareAt(19).toString() + ":| |:" + board.squareAt(20).toString() + ":| |:" + board.squareAt(21).toString() + ":| |:" + board.squareAt(22).toString() + ":|"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("|:" + board.squareAt(23).toString() + ":| |:" + board.squareAt(24).toString() + ":| |:" + board.squareAt(25).toString() + ":| |:" + board.squareAt(26).toString() + ":| |"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("| |:" + board.squareAt(28).toString() + ":| |:" + board.squareAt(29).toString() + ":| |:" + board.squareAt(30).toString() + ":| |:" + board.squareAt(31).toString() + ":|"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("|:" + board.squareAt(32).toString() + ":| |:" + board.squareAt(33).toString() + ":| |:" + board.squareAt(34).toString() + ":| |:" + board.squareAt(35).toString() + ":| |"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("| |:" + board.squareAt(37).toString() + ":| |:" + board.squareAt(38).toString() + ":| |:" + board.squareAt(39).toString() + ":| |:" + board.squareAt(40).toString() + ":|"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("|:" + board.squareAt(41).toString() + ":| |:" + board.squareAt(42).toString() + ":| |:" + board.squareAt(43).toString() + ":| |:" + board.squareAt(44).toString() + ":| |"); System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println(" BLACK"); } } PK @\:ê checkers.gifGIF89a 3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f!, SHp*a‡ !Jtؐċ q㿏 ?vXH!CxPʔ W(IP&L+[yS&́*劗3|٢;PK 5S: AMETA-INF/PK 4S:7;+META-INF/MANIFEST.MFPK @\:$ػeNN #Board$1.classPK @\:,G; ; Board.classPK @\:yـuu Board.javaPK @\:!CheckerBoard$1.classPK @\:4$CheckerBoard.classPK @\:ܔ0PP5CheckerBoard.javaPK @\:#xLؑRCheckers$1.classPK @\: FTCheckers$10.classPK @\: MR*WCheckers$11.classPK @\:]ԯZCheckers$12.classPK @\:9FRl]Checkers$13.classPK @\:HJ`Checkers$14.classPK @\:(cCheckers$15.classPK @\:'fCheckers$16.classPK @\:*dWhCheckers$17.classPK @\:䧌kCheckers$2.classPK @\:%xmCheckers$3.classPK @\: ;pCheckers$4.classPK @\:{.|sCheckers$5.classPK @\:9VvCheckers$6.classPK @\:.#0yCheckers$7.classPK @\: |Checkers$8.classPK @\:M 5~Checkers$9.classPK @\:Q99Checkers.classPK @\: O9O9 rCheckers.formPK @\:vcBWBW Checkers.javaPK @\:踏mmYLCheckersGame$1.classPK @\:c/NCheckersGame.classPK @\:kk^CheckersGame.javaPK @\:0t^{CheckersSearchWorker.classPK @\:8`CheckersSearchWorker.javaPK @\:SPP Move.classPK @\:5z \Move.javaPK @\:tXMoveGen$1.classPK @\:.$ $ IMoveGen.classPK @\:x MoveGen.javaPK @\:8PlayerColor.classPK @\:0IIPlayerColor.javaPK @\:\ss:PlayerType.classPK @\:fPlayerType.javaPK @\:5Search$1.classPK @\: EI} } Search.classPK @\: +Search.javaPK @\:kKTSquare$1.classPK @\::2&& hSquare.classPK @\:PXq  Square.javaPK @\:Nqq Util.classPK @\: %% Util.javaPK @\:ê checkers.gifPK332 #