1 <?xml version=
"1.0" encoding=
"iso-8859-1"?>
3 PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
8 <title>new (Board)
</title>
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1" />
10 <link rel=
"stylesheet" href=
"../.././rdoc-style.css" type=
"text/css" media=
"screen" />
12 <body class=
"standalone-code">
13 <pre><span class=
"ruby-comment cmt"># File lib/libttc.rb, line
94</span>
14 <span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">initialize
</span>(
<span class=
"ruby-identifier">spokes
</span>,
<span class=
"ruby-identifier">spoke_length
</span>,
<span class=
"ruby-identifier">arc_length
</span>)
15 <span class=
"ruby-comment cmt"># A hash of all positions, indexed by position names
</span>
16 <span class=
"ruby-ivar">@positions
</span> =
<span class=
"ruby-constant">Hash
</span>.
<span class=
"ruby-identifier">new
</span>
17 <span class=
"ruby-ivar">@centre
</span> =
<span class=
"ruby-constant">Position
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-value str">'ac'
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-identifier">spoke_length
</span>.
<span class=
"ruby-identifier">to_s
</span>,
<span class=
"ruby-keyword kw">false
</span>,
<span class=
"ruby-keyword kw">false
</span>)
18 <span class=
"ruby-ivar">@positions
</span>[
<span class=
"ruby-value str">'ac'
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-identifier">spoke_length
</span>.
<span class=
"ruby-identifier">to_s
</span>] =
<span class=
"ruby-identifier">centre
</span>
19 <span class=
"ruby-identifier">a1_corner
</span> =
<span class=
"ruby-keyword kw">nil
</span>
20 <span class=
"ruby-identifier">end_of_previous_arc
</span> =
<span class=
"ruby-keyword kw">nil
</span>
22 <span class=
"ruby-comment cmt"># Do each arc-spoke-base set
</span>
23 (
<span class=
"ruby-value">?a
</span><span class=
"ruby-operator">...
</span>(
<span class=
"ruby-value">?a
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-identifier">spokes
</span>)).
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">arc_code
</span><span class=
"ruby-operator">|
</span>
24 <span class=
"ruby-identifier">arc
</span> =
<span class=
"ruby-identifier">arc_code
</span>.
<span class=
"ruby-identifier">chr
</span>
25 <span class=
"ruby-identifier">base
</span> =
<span class=
"ruby-constant">Position
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-identifier">arc
</span>,
<span class=
"ruby-keyword kw">false
</span>,
<span class=
"ruby-keyword kw">true
</span>)
26 <span class=
"ruby-identifier">this_arc
</span> =
<span class=
"ruby-constant">Array
</span>.
<span class=
"ruby-identifier">new
</span>
28 <span class=
"ruby-comment cmt"># build the arc
</span>
29 (
<span class=
"ruby-value">1</span><span class=
"ruby-operator">..
</span><span class=
"ruby-identifier">arc_length
</span>).
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">arc_position
</span><span class=
"ruby-operator">|
</span>
30 <span class=
"ruby-identifier">position_name
</span> =
<span class=
"ruby-identifier">arc
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-identifier">arc_position
</span>.
<span class=
"ruby-identifier">to_s
</span>
31 <span class=
"ruby-identifier">arc_place
</span> =
<span class=
"ruby-constant">Position
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-identifier">position_name
</span>,
<span class=
"ruby-identifier">arc_position
</span> <span class=
"ruby-operator">==
</span> <span class=
"ruby-value">4</span>,
<span class=
"ruby-keyword kw">false
</span>)
32 <span class=
"ruby-identifier">arc_place
</span>.
<span class=
"ruby-identifier">neighbours
</span> = []
33 <span class=
"ruby-ivar">@positions
</span>[
<span class=
"ruby-identifier">position_name
</span>] =
<span class=
"ruby-identifier">arc_place
</span>
34 <span class=
"ruby-identifier">this_arc
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">arc_place
</span>
35 <span class=
"ruby-identifier">a1_corner
</span> =
<span class=
"ruby-identifier">a1_corner
</span> <span class=
"ruby-operator">||
</span> <span class=
"ruby-identifier">arc_place
</span>
36 <span class=
"ruby-keyword kw">end
</span>
37 (
<span class=
"ruby-value">0</span><span class=
"ruby-operator">...
</span><span class=
"ruby-identifier">arc_length
</span>).
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">arc_position
</span><span class=
"ruby-operator">|
</span>
38 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">arc_position
</span> <span class=
"ruby-operator">></span> <span class=
"ruby-value">0</span>
39 <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-identifier">arc_position
</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-identifier">arc_position
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">1</span>]
40 <span class=
"ruby-keyword kw">end
</span>
41 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">arc_position
</span> <span class=
"ruby-operator"><</span> (
<span class=
"ruby-identifier">arc_length
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">1</span>)
42 <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-identifier">arc_position
</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-identifier">arc_position
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-value">1</span>]
43 <span class=
"ruby-keyword kw">end
</span>
44 <span class=
"ruby-keyword kw">end
</span>
46 <span class=
"ruby-comment cmt"># build the spoke
</span>
47 <span class=
"ruby-identifier">this_spoke
</span> =
<span class=
"ruby-constant">Array
</span>.
<span class=
"ruby-identifier">new
</span>
48 (
<span class=
"ruby-value">1</span><span class=
"ruby-operator">..
</span>(
<span class=
"ruby-identifier">spoke_length
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">1</span>)).
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">spoke_position
</span><span class=
"ruby-operator">|
</span>
49 <span class=
"ruby-identifier">position_name
</span> =
<span class=
"ruby-identifier">arc
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-value str">"c
"</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-identifier">spoke_position
</span>.
<span class=
"ruby-identifier">to_s
</span>
50 <span class=
"ruby-identifier">spoke_place
</span> =
<span class=
"ruby-constant">Position
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-identifier">position_name
</span>,
<span class=
"ruby-identifier">spoke_position
</span> <span class=
"ruby-operator">==
</span> <span class=
"ruby-value">3</span>,
<span class=
"ruby-keyword kw">false
</span>)
51 <span class=
"ruby-identifier">spoke_place
</span>.
<span class=
"ruby-identifier">neighbours
</span> = []
52 <span class=
"ruby-ivar">@positions
</span>[
<span class=
"ruby-identifier">position_name
</span>] =
<span class=
"ruby-identifier">spoke_place
</span>
53 <span class=
"ruby-identifier">this_spoke
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">spoke_place
</span>
54 <span class=
"ruby-keyword kw">end
</span>
55 (
<span class=
"ruby-value">0</span><span class=
"ruby-operator">...
</span>(
<span class=
"ruby-identifier">spoke_length
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">1</span>)).
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">spoke_position
</span><span class=
"ruby-operator">|
</span>
56 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">spoke_position
</span> <span class=
"ruby-operator">></span> <span class=
"ruby-value">0</span>
57 <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-identifier">spoke_position
</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-identifier">spoke_position
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">1</span>]
58 <span class=
"ruby-keyword kw">end
</span>
59 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">spoke_position
</span> <span class=
"ruby-operator"><</span> <span class=
"ruby-identifier">spoke_length
</span> <span class=
"ruby-operator">-
</span> <span class=
"ruby-value">2</span>
60 <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-identifier">spoke_position
</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-identifier">spoke_position
</span> <span class=
"ruby-operator">+
</span> <span class=
"ruby-value">1</span>]
61 <span class=
"ruby-keyword kw">end
</span>
62 <span class=
"ruby-keyword kw">end
</span>
64 <span class=
"ruby-comment cmt"># tie the spoke and arc together,
</span>
65 <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-value">0</span>]
66 <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-value">0</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>]
68 <span class=
"ruby-comment cmt"># tie the spoke to the centre, and
</span>
69 <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-value">-
1</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-ivar">@centre
</span>
70 <span class=
"ruby-ivar">@centre
</span>.
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_spoke
</span>[
<span class=
"ruby-value">-
1</span>]
72 <span class=
"ruby-comment cmt"># tie the base to the arc
</span>
73 <span class=
"ruby-identifier">base
</span> =
<span class=
"ruby-constant">Position
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-identifier">arc
</span>,
<span class=
"ruby-keyword kw">false
</span>,
<span class=
"ruby-keyword kw">true
</span>)
74 <span class=
"ruby-ivar">@positions
</span>[
<span class=
"ruby-identifier">arc
</span>] =
<span class=
"ruby-identifier">base
</span>
75 <span class=
"ruby-identifier">base
</span>.
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>]
76 <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">base
</span>
78 <span class=
"ruby-comment cmt"># record the ends of the arc for tying to adjacent arcs
</span>
79 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">end_of_previous_arc
</span>
80 <span class=
"ruby-identifier">end_of_previous_arc
</span>.
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>]
81 <span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">0</span>].
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">end_of_previous_arc
</span>
82 <span class=
"ruby-keyword kw">end
</span>
83 <span class=
"ruby-identifier">end_of_previous_arc
</span> =
<span class=
"ruby-identifier">this_arc
</span>[
<span class=
"ruby-value">-
1</span>]
85 <span class=
"ruby-keyword kw">end
</span> <span class=
"ruby-comment cmt"># arc
</span>
87 <span class=
"ruby-comment cmt"># tie both ends of the rim together
</span>
88 <span class=
"ruby-identifier">a1_corner
</span>.
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">end_of_previous_arc
</span>
89 <span class=
"ruby-identifier">end_of_previous_arc
</span>.
<span class=
"ruby-identifier">neighbours
</span> <span class=
"ruby-operator"><<</span> <span class=
"ruby-identifier">a1_corner
</span>
91 <span class=
"ruby-identifier">cache_valid_moves
</span>
93 <span class=
"ruby-keyword kw">end
</span></pre>