1 /**
2  * The chess framework library.
3  * More information is available at http://www.jinchess.com/.
4  * Copyright (C) 2002 Alexander Maryanovsky.
5  * All rights reserved.
6  *
7  * The chess framework library is free software; you can redistribute
8  * it and/or modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * The chess framework library is distributed in the hope that it will
13  * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the chess framework library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 
22 package free.chess;
23 
24 
25 /**
26  * An interface classes defining rules for wild chess variants must implement.
27  */
28 
29 public interface WildVariant{
30 
31 
32   /**
33    * Sets the initial position for this wild variant on the given Position.
34    */
35 
init(Position pos)36   void init(Position pos);
37 
38 
39 
40   /**
41    * Returns the set of pieces to which the moving piece can be promoted. If the
42    * move is not a promotion, returns null. The first piece in the array is
43    * considered to be the default promotion piece (it'll be used if for example
44    * a dialog to choose the piece is displayed to the user and he cancels it).
45    * If this method returns a non-null value, the array must contain at least
46    * one element.
47    */
48 
getPromotionTargets(Position pos, Square startingSquare, Square endingSquare)49   Piece [] getPromotionTargets(Position pos, Square startingSquare, Square endingSquare);
50 
51 
52 
53 
54   /**
55    * Creates a Move from the 2 given squares in the given Position.
56    * The created move may be illegal, the implementation must ignore this and
57    * return some Move even if it's illegal. If the specified information is so
58    * bad that it's impossible to construct a move from it altogether, the
59    * implementation is allowed to throw an
60    * <code>IllegalArgumentException</code>. The given stringRepresentation may
61    * be null.
62    */
63 
createMove(Position pos, Square startSquare, Square endSquare, Piece promotionTarget, String stringRepresentation)64   Move createMove(Position pos, Square startSquare, Square endSquare,
65     Piece promotionTarget, String stringRepresentation) throws IllegalArgumentException;
66 
67 
68 
69 
70   /**
71    * Creates a <code>Move</code> object representing a move just like the
72    * specified one, but made in the specified position. If the specified
73    * information is so bad that it's impossible to construct a move from it
74    * altogether, the implementation is allowed to throw an
75    * <code>IllegalArgumentException</code>.
76    */
77 
createMove(Position pos, Move move)78   Move createMove(Position pos, Move move) throws IllegalArgumentException;
79 
80 
81 
82 
83   /**
84    * Creates a short castling move for the current player in the specified
85    * position. Short castling must be legal in the specified position.
86    */
87 
createShortCastling(Position pos)88   Move createShortCastling(Position pos);
89 
90 
91 
92 
93   /**
94    * Creates a long castling move for the current player in the specified
95    * position. Long castling must be legal in the specified position.
96    */
97 
createLongCastling(Position pos)98   Move createLongCastling(Position pos);
99 
100 
101 
102 
103   /**
104    * Makes the given Move in the given Position. This method shoudln't
105    * (and can't) be called directly - call Position.makeMove(Move) instead.
106    * Implementations of this method should only modify the Position via the
107    * modifier to avoid the change listeners of the position from being notified
108    * in the middle of a move procedure where the position isn't "stable". There
109    * is no need to trigger the listeners to be called after the move procedure
110    * is done - <code>Position.makeMove(Move)</code> triggers them as needed
111    * by itself (and since this method can't be called directly, that's the only
112    * way to make a move).
113    */
114 
makeMove(Move move, Position pos, Position.Modifier modifier)115   void makeMove(Move move, Position pos, Position.Modifier modifier);
116 
117 
118 
119 
120   /**
121    * Returns the piece represented by the given String.
122    *
123    * @throws IllegalArgumentException if the given character does not represent
124    * a piece in this WildVariant.
125    */
126 
parsePiece(String s)127   Piece parsePiece(String s);
128 
129 
130 
131 
132   /**
133    * Returns a string for the specified Piece. The piece must be one that was
134    * created by this WildVariant and the returned value must be compatible
135    * with the <code>parsePiece</code> method of this WildVariant.
136    *
137    * @throws IllegalArgumentException if the piece couldn't have been produced
138    * by this WildVariant.
139    */
140 
pieceToString(Piece piece)141   String pieceToString(Piece piece);
142 
143 
144 
145 
146   /**
147    * Creates and returns a default PiecePainter for this WildVariant.
148    *
149    * @see PiecePainter
150    */
151 
createDefaultPiecePainter()152   PiecePainter createDefaultPiecePainter();
153 
154 
155 
156   /**
157    * Creates and returns a default BoardPainter for this WildVariant.
158    *
159    * @see BoardPainter
160    */
161 
createDefaultBoardPainter()162   BoardPainter createDefaultBoardPainter();
163 
164 
165 
166 
167   /**
168    * Returns the name of this WildVariant.
169    */
170 
getName()171   String getName();
172 
173 
174 }
175