Initial commit
[trapthecap.git] / doc / classes / Population.src / .svn / text-base / M000016.html.svn-base
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>tournament_select_one (Population)</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 src/selection.rb, line 19</span>
14 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tournament_select_one</span>(<span class="ruby-identifier">winner_success_chance</span> = <span class="ruby-value">0</span><span class="ruby-value">.8</span>, <span class="ruby-identifier">max_game_length</span>= <span class="ruby-value">1000</span>, <span class="ruby-identifier">verbose</span> = <span class="ruby-keyword kw">false</span>)
15 <span class="ruby-identifier">player_count</span> = <span class="ruby-identifier">rand</span>(<span class="ruby-value">5</span>) <span class="ruby-operator">+</span> <span class="ruby-value">2</span>
16 <span class="ruby-identifier">pool_size</span> = <span class="ruby-ivar">@individuals</span>.<span class="ruby-identifier">length</span>
17 <span class="ruby-identifier">players</span> = []
18 <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">player_count</span>) { <span class="ruby-identifier">players</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@individuals</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-identifier">pool_size</span>)].<span class="ruby-identifier">to_potential_player</span> }
19 <span class="ruby-identifier">game</span> = <span class="ruby-constant">GameHandler</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">players</span>, <span class="ruby-identifier">max_game_length</span>, <span class="ruby-keyword kw">false</span>, <span class="ruby-keyword kw">false</span>)
20 <span class="ruby-identifier">winner</span>, <span class="ruby-identifier">length</span> = <span class="ruby-identifier">game</span>.<span class="ruby-identifier">play</span>
21 <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Winner = #{winner} in #{length} moves. Game had #{player_count} players&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">verbose</span>
22 <span class="ruby-comment cmt"># If the game was a draw, or the winner is unlucky, pick a parent at random</span>
23 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">winner</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:draw</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">winner_success_chance</span>
24 <span class="ruby-identifier">successful_player</span> = <span class="ruby-identifier">players</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-identifier">player_count</span>)]
25 <span class="ruby-keyword kw">else</span>
26 <span class="ruby-identifier">successful_player</span> = <span class="ruby-identifier">winner</span>
27 <span class="ruby-keyword kw">end</span>
28 <span class="ruby-identifier">successful_player</span>
29 <span class="ruby-keyword kw">end</span></pre>
30 </body>
31 </html>