def initialize(spokes, spoke_length, arc_length)
@positions = Hash.new
@centre = Position.new('ac' + spoke_length.to_s, false, false)
@positions['ac' + spoke_length.to_s] = centre
a1_corner = nil
end_of_previous_arc = nil
(?a...(?a + spokes)).each do |arc_code|
arc = arc_code.chr
base = Position.new(arc, false, true)
this_arc = Array.new
(1..arc_length).each do |arc_position|
position_name = arc + arc_position.to_s
arc_place = Position.new(position_name, arc_position == 4, false)
arc_place.neighbours = []
@positions[position_name] = arc_place
this_arc << arc_place
a1_corner = a1_corner || arc_place
end
(0...arc_length).each do |arc_position|
if arc_position > 0
this_arc[arc_position].neighbours << this_arc[arc_position - 1]
end
if arc_position < (arc_length - 1)
this_arc[arc_position].neighbours << this_arc[arc_position + 1]
end
end
this_spoke = Array.new
(1..(spoke_length - 1)).each do |spoke_position|
position_name = arc + "c" + spoke_position.to_s
spoke_place = Position.new(position_name, spoke_position == 3, false)
spoke_place.neighbours = []
@positions[position_name] = spoke_place
this_spoke << spoke_place
end
(0...(spoke_length - 1)).each do |spoke_position|
if spoke_position > 0
this_spoke[spoke_position].neighbours << this_spoke[spoke_position - 1]
end
if spoke_position < spoke_length - 2
this_spoke[spoke_position].neighbours << this_spoke[spoke_position + 1]
end
end
this_arc[0].neighbours << this_spoke[0]
this_spoke[0].neighbours << this_arc[0]
this_spoke[-1].neighbours << @centre
@centre.neighbours << this_spoke[-1]
base = Position.new(arc, false, true)
@positions[arc] = base
base.neighbours << this_arc[0]
this_arc[0].neighbours << base
if end_of_previous_arc
end_of_previous_arc.neighbours << this_arc[0]
this_arc[0].neighbours << end_of_previous_arc
end
end_of_previous_arc = this_arc[-1]
end
a1_corner.neighbours << end_of_previous_arc
end_of_previous_arc.neighbours << a1_corner
cache_valid_moves
end