Document Cardinal and Color enumerations and Coordinate class files

This commit is contained in:
Dorian HAMDANI
2025-05-06 14:54:25 +02:00
parent 9adaff9bc8
commit 77a1ceca23
3 changed files with 55 additions and 36 deletions

View File

@@ -6,19 +6,23 @@
* operations on cardinals, such as rotation and inverse cardinals. * operations on cardinals, such as rotation and inverse cardinals.
*/ */
public enum Cardinal { public enum Cardinal {
N (0), N (0), /* North or up */
NE (1), NE (1), /* North-East */
E (2), E (2), /* East or right */
SE (3), SE (3), /* South-East */
S (4), S (4), /* South or down */
SW (5), SW (5), /* South-West */
W (6), W (6), /* West or left */
NW (7); NW (7); /* North-West */
/** Integer representation of the cardinal (starting at 0 for North) */ /** Integer representation of the cardinal (starting at 0 for North) */
private final int value; private final int value;
/** Private constructor for the enumeration */ /** Private constructor for the enumeration
*
* @param value the integer value associated with the cardinal direction
* (0 for North, 1 for North-East, etc.)
*/
private Cardinal(int value) { private Cardinal(int value) {
this.value = value; this.value = value;
} }

View File

@@ -1,28 +1,31 @@
/**
* Color enumeration representing the two colors of a gomoku board.
*
* This enumeration represents the colors used on a gomoku board: WHITE and BLACK,
* as well as methods to manipulate and retrieve information about the colors.
*
* Note that the two main colors are named arbitrarily (e.g., WHITE and BLACK),
* only to be used in the context of the game.
*/
public enum Color { public enum Color {
NIL(-1), NIL, /* No color */
WHITE(0), WHITE, /* White color */
BLACK(1); BLACK; /* Black color */
private final int val;
Color(int i) {
this.val = i;
}
public Color fromInt(int i) {
for (Color c : Color.values()) {
if (c.val == val) {
return c;
}
}
throw new IllegalArgumentException("Invalid value: " + this);
}
/**
* Returns the opposite color of the current color.
*
* @return the opposite color (WHITE if BLACK, BLACK if WHITE, NIL if NIL)
*/
public Color inverse() { public Color inverse() {
if (this.val == -1) switch (this) {
throw new IllegalArgumentException("No inverse of NIL"); case WHITE:
return fromInt((this.val + 1) % 2); return BLACK;
case BLACK:
return WHITE;
default:
return NIL;
}
} }
} }

View File

@@ -1,13 +1,25 @@
/**
* Coordinate class to represent a point in 2D space.
*
* This class is used to store the x and y integer components of a 2D coordinate.
* It provides a constructor to initialize the coordinate and
* public fields to access the x and y values.
*/
public class Coordinate { public class Coordinate {
/** The x component of the coordinate */
public int x; public int x;
/** The y component of the coordinate */
public int y; public int y;
/**
* Constructor to create a Coordinate object with specified x and y values.
*
* @param x The x component of the coordinate
* @param y The y component of the coordinate
*/
public Coordinate(int x, int y) { public Coordinate(int x, int y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
} }