Module: Sashite::Cgsn

Defined in:
lib/sashite/cgsn.rb,
lib/sashite/cgsn/status.rb

Overview

CGSN (Chess Game Status Notation) implementation for Ruby

Provides functionality for working with rule-agnostic game status values for abstract strategy board games.

This implementation is strictly compliant with CGSN Specification v1.0.0

Defined Under Namespace

Classes: Status

Constant Summary collapse

STATUSES =

Complete list of all defined CGSN status values

%w[
  stale
  checkmate
  stalemate
  nomove
  bareking
  mareking
  insufficient
  resignation
  illegalmove
  timelimit
  movelimit
  repetition
  agreement
].freeze
INFERABLE_STATUSES =

Statuses that can be inferred from position analysis

%w[
  stale
  checkmate
  stalemate
  nomove
  bareking
  mareking
  insufficient
].freeze
EXPLICIT_ONLY_STATUSES =

Statuses that require explicit declaration

%w[
  resignation
  illegalmove
  timelimit
  movelimit
  repetition
  agreement
].freeze

Class Method Summary collapse

Class Method Details

.explicit_only?(status) ⇒ Boolean

Check if a status requires explicit declaration

Examples:

Sashite::Cgsn.explicit_only?("resignation")  # => true
Sashite::Cgsn.explicit_only?("checkmate")    # => false
Sashite::Cgsn.explicit_only?("nomove")    # => false

Parameters:

  • status (String, Status)

    the status to check

Returns:

  • (Boolean)

    true if the status is explicit-only



110
111
112
113
114
115
# File 'lib/sashite/cgsn.rb', line 110

def self.explicit_only?(status)
  status_string = String(status)
  EXPLICIT_ONLY_STATUSES.include?(status_string)
rescue ::TypeError
  false
end

.explicit_only_statusesArray<String>

Get the list of explicit-only status values

Examples:

Sashite::Cgsn.explicit_only_statuses
# => ["resignation", "illegalmove", "timelimit", ...]

Returns:

  • (Array<String>)

    array of explicit-only status values



146
147
148
# File 'lib/sashite/cgsn.rb', line 146

def self.explicit_only_statuses
  EXPLICIT_ONLY_STATUSES.dup
end

.inferable?(status) ⇒ Boolean

Check if a status can be inferred from position analysis

Examples:

Sashite::Cgsn.inferable?("checkmate")     # => true
Sashite::Cgsn.inferable?("nomove")     # => true
Sashite::Cgsn.inferable?("resignation")   # => false

Parameters:

  • status (String, Status)

    the status to check

Returns:

  • (Boolean)

    true if the status is inferable



94
95
96
97
98
99
# File 'lib/sashite/cgsn.rb', line 94

def self.inferable?(status)
  status_string = String(status)
  INFERABLE_STATUSES.include?(status_string)
rescue ::TypeError
  false
end

.inferable_statusesArray<String>

Get the list of inferable status values

Examples:

Sashite::Cgsn.inferable_statuses
# => ["stale", "checkmate", "stalemate", "nomove", ...]

Returns:

  • (Array<String>)

    array of inferable status values



135
136
137
# File 'lib/sashite/cgsn.rb', line 135

def self.inferable_statuses
  INFERABLE_STATUSES.dup
end

.parse(value) ⇒ Status

Parse a status value into a Status object

Examples:

Sashite::Cgsn.parse("checkmate")    # => #<Cgsn::Status value="checkmate">
Sashite::Cgsn.parse("nomove")    # => #<Cgsn::Status value="nomove">
Sashite::Cgsn.parse("resignation")  # => #<Cgsn::Status value="resignation">

Parameters:

  • value (String)

    the status value to parse

Returns:

  • (Status)

    new status instance

Raises:

  • (ArgumentError)

    if the status value is invalid



81
82
83
# File 'lib/sashite/cgsn.rb', line 81

def self.parse(value)
  Status.new(value)
end

.statusesArray<String>

Get the list of all defined CGSN status values

Examples:

Sashite::Cgsn.statuses
# => ["stale", "checkmate", "stalemate", "nomove", ...]

Returns:

  • (Array<String>)

    array of all status values



124
125
126
# File 'lib/sashite/cgsn.rb', line 124

def self.statuses
  STATUSES.dup
end

.valid?(value) ⇒ Boolean

Check if a string is a valid CGSN status value

Examples:

Sashite::Cgsn.valid?("checkmate")     # => true
Sashite::Cgsn.valid?("nomove")     # => true
Sashite::Cgsn.valid?("timelimit")    # => true
Sashite::Cgsn.valid?("invalid")       # => false
Sashite::Cgsn.valid?("Checkmate")     # => false
Sashite::Cgsn.valid?(:checkmate)      # => true (converts to "checkmate")

Parameters:

  • value (String)

    the status to validate

Returns:

  • (Boolean)

    true if the status is valid



64
65
66
67
68
69
# File 'lib/sashite/cgsn.rb', line 64

def self.valid?(value)
  status_string = String(value)
  STATUSES.include?(status_string)
rescue ::TypeError
  false
end