Wikirace, MicroMod Taste

Have you ever ever heard of the Wikirace? It is a common solution to go time through the use of hyperlinks to shuttle from one Wikipedia web page to every other.

alt text

Principally, one of the most productive portions about the use of Wikipedia is how huge it’s…it’s essential to glance up one matter, and in seeking to needless to say matter have to be informed a couple of part a dozen different subjects inside Wikipedia. That is all accomplished thru Wikilinks, or the interior hyperlinks that attach subjects. The basis of the Wikirace is to look in point of fact how huge Wikipedia in truth is, and take a look at to attach two utterly unrelated subjects to one another in as few ‘clicks’ as conceivable. You’ll play the sport your self, or it’s essential to construct a bot to do it for you as briefly as conceivable.

It is particularly amusing to construct this type of bot when you love to nerd out on information buildings, as a result of it is necessarily a breadth-first seek algorthim. A breadth-first seek set of rules is efficacious for looking out tree or graph information buildings – it explores the entire neighbor nodes on the fast intensity degree prior to viewing any node at the subsequent intensity degree.

alt text

Construction a Wikirace bot on a microcontroller turns out like a amusing problem, so let’s have a look at how the construct is going!

The Construct

This type of bot will also be constructed thru Python, and I am a mega fan of Python because of its ease of use and unending libraries. So naturally, the very best conversion to construct this out on a microcontroller is to make use of MicroPython, which has lots of the nice options of Python thru a small subset of the Python same old library.

Plus, I need to use a show to depend the choice of Wikilinks visited during the race and what they’re. It sort of feels to be an high alternative to make use of the new RP2040 MicroMod Processor and the Enter and Show Service board. As with any MicroMod tasks, the {hardware} hookup is tremendous easy – it simply takes placing the particular keyed M.2 connector of the processor board into the service board and gently screwing it in.


SparkFun MicroMod RP2040 Processor



Favorited Favourite 3


SparkFun MicroMod Enter and Show Service Board




Favorited Favourite 7

The Code

I needed to import some libraries without delay into the MicroPython to get entry to the Wikipedia pages. Another way, the code takes a root and goal web page, and completes breadth-first seek to head thru Wikipedia to attach the two.

import os, sys, wikipedia def print_path(information): if information['parent']: print_path(information['parent']) print(' => ', finish='') print(information['title'], finish='') def get_page(variety): web page = None whilst no longer web page: check out: access = enter('%s web page name: ' % variety) web page = wikipedia.web page(access) aside from wikipedia.exceptions.DisambiguationError as e: print('nDisambiguation Variety (Make a choice one of those or use every other time period)') for choice in e.choices: print('t' + choice) print() aside from wikipedia.exceptions.PageError as e: print('Web page error, check out once more.') aside from KeyboardInterrupt: print('Exiting') sys.go out() go back web page def wikipedia_game(): # Clears up the display on get started. os.gadget('cls' if os.identify == 'nt' else 'transparent') print('Wikipedia Gamenn') root_page = get_page('Root') target_page = get_page('Goal') G = {} G[root_page.title] = { 'name':, 'distance': 0, 'mum or dad': None } Q = [G[root_page.title]] print('nFinding the shortest trail between the %s and %s pages...' % (, whilst Q: present = Q[0] Q = Q[1:] check out: current_page = wikipedia.web page(present['title']) print('tpercents' % for hyperlink in current_page.hyperlinks: if hyperlink no longer in G: G[link] = { 'name': hyperlink, 'distance': present['distance'] + 1, 'mum or dad': present } if hyperlink == print('npercents discovered!' % hyperlink) print('Trail: ', finish='') print_path(G[link]) print() sys.go out() Q.append(G[link]) aside from wikipedia.exceptions.DisambiguationError as e: # Disambiguation Web page G[e.title] = { 'name':, 'distance': present['distance'] + 1, 'mum or dad': present } # Provides each and every hyperlink on disambiguation web page to queue for choice in e.choices: if choice no longer in G: G[option] = { 'name': choice, 'distance': present['distance'] + 2, 'mum or dad': G[e.title] } if choice == print('npercents discovered!' % choice) print('Trail: ', finish='') print_path(G[option]) print() sys.go out() Q.append(G[option]) aside from wikipedia.exceptions.PageError as e: # Skips over the thing within the queue if it leads to a web page error. print('tSkipping %s...nttpercents' % (present['title'], e)) aside from KeyboardInterrupt: print('Exiting') sys.go out() wikipedia_game()

Clearly, there is an instantaneous factor with this code working at the RP2040 – I want Wifi to get entry to Wikipedia within the first position. However it is k that I wrote this up in MicroPython, since the ESP32 Processor board additionally works with MicroPython and has WiFi functions. So I will switch it out actual fast and run it thru a unique processor board.


SparkFun MicroMod ESP32 Processor



Favorited Favourite 3

The Finish Outcome

The result is that I will give you the bot a beginning and finishing Wikipedia web page, and it may possibly depend what number of Wikilinks it visited and what they had been and show it at the Enter and Show Service board. I seemed up a random web page on Wikipedia (Montesarchio), and ran it to look if I may just get to tree. Those had been the next steps it took: Montesarchio, Western Roman Empire, Africa, Oil Lamp, Walnuts, Tree. I assume your next step is to race the bot itself…

feedback | remark feed