[LIB-9] Add original chesshog source files
[chesshog.git] / src / main / java / org / hedgecode / chess / position / Square.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 Square {
25
26     A1 (0, 0), B1 (1, 0), C1 (2, 0), D1 (3, 0), E1 (4, 0), F1 (5, 0), G1 (6, 0), H1 (7, 0),
27     A2 (0, 1), B2 (1, 1), C2 (2, 1), D2 (3, 1), E2 (4, 1), F2 (5, 1), G2 (6, 1), H2 (7, 1),
28     A3 (0, 2), B3 (1, 2), C3 (2, 2), D3 (3, 2), E3 (4, 2), F3 (5, 2), G3 (6, 2), H3 (7, 2),
29     A4 (0, 3), B4 (1, 3), C4 (2, 3), D4 (3, 3), E4 (4, 3), F4 (5, 3), G4 (6, 3), H4 (7, 3),
30     A5 (0, 4), B5 (1, 4), C5 (2, 4), D5 (3, 4), E5 (4, 4), F5 (5, 4), G5 (6, 4), H5 (7, 4),
31     A6 (0, 5), B6 (1, 5), C6 (2, 5), D6 (3, 5), E6 (4, 5), F6 (5, 5), G6 (6, 5), H6 (7, 5),
32     A7 (0, 6), B7 (1, 6), C7 (2, 6), D7 (3, 6), E7 (4, 6), F7 (5, 6), G7 (6, 6), H7 (7, 6),
33     A8 (0, 7), B8 (1, 7), C8 (2, 7), D8 (3, 7), E8 (4, 7), F8 (5, 7), G8 (6, 7), H8 (7, 7);
34
35     private static final int SIZE = 8;
36
37     private int vertical;
38     private int horizontal;
39
40     Square(int vLine, int hLine) {
41         this.vertical = vLine;
42         this.horizontal = hLine;
43     }
44
45     public int getV() {
46         return vertical;
47     }
48
49     public int getH() {
50         return horizontal;
51     }
52
53     public static Square getSquare(int vLine, int hLine) {
54         for (Square square : Square.values()) {
55             if (square.getV() == vLine && square.getH() == hLine)
56                 return square;
57         }
58         return null;
59     }
60
61     public static Square getSquare(String squareName) {
62         for (Square square : Square.values()) {
63             if (square.name().equalsIgnoreCase(squareName))
64                 return square;
65         }
66         return null;
67     }
68
69     public static int getSize() {
70         return SIZE;
71     }
72
73 }