[LIB-9] Add original chesshog source files
[chesshog.git] / src / main / java / org / hedgecode / chess / position / ColorPiece.java
1 /*
2  * Copyright (c) 2018. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.position;
18
19 /**
20  *
21  *
22  * @author Dmitry Samoshin aka gotty
23  */
24 public enum ColorPiece {
25
26     WHITE_PAWN   (Color.WHITE, Piece.PAWN),
27     WHITE_KNIGHT (Color.WHITE, Piece.KNIGHT),
28     WHITE_BISHOP (Color.WHITE, Piece.BISHOP),
29     WHITE_ROOK   (Color.WHITE, Piece.ROOK),
30     WHITE_QUEEN  (Color.WHITE, Piece.QUEEN),
31     WHITE_KING   (Color.WHITE, Piece.KING),
32
33     BLACK_PAWN   (Color.BLACK, Piece.PAWN),
34     BLACK_KNIGHT (Color.BLACK, Piece.KNIGHT),
35     BLACK_BISHOP (Color.BLACK, Piece.BISHOP),
36     BLACK_ROOK   (Color.BLACK, Piece.ROOK),
37     BLACK_QUEEN  (Color.BLACK, Piece.QUEEN),
38     BLACK_KING   (Color.BLACK, Piece.KING);
39
40     private Color color;
41     private Piece piece;
42
43     ColorPiece(Color color, Piece piece) {
44         this.color = color;
45         this.piece = piece;
46     }
47
48     public Color color() {
49         return color;
50     }
51
52     public Piece piece() {
53         return piece;
54     }
55
56     public static ColorPiece getColorPiece(Color color, Piece piece) {
57         if (color == null || piece == null)
58             return null;
59         for (ColorPiece colorPiece : ColorPiece.values()) {
60             if (colorPiece.color.equals(color) && (colorPiece.piece.equals(piece)))
61                 return colorPiece;
62         }
63         return null;
64     }
65
66 }