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.
*/
public enum Cardinal {
N (0),
NE (1),
E (2),
SE (3),
S (4),
SW (5),
W (6),
NW (7);
N (0), /* North or up */
NE (1), /* North-East */
E (2), /* East or right */
SE (3), /* South-East */
S (4), /* South or down */
SW (5), /* South-West */
W (6), /* West or left */
NW (7); /* North-West */
/** Integer representation of the cardinal (starting at 0 for North) */
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) {
this.value = value;
}
@@ -85,5 +89,5 @@ public enum Cardinal {
}
// North, South, East, West cardinals array
public static final Cardinal[] NS_EW = {N, S, E, W};
public static final Cardinal[] NS_EW = { N, S, E, W };
}

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 {
NIL(-1),
WHITE(0),
BLACK(1);
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);
}
NIL, /* No color */
WHITE, /* White color */
BLACK; /* Black color */
/**
* Returns the opposite color of the current color.
*
* @return the opposite color (WHITE if BLACK, BLACK if WHITE, NIL if NIL)
*/
public Color inverse() {
if (this.val == -1)
throw new IllegalArgumentException("No inverse of NIL");
return fromInt((this.val + 1) % 2);
switch (this) {
case WHITE:
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 {
/** The x component of the coordinate */
public int x;
/** The y component of the coordinate */
public int y;
public Coordinate(int x,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) {
this.x = x;
this.y = y;
}
}