Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just for fun, keep two numbers, starting as zeros, one for <code>X</code>, one for <code>O</code>. Update them by <code>or</code>ing with the moves. To check for a winner, first <code>and</code>, then <code>xor</code> with the mask.</p> <pre><code>277 &amp; 273 ^ 273 0 ==&gt; we have a winner. 276 &amp; 273 ^ 273 1 ==&gt; not. </code></pre> <p>277 == parseInt("100010101",2)<br /> 273 == parseInt("100010001",2)<br /> 276 == parseInt("100010100",2)</p> <p>For more fun, here's an example that plays <code>O</code> in your favorite JavaScript console:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-type" content="text/html;charset=UTF-8"&gt; &lt;/head&gt; &lt;body&gt; &lt;script&gt; var x = 0, o = 0, count = 0, w = 0 ws = [0007,0070,0700,0111,0222,0444,0124,0421] function t1(v){ var w1 = 0 for (var i in ws) w1 |= !(v &amp; ws[i] ^ ws[i]) return w1 } function t(i){ var ot = count % 2, m = 1 &lt;&lt; (9 - i), bd = x | o if (!ot &amp;&amp; (i &gt; 9 || i &lt; 1 || i != Math.floor(i))) return "Out of bounds." else if (m &amp; bd) return "Position taken." if (ot){ var n1 = 0, a1 = -2 while (bd &amp; (1 &lt;&lt; n1)) n1++ var n = n1 while (n1 &lt; 9){ var m1 = 1 &lt;&lt; n1 if (!(bd &amp; m1)){ var bt = -mx(x,o | m1,count + 1) if (bt &gt; a1){ a1 = bt n = n1 } } n1++ } w = t1(o |= 1 &lt;&lt; n) } else w = t1(x |= m) var b = "\n", p = 0400 while (p &gt; 0){ if (p &amp; x) b += "X" else if (p &amp; o) b += "O" else b += "." if (p &amp; 0110) b += "\n" p &gt;&gt;= 1 } if (w) b += "\n\n" + (ot ? "O" : "X") + " wins!" else if (!(bd ^ 0777)) b += "\n\nDraw." if (!ot){ console.log(b + '\n\n"""') count++ console.log(t(-1)) count++ } else return b + "\n" return '"' } function mx(x1,o1,c1){ var ot1 = c1 % 2, w1 = ot1 ? t1(x1) : t1 (o1), b1 = x1 | o1, p = 0400 if (w1) return -1 if (!(b1 ^ 0777)) return 0 var a = -2 while (p &gt; 0){ if (!(b1 &amp; p)) a = Math.max(a,-mx(ot1 ? x1 : x1 | p,ot1 ? o1 | p : o1,c1 + 1)) p &gt;&gt;= 1 } return a } console.log(' Plays O!' + '\nTo play, type t(MOVE); MOVE is from 1-9') &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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