Rank

value class Rank(val value: Int)

The Rank class represents a row on a chessboard, ranging from 1 to 8. It provides methods for manipulating and querying rank values, performing arithmetic operations, and validating ranges.

Overview

  • A rank is represented by an integer (1 to 8).

  • Provides utility methods for arithmetic operations, comparisons, and range validation.

Arithmetic Operations

  • Addition: You can add an integer to a rank, resulting in a new rank shifted by the given amount.

  • Subtraction: You can subtract an integer from a rank, resulting in a new rank shifted by the given amount.

  • These operations are useful for calculating neighboring ranks or iterating over ranks programmatically.

Example Usage

val rank = Rank(5)
val nextRank = rank + 1 // Rank(6)
val isEqual = rank.isEqualTo(5) // true

Constructors

Link copied to clipboard
constructor(value: Int)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val value: Int

The integer value of the rank (1 to 8).

Functions

Link copied to clipboard
fun isEqualTo(other: Int): Boolean

Checks if the rank is equal to the given integer.

Link copied to clipboard
operator fun minus(other: Int): Rank

Subtracts an integer from the rank, resulting in a new rank shifted by the given amount.

Link copied to clipboard
operator fun plus(other: Int): Rank

Adds an integer to the rank, resulting in a new rank shifted by the given amount.

Link copied to clipboard
internal fun toArrayIndex(): Int
Link copied to clipboard
open override fun toString(): String

Returns the string representation of the rank.