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  * Defines two constants, one for the player with the white pieces and one
27  * for the player with the black pieces.
28  */
29 
30 public class Player{
31 
32 
33   /**
34    * A constant for the white player.
35    */
36 
37   public static final Player WHITE_PLAYER = new Player();
38 
39 
40 
41 
42   /**
43    * A constant for the black player.
44    */
45 
46   public static final Player BLACK_PLAYER = new Player();
47 
48 
49 
50 
51   /**
52    * Do not allow others to instantiate this class.
53    */
54 
Player()55   private Player(){}
56 
57 
58 
59 
60   /**
61    * Returns true if this player is the player with the White pieces,
62    * false otherwise.
63    */
64 
isWhite()65   public boolean isWhite(){
66     return (this==WHITE_PLAYER);
67   }
68 
69 
70 
71 
72   /**
73    * Returns true if this player is the player with the Black pieces,
74    * false otherwise.
75    */
76 
isBlack()77   public boolean isBlack(){
78     return (this==BLACK_PLAYER);
79   }
80 
81 
82 
83 
84   /**
85    * Returns the opponent of this player.
86    */
87 
getOpponent()88   public Player getOpponent(){
89     if (this.isWhite())
90       return BLACK_PLAYER;
91     else
92       return WHITE_PLAYER;
93   }
94 
95 
96 
97 
98 
99   /**
100    * Returns "White" for the player with the white pieces and "Black" for the
101    * player with the black pieces.
102    */
103 
toString()104   public String toString(){
105     if (this==WHITE_PLAYER)
106       return "White";
107     else
108       return "Black";
109   }
110 
111 }
112