Class: PGN::FEN

Inherits:
Object
  • Object
show all
Defined in:
lib/pgn/fen.rb

Overview

FEN is responsible for translating between strings in FEN notation and an internal representation of the board.

Constant Summary collapse

INITIAL =

The FEN string representing the starting position in chess

'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fen_string = nil) ⇒ FEN

Returns a new instance of FEN.

Parameters:

  • fen_string (String) (defaults to: nil)

    a string in Forsyth-Edwards Notation



67
68
69
70
71
72
73
74
75
76
# File 'lib/pgn/fen.rb', line 67

def initialize(fen_string = nil)
  return unless fen_string

  self.board_string,
    self.active,
    self.castling,
    self.en_passant,
    self.halfmove,
    self.fullmove = fen_string.split
end

Instance Attribute Details

#active'w', 't'

Returns the current player.

Returns:

  • ('w', 't')

    the current player



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

#boardPGN::Board

Returns a Board object for the current board state.

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

#castlingObject

castling and en_passant have custom writers below (normalize nil/empty to '-'), so expose readers here and define the writers explicitly to avoid redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

#en_passantObject

castling and en_passant have custom writers below (normalize nil/empty to '-'), so expose readers here and define the writers explicitly to avoid redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

#fullmoveString

Note:

The number of full moves. This is incremented after black plays.

Returns the fullmove counter.

Returns:

  • (String)

    the fullmove counter



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

#halfmoveString

Note:

This is the number of halfmoves since the last pawn advance or capture

Returns the halfmove clock.

Returns:

  • (String)

    the halfmove clock



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pgn/fen.rb', line 37

class FEN
  # The FEN string representing the starting position in chess
  #
  INITIAL = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'.freeze

  attr_accessor :board, :active, :halfmove, :fullmove
  # `castling` and `en_passant` have custom writers below (normalize nil/empty
  # to '-'), so expose readers here and define the writers explicitly to avoid
  # redefining the accessors generated by attr_accessor (Lint/DuplicateMethods).
  attr_reader :castling, :en_passant

  # @return [PGN::FEN] a {PGN::FEN} object representing the starting
  #   position
  #
  def self.start
    PGN::FEN.new(INITIAL)
  end

  # @return [PGN::FEN] a {PGN::FEN} object with the given attributes
  #
  def self.from_attributes(attrs)
    fen = PGN::FEN.new
    attrs.each do |key, val|
      fen.send("#{key}=", val)
    end
    fen
  end

  # @param fen_string [String] a string in Forsyth-Edwards Notation
  #
  def initialize(fen_string = nil)
    return unless fen_string

    self.board_string,
      self.active,
      self.castling,
      self.en_passant,
      self.halfmove,
      self.fullmove = fen_string.split
  end

  def en_passant=(val)
    @en_passant = val.nil? ? '-' : val
  end

  def castling=(val)
    @castling = val.nil? || val.empty? ? '-' : val
  end

  # @param board_fen [String] the fen representation of the board
  # @example
  #   fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string=(board_fen)
    squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                       .split('/')
                       .map(&:chars)
                       .map { |row| row.map { |e| e == '_' ? nil : e } }
                       .reverse
                       .transpose
    self.board = PGN::Board.new(squares)
  end

  # @return [String] the fen representation of the board
  # @example
  #   PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  #
  def board_string
    board.fen_board_string
  end

  # @return [PGN::Position] a {PGN::Position} representing the current
  #   position
  #
  def to_position
    player     = active == 'w' ? :white : :black
    castling   = self.castling.chars - ['-']
    en_passant = nil if self.en_passant == '-'

    PGN::Position.new(
      board,
      player,
      castling,
      en_passant,
      halfmove.to_i,
      fullmove.to_i
    )
  end

  # @return [String] the FEN string
  # @example
  #   PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
  #
  def to_s
    [
      board_string,
      active,
      castling,
      en_passant,
      halfmove,
      fullmove
    ].join(' ')
  end

  def inspect
    to_s
  end
end

Class Method Details

.from_attributes(attrs) ⇒ PGN::FEN

Returns a PGN::FEN object with the given attributes.

Returns:



57
58
59
60
61
62
63
# File 'lib/pgn/fen.rb', line 57

def self.from_attributes(attrs)
  fen = PGN::FEN.new
  attrs.each do |key, val|
    fen.send("#{key}=", val)
  end
  fen
end

.startPGN::FEN

Returns a PGN::FEN object representing the starting position.

Returns:



51
52
53
# File 'lib/pgn/fen.rb', line 51

def self.start
  PGN::FEN.new(INITIAL)
end

Instance Method Details

#board_stringString

Returns the fen representation of the board.

Examples:

PGN::FEN.start.board_string #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"

Returns:

  • (String)

    the fen representation of the board



104
105
106
# File 'lib/pgn/fen.rb', line 104

def board_string
  board.fen_board_string
end

#board_string=(board_fen) ⇒ Object

Examples:

fen.board_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"

Parameters:

  • board_fen (String)

    the fen representation of the board



90
91
92
93
94
95
96
97
98
# File 'lib/pgn/fen.rb', line 90

def board_string=(board_fen)
  squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                     .split('/')
                     .map(&:chars)
                     .map { |row| row.map { |e| e == '_' ? nil : e } }
                     .reverse
                     .transpose
  self.board = PGN::Board.new(squares)
end

#inspectObject



141
142
143
# File 'lib/pgn/fen.rb', line 141

def inspect
  to_s
end

#to_positionPGN::Position

Returns a Position representing the current position.

Returns:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/pgn/fen.rb', line 111

def to_position
  player     = active == 'w' ? :white : :black
  castling   = self.castling.chars - ['-']
  en_passant = nil if self.en_passant == '-'

  PGN::Position.new(
    board,
    player,
    castling,
    en_passant,
    halfmove.to_i,
    fullmove.to_i
  )
end

#to_sString

Returns the FEN string.

Examples:

PGN::FEN.start.to_s #=> "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"

Returns:

  • (String)

    the FEN string



130
131
132
133
134
135
136
137
138
139
# File 'lib/pgn/fen.rb', line 130

def to_s
  [
    board_string,
    active,
    castling,
    en_passant,
    halfmove,
    fullmove
  ].join(' ')
end