Skip to content

Commit c201728

Browse files
committed
Initial commit
0 parents  commit c201728

File tree

9 files changed

+565
-0
lines changed

9 files changed

+565
-0
lines changed

FrankyJ.iml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />

pom.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>fko.FrankyJ</groupId>
8+
<artifactId>FrankyJ</artifactId>
9+
<version>0.1-SNAPSHOT</version>
10+
<dependencies>
11+
<dependency>
12+
<groupId>org.junit.jupiter</groupId>
13+
<artifactId>junit-jupiter</artifactId>
14+
<version>RELEASE</version>
15+
<scope>test</scope>
16+
</dependency>
17+
</dependencies>
18+
19+
20+
<properties>
21+
<!-- JAVA8 -->
22+
<maven.compiler.source>14.0</maven.compiler.source>
23+
<maven.compiler.target>14.0</maven.compiler.target>
24+
</properties>
25+
26+
</project>

src/main/java/fko/FrankyJ/Main.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Frank Kopp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package fko.FrankyJ;
27+
28+
public class Main {
29+
public static void main(final String[] args) {
30+
System.out.println("Hello World");
31+
}
32+
}
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Frank Kopp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package fko.FrankyJ.types;
27+
28+
29+
/**
30+
* The Color class represents the two colors of a chess game and a
31+
* special color for empty fields (NONE).
32+
* This class can not be instantiated. It keeps public references to the only possible instances
33+
* White and Black
34+
* These instances are immutable. As it is not possible to have any other instances of
35+
* Colors the use of these instances is as fast as if using an int.
36+
* @author Frank Kopp ([email protected])
37+
*/
38+
public enum Color {
39+
40+
// order has influence on Piece
41+
White(1), // 0
42+
Black(-1); // 1
43+
44+
/**
45+
* This is 1 for white and -1 for black. Useful in evaluation and pawn directions
46+
*/
47+
public final int pawnDir;
48+
private Color opponentColor;
49+
private char shortName;
50+
51+
Color(int pawnDir) {
52+
this.pawnDir = pawnDir;
53+
}
54+
55+
public static final Color[] values = {White, Black};
56+
57+
static {
58+
for (Color c : Color.values()) {
59+
switch (c) {
60+
case White -> {
61+
c.opponentColor = Black;
62+
c.shortName = 'w';
63+
}
64+
case Black -> {
65+
c.opponentColor = White;
66+
c.shortName = 'b';
67+
}
68+
}
69+
}
70+
}
71+
72+
/**
73+
* Returns the other Color.
74+
* @return int - as defined in Color
75+
*/
76+
public Color flip() {
77+
return opponentColor;
78+
}
79+
80+
/**
81+
* Returns a character to use for a String representation of the field.<br>
82+
* It accepts ChesslyColor.BLACK (X), ChesslyColor.WHITE (O), ChesslyColor.EMPTY (-) otherwise
83+
* returns
84+
* an empty character.
85+
* @return char - one of 'b', '-', 'w' or ' '
86+
*/
87+
public char toChar() {
88+
return shortName;
89+
}
90+
91+
/**
92+
* Convenience method to check if the instance is BLACK
93+
* @return true if black
94+
*/
95+
public boolean isBlack() {
96+
return this == Black;
97+
}
98+
99+
/**
100+
* Convenience method to check if the instance is WHITE
101+
* @return true if white
102+
*/
103+
public boolean isWhite() {
104+
return this == White;
105+
}
106+
107+
}
108+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Frank Kopp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package fko.FrankyJ.types;
27+
28+
public enum Direction {
29+
North(8), // 8
30+
East(1), // 1
31+
South(-8), // -North
32+
West(-1), // -East
33+
NorthEast(9), // North + East
34+
Southeast(-7), // South + East
35+
Southwest(-9), // South + West
36+
Northwest(7); // North + West
37+
38+
private final int dir;
39+
40+
Direction(final int d) {
41+
this.dir = d;
42+
}
43+
44+
45+
46+
public int get() {
47+
return dir;
48+
}
49+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Frank Kopp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package fko.FrankyJ.types;
27+
28+
/**
29+
* This enum represents all files of a chess board. If used in a loop via values() omit NOFILE.
30+
*/
31+
public enum File {
32+
33+
a, b, c, d, e, f, g, h, NoFile;
34+
35+
// pre-filled list with all squares
36+
public final long bitBoard;
37+
38+
File() {
39+
final long a = 0b0000000100000001000000010000000100000001000000010000000100000001L;
40+
if (ordinal() < 8) bitBoard = a << ordinal();
41+
else bitBoard = 0;
42+
}
43+
44+
// returns the enum File for a given file number
45+
public static File get(int file) {
46+
return File.values()[file];
47+
}
48+
49+
@Override
50+
public String toString() {
51+
if (this == NoFile) {
52+
return "-";
53+
}
54+
return this.name();
55+
}
56+
57+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Frank Kopp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package fko.FrankyJ.types;
27+
28+
/**
29+
* This enum represents all ranks of a chess board If used in a loop via values() omit NORANK.
30+
*/
31+
public enum Rank {
32+
33+
r1, r2, r3, r4, r5, r6, r7, r8, NoRank;
34+
35+
// pre-filled list with all squares
36+
public final long bitBoard;
37+
38+
39+
Rank() {
40+
final long mask = 0b11111111L;
41+
if (ordinal() < 8) this.bitBoard = mask << (8 * (7 - ordinal()));
42+
else bitBoard = 0;
43+
}
44+
45+
/**
46+
* returns the enum Rank for a given rank number
47+
*/
48+
public static Rank get(int rank) {
49+
return Rank.values()[rank];
50+
}
51+
52+
@Override
53+
public String toString() {
54+
if (this == NoRank) {
55+
return "-";
56+
}
57+
return "" + (this.ordinal() + 1);
58+
}
59+
}
60+

0 commit comments

Comments
 (0)