Class: SGF::Model::Node
Constant Summary
Constants included
from Constants
Constants::BLACK, Constants::DEFAULT_BOARD_SIZE, Constants::DEFAULT_KOMI, Constants::NODE_MOVE, Constants::NODE_PASS, Constants::NODE_SETUP, Constants::POSITIONS, Constants::WEIQI, Constants::WHITE
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from SGFHelper
#move_to_sgf, #to_label, #to_position, #to_position_array, #xy_to_sgf_pos
Constructor Details
#initialize(parent = nil) ⇒ Node
Returns a new instance of Node.
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/sgf/model/node.rb', line 11
def initialize parent = nil
@parent = parent
@node_type = NODE_SETUP
@labels = []
@whose_turn = BLACK
@trunk = true
if parent
@trunk = parent.trunk?
@parent.children << self
end
end
|
Instance Attribute Details
#black_moves ⇒ Object
Returns the value of attribute black_moves.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def black_moves
@black_moves
end
|
#children ⇒ Object
Returns the value of attribute children.
8
9
10
|
# File 'lib/sgf/model/node.rb', line 8
def children
@children
end
|
#color ⇒ Object
Returns the value of attribute color.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def color
@color
end
|
Returns the value of attribute comment.
9
10
11
|
# File 'lib/sgf/model/node.rb', line 9
def
@comment
end
|
#labels ⇒ Object
Returns the value of attribute labels.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def labels
@labels
end
|
#move ⇒ Object
Returns the value of attribute move.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def move
@move
end
|
#node_type ⇒ Object
Returns the value of attribute node_type.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def node_type
@node_type
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/sgf/model/node.rb', line 8
def parent
@parent
end
|
#white_moves ⇒ Object
Returns the value of attribute white_moves.
7
8
9
|
# File 'lib/sgf/model/node.rb', line 7
def white_moves
@white_moves
end
|
#whose_turn ⇒ Object
Returns the value of attribute whose_turn.
9
10
11
|
# File 'lib/sgf/model/node.rb', line 9
def whose_turn
@whose_turn
end
|
Instance Method Details
#child ⇒ Object
52
53
54
|
# File 'lib/sgf/model/node.rb', line 52
def child
@children.first
end
|
#clear_moves ⇒ Object
44
45
46
|
# File 'lib/sgf/model/node.rb', line 44
def clear_moves
@white_moves ||= []
end
|
#last? ⇒ Boolean
64
65
66
|
# File 'lib/sgf/model/node.rb', line 64
def last?
@children.nil? or @children.empty?
end
|
#misc_properties ⇒ Object
28
29
30
|
# File 'lib/sgf/model/node.rb', line 28
def misc_properties
@misc_properties ||= {}
end
|
#move_no ⇒ Object
23
24
25
26
|
# File 'lib/sgf/model/node.rb', line 23
def move_no
parent_move_no = parent.nil? ? 0 : parent.move_no
self.node_type == NODE_MOVE ? parent_move_no + 1 : parent_move_no
end
|
#root? ⇒ Boolean
56
57
58
|
# File 'lib/sgf/model/node.rb', line 56
def root?
@parent.nil?
end
|
#sgf_label(input) ⇒ Object
99
100
101
|
# File 'lib/sgf/model/node.rb', line 99
def sgf_label input
@labels << to_label(input)
end
|
#sgf_play_black(input) ⇒ Object
89
90
91
92
|
# File 'lib/sgf/model/node.rb', line 89
def sgf_play_black input
@color = BLACK
set_move input
end
|
#sgf_play_white(input) ⇒ Object
94
95
96
97
|
# File 'lib/sgf/model/node.rb', line 94
def sgf_play_white input
@color = WHITE
set_move input
end
|
#sgf_setup_black(input) ⇒ Object
77
78
79
|
# File 'lib/sgf/model/node.rb', line 77
def sgf_setup_black input
to_position_array(input).each {|position| self.black_moves << position}
end
|
#sgf_setup_clear(input) ⇒ Object
85
86
87
|
# File 'lib/sgf/model/node.rb', line 85
def sgf_setup_clear input
to_position_array(input).each {|position| self.clear_moves << position}
end
|
#sgf_setup_white(input) ⇒ Object
81
82
83
|
# File 'lib/sgf/model/node.rb', line 81
def sgf_setup_white input
to_position_array(input).each {|position| self.white_moves << position}
end
|
#trunk? ⇒ Boolean
60
61
62
|
# File 'lib/sgf/model/node.rb', line 60
def trunk?
@trunk
end
|
#variation_root=(value) ⇒ Object
68
69
70
71
|
# File 'lib/sgf/model/node.rb', line 68
def variation_root= value
@variation_root = value
@trunk = false if value
end
|
#variation_root? ⇒ Boolean
73
74
75
|
# File 'lib/sgf/model/node.rb', line 73
def variation_root?
@variation_root
end
|