--> --> --> --> --> Wiki Game solver :: Projects :: TheOrangeOne

Wiki Game solver

Simple script to win the Wiki Game

3 minutes


The Wiki Game is an online game where you attempt to navigate through Wikipedia from a start page to a goal page using as few other pages as possible.

Not long after I was shown the it, I realised that I really wasn't very good at it. After about 15 minutes of coming in last place all the time, I started to wonder how it worked, and how I could beat it.

As it turns out, it really isn't very hard! It does require injecting some JS into the page, but it's not that much.

Usage

  1. Start a new game, don't press start!
  2. Open your browser's developer console. This will vary from browser.
  3. Paste the compact version of the code (wiki-game-solver.min.js), and execute it (press enter)
  4. Congratulations, you just won!

How it works

The game isn't open source, so I couldn't see how the back end worked, but after playing a few games and checking what happened on the page, I worked out what it was doing.

The game was won when the iframe was at the final page location, or at least a clone of it on their servers with some extra querystring information.

With this, I started to write something that would change the location of the iframe to the goal. Fortunately for me, the goal URL was on the page. So all it took was a little switcheroo to win!

Source

The source for this was written in pure JS, and relies heavily on the fact that the wiki game uses jQuery so I can plug into components and events really easily. The code can be found in the GitHub gist below. Both the standard and compact versions are available.

wiki-game-solver.js    View Raw
1$("#start").click();
2var goal = $("#endpagelink0 > a").attr('href').replace("http://en.wikipedia.org/", ""); 
3var goalArray = $("#wiki").attr("src").split("?"); 
4goalArray[1] = "?" + goalArray[1];
5goalArray[0] = goal;
6$("#wiki").attr("src", goalArray.join().replace(",", ""));
<h5 class="mb-0">
  <a href="https://gist.github.com/7da9a3dd1bf90ecdf7be#file-wiki-game-solver.min.js">
    <code class="font-weight-bold pl-2">wiki-game-solver.min.js</code>
  </a>
  &nbsp;&nbsp;
  <a href="https://gist.githubusercontent.com/RealOrangeOne/7da9a3dd1bf90ecdf7be/raw/d6a21fa4f7154cafd3c42e098330a0b8cee7273b/wiki-game-solver.min.js">
    <small class="font-italic">View Raw</small>
  </a>
</h5>
<div class="highlight"><pre class="chroma"><code class="language-JavaScript" data-lang="JavaScript"><span class="ln">1</span><span class="nx">$</span><span class="p">(</span><span class="s2">&#34;#start&#34;</span><span class="p">).</span><span class="nx">click</span><span class="p">();</span><span class="kd">var</span> <span class="nx">goal</span><span class="o">=</span><span class="nx">$</span><span class="p">(</span><span class="s2">&#34;#endpagelink0 &gt; a&#34;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&#34;href&#34;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s2">&#34;http://en.wikipedia.org/&#34;</span><span class="p">,</span><span class="s2">&#34;&#34;</span><span class="p">),</span><span class="nx">goalArray</span><span class="o">=</span><span class="nx">$</span><span class="p">(</span><span class="s2">&#34;#wiki&#34;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&#34;src&#34;</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s2">&#34;?&#34;</span><span class="p">);</span><span class="nx">goalArray</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="s2">&#34;?&#34;</span><span class="o">+</span><span class="nx">goalArray</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="nx">goalArray</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="nx">goal</span><span class="p">,</span><span class="nx">$</span><span class="p">(</span><span class="s2">&#34;#wiki&#34;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&#34;src&#34;</span><span class="p">,</span><span class="nx">goalArray</span><span class="p">.</span><span class="nx">join</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="s2">&#34;,&#34;</span><span class="p">,</span><span class="s2">&#34;&#34;</span><span class="p">));</span>

Disclaimer

As I experienced whilst developing this, the people that play Wiki Game don't tend to like people cheating. There were a lot of people getting very annoyed whilst I was developing and testing. So please use this at your own risk! At the moment I don't think there is any kind of banning system, but be warned!

Share this page