Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using precomputed lookup tables, it's possible to detect whether one player has five in a row in about 18 instructions. The following routine takes as input all stones of one player packed into a 64-bit int:</p> <pre><code>inline quadrant_t quadrant(uint64_t state, int q) { assert(0&lt;=q &amp;&amp; q&lt;4); return (state&gt;&gt;16*q)&amp;0xffff; } // Determine if one side has 5 in a row inline bool won(side_t side) { /* To test whether a position is a win for a given player, we note that * there are 3*4*2+4+4 = 32 different ways of getting 5 in a row on the * board. Thus, a 64-bit int can store a 2 bit field for each possible * method. We then precompute a lookup table mapping each quadrant state * to the number of win-possibilities it contributes to. 28 of the ways * of winning occur between two boards, and 4 occur between 4, so a sum * and a few bit twiddling checks are sufficient to test whether 5 in a * row exists. See helper for the precomputation code. */ uint64_t c = win_contributions[0][quadrant(side,0)] + win_contributions[1][quadrant(side,1)] + win_contributions[2][quadrant(side,2)] + win_contributions[3][quadrant(side,3)]; return c&amp;(c&gt;&gt;1)&amp;0x55 // The first four ways of winning require contributions from three quadrants || c&amp;(0xaaaaaaaaaaaaaaaa&lt;&lt;8); // The remaining 28 ways require contributions from only two } </code></pre> <p>The full source code is here:</p> <p><a href="https://github.com/girving/pentago/blob/9c9dedbb8dd3a5cf8dd778d28f351419126bbb7c/engine.cpp#L94" rel="nofollow">https://github.com/girving/pentago/blob/9c9dedbb8dd3a5cf8dd778d28f351419126bbb7c/engine.cpp#L94</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload