Initial commit
[trapthecap.git] / doc / classes / Game.src / M000038.html
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6 <html>
7 <head>
8 <title>undo_move! (Game)</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" />
11 </head>
12 <body class="standalone-code">
13 <pre><span class="ruby-comment cmt"># File lib/libttc.rb, line 445</span>
14 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">undo_move!</span>
15 <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@history</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
16 <span class="ruby-comment cmt"># general case</span>
17 <span class="ruby-identifier">state_to_restore</span> = <span class="ruby-ivar">@history</span>[<span class="ruby-value">-2</span>]
18 <span class="ruby-ivar">@current_player</span> = <span class="ruby-ivar">@history</span>[<span class="ruby-value">-1</span>].<span class="ruby-identifier">player</span>
19 <span class="ruby-ivar">@pieces</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">piece</span><span class="ruby-operator">|</span>
20 <span class="ruby-identifier">copy_piece</span> = <span class="ruby-identifier">state_to_restore</span>.<span class="ruby-identifier">pieces_after_move</span>[<span class="ruby-identifier">name</span>]
21 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">position</span> = <span class="ruby-identifier">copy_piece</span>.<span class="ruby-identifier">position</span>
22 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">captured</span> = <span class="ruby-identifier">copy_piece</span>.<span class="ruby-identifier">captured</span>
23 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">contains</span> = []
24 <span class="ruby-identifier">copy_piece</span>.<span class="ruby-identifier">contains</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
25 <span class="ruby-comment cmt"># piece.capture(@pieces[p.name])</span>
26 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">contains</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@pieces</span>[<span class="ruby-identifier">p</span>.<span class="ruby-identifier">name</span>]
27 <span class="ruby-keyword kw">end</span>
28 <span class="ruby-keyword kw">end</span>
29 <span class="ruby-ivar">@history</span>.<span class="ruby-identifier">pop</span>
30 <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@history</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
31 <span class="ruby-comment cmt"># reset to start</span>
32 <span class="ruby-ivar">@current_player</span> = <span class="ruby-value str">'a'</span>
33 <span class="ruby-ivar">@pieces</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">piece</span><span class="ruby-operator">|</span>
34 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">position</span> = <span class="ruby-ivar">@board</span>.<span class="ruby-identifier">positions</span>[<span class="ruby-identifier">piece</span>.<span class="ruby-identifier">colour</span>]
35 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">captured</span> = <span class="ruby-keyword kw">false</span>
36 <span class="ruby-identifier">piece</span>.<span class="ruby-identifier">contains</span> = []
37 <span class="ruby-keyword kw">end</span>
38 <span class="ruby-ivar">@history</span>.<span class="ruby-identifier">pop</span>
39 <span class="ruby-keyword kw">end</span>
40 <span class="ruby-keyword kw">end</span></pre>
41 </body>
42 </html>