From 77a1ceca231fa8a4e491284b481c2eab2787a763 Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Tue, 6 May 2025 14:54:25 +0200 Subject: [PATCH] Document Cardinal and Color enumerations and Coordinate class files --- src/Cardinal.java | 24 +++++++++++++---------- src/Color.java | 47 ++++++++++++++++++++++++--------------------- src/Coordinate.java | 20 +++++++++++++++---- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/Cardinal.java b/src/Cardinal.java index ab787dd..9d5a0b0 100644 --- a/src/Cardinal.java +++ b/src/Cardinal.java @@ -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 }; } diff --git a/src/Color.java b/src/Color.java index af9eeaa..c2b5ddd 100644 --- a/src/Color.java +++ b/src/Color.java @@ -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; + } } } diff --git a/src/Coordinate.java b/src/Coordinate.java index 675977a..8786342 100644 --- a/src/Coordinate.java +++ b/src/Coordinate.java @@ -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; } - - }