This commit is contained in:
Sarsoo 2022-05-05 22:04:25 +00:00
parent 881d265006
commit 057883f88f
6 changed files with 21 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
</nav>
<nav class="sidebar"><a class="sidebar-logo" href="../../draught/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div>
</a><h2 class="location"><a href="#">Module comp</a></h2><div class="sidebar-elems"><section><div class="block"><ul><li><a href="#structs">Structs</a></li></ul></div></section><div id="sidebar-vars" data-name="comp" data-ty="mod" data-relpath="./"></div><script defer src="./sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../draught/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Module <a href="../index.html">draught</a>::<wbr><a class="mod" href="#">comp</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../src/draught/comp/mod.rs.html#1-425">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>AI player logic</p>
<h1 class="fqn"><span class="in-band">Module <a href="../index.html">draught</a>::<wbr><a class="mod" href="#">comp</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../src/draught/comp/mod.rs.html#1-430">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>AI player logic</p>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.BoardNode.html" title="draught::comp::BoardNode struct">BoardNode</a></div><div class="item-right docblock-short"><p>For storing boards in the AI tree, stores board with score for comparisons</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Computer.html" title="draught::comp::Computer struct">Computer</a></div><div class="item-right docblock-short"><p>Root-level structure for managing the game as a collection of board states</p>

View File

