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>to_move (String)
</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
513</span>
14 <span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">to_move
</span>(
<span class=
"ruby-identifier">game
</span>)
15 <span class=
"ruby-identifier">move_elements
</span> =
<span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">downcase
</span>.
<span class=
"ruby-identifier">split
</span>
16 <span class=
"ruby-identifier">piece_name
</span> =
<span class=
"ruby-identifier">move_elements
</span>[
<span class=
"ruby-value">0</span>]
17 <span class=
"ruby-identifier">destination_name
</span> =
<span class=
"ruby-identifier">move_elements
</span>[
<span class=
"ruby-value">-
1</span>]
18 <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">destination_name
</span>.
<span class=
"ruby-identifier">length
</span> <span class=
"ruby-operator">></span> <span class=
"ruby-value">2</span> <span class=
"ruby-keyword kw">and
</span>
19 <span class=
"ruby-identifier">destination_name
</span>[
<span class=
"ruby-value">-
2</span>,
<span class=
"ruby-value">2</span>]
<span class=
"ruby-operator">==
</span> <span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">board
</span>.
<span class=
"ruby-identifier">centre
</span>.
<span class=
"ruby-identifier">place
</span>[
<span class=
"ruby-value">-
2</span>,
<span class=
"ruby-value">2</span>]
20 <span class=
"ruby-identifier">destination_name
</span> =
<span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">board
</span>.
<span class=
"ruby-identifier">centre
</span>.
<span class=
"ruby-identifier">place
</span>
21 <span class=
"ruby-keyword kw">end
</span>
22 <span class=
"ruby-identifier">raise
</span>(
<span class=
"ruby-constant">InvalidMoveError
</span>,
<span class=
"ruby-value str">"Invalid piece in move read
"</span>)
<span class=
"ruby-keyword kw">unless
</span> <span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">pieces
</span>.
<span class=
"ruby-identifier">has_key?
</span>(
<span class=
"ruby-identifier">piece_name
</span>)
23 <span class=
"ruby-identifier">raise
</span>(
<span class=
"ruby-constant">InvalidMoveError
</span>,
<span class=
"ruby-value str">"Invalid destination in move read
"</span>)
<span class=
"ruby-keyword kw">unless
</span> <span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">board
</span>.
<span class=
"ruby-identifier">positions
</span>.
<span class=
"ruby-identifier">has_key?
</span>(
<span class=
"ruby-identifier">destination_name
</span>)
24 <span class=
"ruby-comment cmt"># Deal with the synonyms for the centre position
</span>
25 <span class=
"ruby-identifier">via_base
</span> = (
<span class=
"ruby-identifier">destination_name
</span>.
<span class=
"ruby-identifier">length
</span> <span class=
"ruby-operator">==
</span> <span class=
"ruby-value">1</span> <span class=
"ruby-keyword kw">or
</span> <span class=
"ruby-identifier">move_elements
</span>.
<span class=
"ruby-identifier">length
</span> <span class=
"ruby-operator">></span> <span class=
"ruby-value">2</span>)
26 <span class=
"ruby-constant">Move
</span>.
<span class=
"ruby-identifier">new
</span>(
<span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">pieces
</span>[
<span class=
"ruby-identifier">piece_name
</span>],
<span class=
"ruby-identifier">game
</span>.
<span class=
"ruby-identifier">board
</span>.
<span class=
"ruby-identifier">positions
</span>[
<span class=
"ruby-identifier">destination_name
</span>],
<span class=
"ruby-identifier">via_base
</span>)
27 <span class=
"ruby-keyword kw">end
</span></pre>