Class: Sashite::Ggn::Ruleset::Source::Destination::Engine::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/sashite/ggn/ruleset/source/destination/engine/transition.rb

Overview

Represents the result of a valid pseudo-legal move evaluation.

A Transition encapsulates the changes that occur when a move is executed on the game board. Since GGN focuses exclusively on board-to-board transformations, a Transition only contains board state changes: pieces moving, appearing, or disappearing on the board.

Examples:

Basic move (pawn advance)

transition = Transition.new("e2" => nil, "e4" => "CHESS:P")
transition.diff  # => { "e2" => nil, "e4" => "CHESS:P" }

Capture (piece takes enemy piece)

transition = Transition.new("d4" => nil, "e5" => "CHESS:P")
transition.diff  # => { "d4" => nil, "e5" => "CHESS:P" }

Complex move (castling with king and rook)

transition = Transition.new(
  "e1" => nil, "f1" => "CHESS:R", "g1" => "CHESS:K", "h1" => nil
)
transition.diff  # => { "e1" => nil, "f1" => "CHESS:R", "g1" => "CHESS:K", "h1" => nil }

Promotion (pawn becomes queen)

transition = Transition.new("e7" => nil, "e8" => "CHESS:Q")
transition.diff  # => { "e7" => nil, "e8" => "CHESS:Q" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**diff) ⇒ Transition

Creates a new Transition with the specified board changes.

Examples:

Creating a simple move transition

Transition.new("e2" => nil, "e4" => "CHESS:P")

Creating a capture transition

Transition.new("d4" => nil, "e5" => "CHESS:P")

Creating a complex multi-square transition (castling)

Transition.new(
  "e1" => nil,        # King leaves e1
  "f1" => "CHESS:R",  # Rook moves to f1
  "g1" => "CHESS:K",  # King moves to g1
  "h1" => nil         # Rook leaves h1
)

Creating a promotion transition

Transition.new("e7" => nil, "e8" => "CHESS:Q")

Creating an en passant capture

Transition.new(
  "d5" => nil,        # Attacking pawn leaves d5
  "e5" => nil,        # Captured pawn removed from e5
  "e6" => "CHESS:P"   # Attacking pawn lands on e6
)

Parameters:

  • diff (Hash)

    Board state changes as keyword arguments. Keys should be square labels, values should be piece identifiers or nil.



66
67
68
69
70
# File 'lib/sashite/ggn/ruleset/source/destination/engine/transition.rb', line 66

def initialize(**diff)
  @diff = diff

  freeze
end

Instance Attribute Details

#diffHash<String, String|nil> (readonly)

Returns Board state changes after the move. Keys are square labels, values are piece identifiers or nil for empty squares.

Returns:

  • (Hash<String, String|nil>)

    Board state changes after the move. Keys are square labels, values are piece identifiers or nil for empty squares.



36
37
38
# File 'lib/sashite/ggn/ruleset/source/destination/engine/transition.rb', line 36

def diff
  @diff
end