@ -10,7 +10,7 @@
pub last_node_count: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a>,
pub perfect_chance: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.f64.html">f64</a>,
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Root-level structure for managing the game as a collection of board states</p>
</div></details><h2 id="fields" class="fields small-section-header">Fields<a href="#fields" class="anchor"></a></h2><span id="structfield.search_depth" class="structfield small-section-header"><a href="#structfield.search_depth" class="anchor field"></a><code>search_depth: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a></code></span><span id="structfield.team" class="structfield small-section-header"><a href="#structfield.team" class="anchor field"></a><code>team: <a class="enum" href="../board/enums/enum.Team.html" title="enum draught::board::enums::Team">Team</a></code></span><span id="structfield.last_node_count" class="structfield small-section-header"><a href="#structfield.last_node_count" class="anchor field"></a><code>last_node_count: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a></code></span><span id="structfield.perfect_chance" class="structfield small-section-header"><a href="#structfield.perfect_chance" class="anchor field"></a><code>perfect_chance: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.f64.html">f64</a></code></span><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#72-425">source</a></span><a href="#impl" class="anchor"></a><h3 class="code-header in-band">impl <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section></summary><div class="impl-items"><section id="method.new" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#73-80">source</a></span><a href="#method.new" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(search_depth: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a>, team: <a class="enum" href="../board/enums/enum.Team.html" title="enum draught::board::enums::Team">Team</a>, perfect_chance: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.f64.html">f64</a>) -&gt; <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h4></section><details class="rustdoc-toggle method-toggle" open><summary><section id="method.available_turns" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#83-136">source</a></span><a href="#method.available_turns" class="anchor"></a><h4 class="code-header">fn <a href="#method.available_turns" class="fnname">available_turns</a>(&amp;self, board: &amp;<a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="struct.Move.html" title="struct draught::comp::Move">Move</a>&gt;</h4></section></summary><div class="docblock"><p>Get vector of available moves for a given board</p>
</div></details><h2 id="fields" class="fields small-section-header">Fields<a href="#fields" class="anchor"></a></h2><span id="structfield.search_depth" class="structfield small-section-header"><a href="#structfield.search_depth" class="anchor field"></a><code>search_depth: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a></code></span><span id="structfield.team" class="structfield small-section-header"><a href="#structfield.team" class="anchor field"></a><code>team: <a class="enum" href="../board/enums/enum.Team.html" title="enum draught::board::enums::Team">Team</a></code></span><span id="structfield.last_node_count" class="structfield small-section-header"><a href="#structfield.last_node_count" class="anchor field"></a><code>last_node_count: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a></code></span><span id="structfield.perfect_chance" class="structfield small-section-header"><a href="#structfield.perfect_chance" class="anchor field"></a><code>perfect_chance: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.f64.html">f64</a></code></span><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#72-430">source</a></span><a href="#impl" class="anchor"></a><h3 class="code-header in-band">impl <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section></summary><div class="impl-items"><section id="method.new" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#73-80">source</a></span><a href="#method.new" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(search_depth: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.usize.html">usize</a>, team: <a class="enum" href="../board/enums/enum.Team.html" title="enum draught::board::enums::Team">Team</a>, perfect_chance: <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.f64.html">f64</a>) -&gt; <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h4></section><details class="rustdoc-toggle method-toggle" open><summary><section id="method.available_turns" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#83-136">source</a></span><a href="#method.available_turns" class="anchor"></a><h4 class="code-header">fn <a href="#method.available_turns" class="fnname">available_turns</a>(&amp;self, board: &amp;<a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="struct.Move.html" title="struct draught::comp::Move">Move</a>&gt;</h4></section></summary><div class="docblock"><p>Get vector of available moves for a given board</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.gen_tree" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#139-155">source</a></span><a href="#method.gen_tree" class="anchor"></a><h4 class="code-header">fn <a href="#method.gen_tree" class="fnname">gen_tree</a>(&amp;mut self, tree: &amp;mut Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, board: <a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>) -&gt; NodeId</h4></section></summary><div class="docblock"><p>Generate tree of boards to given search depth, return root node</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.propagate_scores" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#158-200">source</a></span><a href="#method.propagate_scores" class="anchor"></a><h4 class="code-header">fn <a href="#method.propagate_scores" class="fnname">propagate_scores</a>(tree: Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, root: NodeId) -&gt; Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;</h4></section></summary><div class="docblock"><p>Propagate scores up the tree employing MiniMax algorithm</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.best_score" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#203-215">source</a></span><a href="#method.best_score" class="anchor"></a><h4 class="code-header">fn <a href="#method.best_score" class="fnname">best_score</a>(board: &amp;<a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>, children_scores: <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.isize.html">isize</a>&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.isize.html">isize</a></h4></section></summary><div class="docblock"><p>Get best of given scores for given team</p>
@ -21,8 +21,8 @@ Used for leaf nodes ready for propagating up tree</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.expand_node" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#265-287">source</a></span><a href="#method.expand_node" class="anchor"></a><h4 class="code-header">fn <a href="#method.expand_node" class="fnname">expand_node</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;tree: &amp;mut Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;node: NodeId<br>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;NodeId&gt;</h4></section></summary><div class="docblock"><p>Insert all possible next boards as children of given board node</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.insert_boards" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#290-296">source</a></span><a href="#method.insert_boards" class="anchor"></a><h4 class="code-header">fn <a href="#method.insert_boards" class="fnname">insert_boards</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;tree: &amp;mut Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;boards: <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;<br>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;NodeId&gt;</h4></section></summary><div class="docblock"><p>Insert given boards into tree</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_move_boards" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#299-314">source</a></span><a href="#method.get_move_boards" class="anchor"></a><h4 class="code-header">fn <a href="#method.get_move_boards" class="fnname">get_move_boards</a>(&amp;self, board: &amp;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;</h4></section></summary><div class="docblock"><p>Get all possible next boards from given board</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_move" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#317-413">source</a></span><a href="#method.get_move" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.get_move" class="fnname">get_move</a>(&amp;mut self, brd: <a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.60.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>&gt;</h4></section></summary><div class="docblock"><p>Get a new board based on the given using MiniMax to make decisions </p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.random_choice" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#416-424">source</a></span><a href="#method.random_choice" class="anchor"></a><h4 class="code-header">fn <a href="#method.random_choice" class="fnname">random_choice</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;tree: &amp;Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;possible_moves: <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;NodeId&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut <a class="struct" href="https://rust-random.github.io/rand/rand/rngs/thread/struct.ThreadRng.html" title="struct rand::rngs::thread::ThreadRng">ThreadRng</a><br>) -&gt; <a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a></h4></section></summary><div class="docblock"><p>Get a random board from possible node IDs and associated tree</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_move" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#317-418">source</a></span><a href="#method.get_move" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.get_move" class="fnname">get_move</a>(&amp;mut self, brd: <a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.60.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a>&gt;</h4></section></summary><div class="docblock"><p>Get a new board based on the given using MiniMax to make decisions </p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.random_choice" class="method has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#421-429">source</a></span><a href="#method.random_choice" class="anchor"></a><h4 class="code-header">fn <a href="#method.random_choice" class="fnname">random_choice</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;tree: &amp;Arena&lt;<a class="struct" href="struct.BoardNode.html" title="struct draught::comp::BoardNode">BoardNode</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;possible_moves: <a class="struct" href="https://doc.rust-lang.org/1.60.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;NodeId&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut <a class="struct" href="https://rust-random.github.io/rand/rand/rngs/thread/struct.ThreadRng.html" title="struct rand::rngs::thread::ThreadRng">ThreadRng</a><br>) -&gt; <a class="struct" href="../board/struct.Board.html" title="struct draught::board::Board">Board</a></h4></section></summary><div class="docblock"><p>Get a random board from possible node IDs and associated tree</p>
</div></details></div></details><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#64">source</a></span><a href="#impl-Debug" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/draught/comp/mod.rs.html#64">source</a></span><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.60.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.60.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/1.60.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.60.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe" class="impl has-srclink"><a href="#impl-RefUnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section><section id="impl-Send" class="impl has-srclink"><a href="#impl-Send" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section><section id="impl-Sync" class="impl has-srclink"><a href="#impl-Sync" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section><section id="impl-Unpin" class="impl has-srclink"><a href="#impl-Unpin" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section><section id="impl-UnwindSafe" class="impl has-srclink"><a href="#impl-UnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Computer.html" title="struct draught::comp::Computer">Computer</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Any" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.60.0/src/core/any.rs.html#132-136">source</a></span><a href="#impl-Any" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.60.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.60.0/src/core/any.rs.html#133">source</a></span><a href="#method.type_id" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.60.0/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.60.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.60.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Borrow%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.60.0/src/core/borrow.rs.html#209-214">source</a></span><a href="#impl-Borrow%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.60.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/1.60.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.60.0/src/core/borrow.rs.html#211">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.60.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.60.0/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.60.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>

View File

@ -428,6 +428,11 @@
<span id="423">423</span>
<span id="424">424</span>
<span id="425">425</span>
<span id="426">426</span>
<span id="427">427</span>
<span id="428">428</span>
<span id="429">429</span>
<span id="430">430</span>
</pre><pre class="rust"><code><span class="doccomment">//! AI player logic</span>
<span class="kw">use</span> <span class="ident">indextree</span>::{<span class="ident">Arena</span>, <span class="ident">Node</span>, <span class="ident">NodeId</span>, <span class="ident">NodeEdge</span>};
@ -746,6 +751,9 @@
<span class="doccomment">/// Get a new board based on the given using MiniMax to make decisions </span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_move</span>(<span class="kw-2">&amp;mut</span> <span class="self">self</span>, <span class="ident">brd</span>: <span class="ident">Board</span>) -&gt; <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Board</span><span class="op">&gt;</span> {
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">unused_assignments</span>)]</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">ret</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Board</span><span class="op">&gt;</span> <span class="op">=</span> <span class="prelude-val">None</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tree</span> <span class="op">=</span> <span class="ident">Arena::new</span>();
<span class="comment">// generate a tree to given depth for the given board</span>
@ -816,21 +824,21 @@
<span class="kw">if</span> <span class="ident">possible_perfect_moves</span>.<span class="ident">len</span>() <span class="op">==</span> <span class="number">0</span> {
<span class="macro">log_error!</span>(<span class="string">&quot;No next moves matched the score of the root node, picking randomly instead&quot;</span>);
<span class="prelude-val">Some</span>(<span class="ident">Computer::random_choice</span>(<span class="kw-2">&amp;</span><span class="ident">tree</span>, <span class="ident">possible_moves</span>, <span class="kw-2">&amp;mut</span> <span class="ident">rng</span>))
<span class="ident">ret</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">Computer::random_choice</span>(<span class="kw-2">&amp;</span><span class="ident">tree</span>, <span class="ident">possible_moves</span>, <span class="kw-2">&amp;mut</span> <span class="ident">rng</span>));
}
<span class="comment">// only one possible move, use that</span>
<span class="kw">else</span> <span class="kw">if</span> <span class="ident">possible_perfect_moves</span>.<span class="ident">len</span>() <span class="op">==</span> <span class="number">1</span> {
<span class="prelude-val">Some</span>(<span class="ident">possible_perfect_moves</span>[<span class="number">0</span>].<span class="ident">board</span>.<span class="ident">clone</span>())
<span class="ident">ret</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">possible_perfect_moves</span>[<span class="number">0</span>].<span class="ident">board</span>.<span class="ident">clone</span>());
}
<span class="comment">// more than one possible perfect move to make, choose one randomly</span>
<span class="kw">else</span> {
<span class="prelude-val">Some</span>(
<span class="ident">ret</span> <span class="op">=</span> <span class="prelude-val">Some</span>(
<span class="ident">possible_perfect_moves</span>
.<span class="ident">choose</span>(<span class="kw-2">&amp;mut</span> <span class="ident">rng</span>) <span class="comment">// random choice</span>
.<span class="ident">unwrap</span>() <span class="comment">// unwrap Option</span>
.<span class="ident">board</span>
.<span class="ident">clone</span>()
)
);
}
}
<span class="comment">// get random move</span>
@ -838,8 +846,10 @@
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;debug_logs&quot;</span>)]</span>
<span class="macro">log!</span>(<span class="string">&quot;Making random move&quot;</span>);
<span class="prelude-val">Some</span>(<span class="ident">Computer::random_choice</span>(<span class="kw-2">&amp;</span><span class="ident">tree</span>, <span class="ident">possible_moves</span>, <span class="kw-2">&amp;mut</span> <span class="ident">rng</span>))
<span class="ident">ret</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">Computer::random_choice</span>(<span class="kw-2">&amp;</span><span class="ident">tree</span>, <span class="ident">possible_moves</span>, <span class="kw-2">&amp;mut</span> <span class="ident">rng</span>));
}
<span class="ident">ret</span>
}
<span class="doccomment">/// Get a random board from possible node IDs and associated tree</span>