File

value class File(val value: Char)

The File class represents a column on a chessboard, ranging from 'a' to 'h'. It provides methods for manipulating and querying file values, converting them to array indices, and performing arithmetic operations.

Overview

  • A file is represented by a single character ('a' to 'h').

  • Provides utility methods for arithmetic operations, comparisons, and conversions.

Arithmetic Operations

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

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

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

Conversion

  • To Array Index: The toArrayIndex method converts the file to a zero-based index (0 for 'a', 7 for 'h').

  • This is useful for accessing arrays or lists that represent chessboard rows or columns.

Example Usage

val file = File('e')
val nextFile = file + 1 // File('f')
val index = file.toArrayIndex() // 4
val isEqual = file.isEqualTo('e') // true

Constructors

Link copied to clipboard
constructor(value: Char)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val value: Char

The character representing the file ('a' to 'h').

Functions

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

Checks if the file is equal to the given character.

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

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

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

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

Link copied to clipboard
internal fun toArrayIndex(): Int

Converts the file to a zero-based array index (0 for 'a', 7 for 'h').

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

Returns the string representation of the file.