Find The Country
Monday, 15. January 2007, 00:13:15
Update 21/01/2007:
Thanks to help from Jeff we are now fully functional in IE+ASV as well!
We also have a much smaller Compressed svgz file of the game as well.
For most people that's all you'll be interested in. The rest of this entry is extremely long & probably not that interesting. You have been warned.
A while ago I found a link to this flash based game which presents a world map & the object of the game is to click on the country whose name pops up on the bottom.
I thought this game would be an excellent tool for learning the locations of countries, but after playing it for a little while I noticed many limitations.
There are some countries missing, Greenland for example. It has annoying sound effects. You can have as many guesses as you like within the time limit, meaning you can click wildly, chance upon the right answer by accident & possibly without knowing which country was the correct one. The navigation is a bit clunky for many reasons. You have a number of predefined zoom levels, on the lower zoom levels many countries are too small to be clicked. While zoomed in you can pan round the map by clicking & dragging a body of water, but on the higher zoom levels sometimes there is no sea or lake to drag - so you have to zoom out, pan, zoom back in & select your country before the timer runs out which can be frustrating.
Worst of all though (especially in terms of learning) this game does not provide any feedback other than yes or no. To really learn you need to be told what you did wrong & what the correct answer was.
Clearly there is room for improvement. So I thought I'd give it a go.
SVG
A couple of years ago I started looking at Scalable Vector Graphics (SVG). At the time though, there was only one viewer available from Adobe & it wasn't particularly great back then. Online information was limited to a few examples that all linked back to the W3C specification & there were no editing tools available. I learnt to draw the basic shapes (hand coding) & that was about it. What I wanted to do with SVG at the time was way too advanced for the little I was able to learn so I thought I'd leave it for a while to let the SVG scene develop.
Here we are a year later & yes the SVG scene has developped, we have editors, native support in a number of browsers & considerably more reference material available online. There are also a large number of SVG advocacy articles, all saying the same thing.
Yes it's scalable, yes it has a small filesize, yes it is an open format etc. But these are all plus points that relate to graphics formats. For me the best thing about SVG is that it is text, or more specifically XML. This means that the contents of an SVG file is machine readable data. But unfortunately everyone seems to be treating SVG as a graphics format & totally ignoring this major strength.
An SVG file consists of a number of elements, for example a
Rule 1 of SVG:
Every element must have a unique & descriptive ID
The Open Clip Art Library already has a huge number of svg files on all manner of subjects. But if you look at the source of all the files they have all been created using Inkscape or Sodipodi, two major SVG editors which enable you to save pictures in the SVG format.
None of the elements have any useful semantic information assigned to them. At best an object will have 'id="path2521"' as an attribute, but this only tells us that it was (possibly) the 2521th path that was drawn. Most elements don't have a unique ID at all.
To create the Find the country svg I first started with this blank world map that I found in the Wikimedia Commons which obviously provided me with a great start. But looking at the data the entire world was drawn as a single path element. Every country on the planet was lumped together as one object. An SVG viewer is perfectly capable of rendering the information in the file into an image that looks like a map of the world. But because there is no information contained in the file stating what that shape is it has no idea as to whether one shape is England, France, Germany or any other country.
My first task using a bit of regexp magic was to seperate that one single element into lots of individual elements. Then I went through each element in turn, finding it on another map then assigning that countries name to the element as a unique ID. While doing this I found another problem with the original file was that some of the paths represented more than one country. The worst offender being a single path that depicted Norway, Russia, North Korea, Kazakstan & many others. Because these countries were not stored as individual elements they could not be treated individually.
Rule 2 of SVG:
One Element = One Object
The last major problem I had with the original file was the order in which the file was composed. The original must have been made by importing a traditional raster image of the world which was then automagically converted to SVG. Not knowing what it was doing (raster file formats don't hold any semantically meaningful data either) the SVG simply drew all the elements in order from left to right, then top to bottom. For a computer this is entirely logical, but us humans tend to group data differently. In the case of countries the obvious way to group them together is by continent. If you look at the source of my file you'll notice all the countries are grouped in a much more human friendly way.
Rule 3 of SVG:
Group elements together by usage
By following these 3 simple rules you produce SVG files that are much easier to maintain. For example, say you wanted to change my svg file to only include African countries. You'd simply need to delete the other 5 continents which are clearly labelled in easy to read plain text.
Jax seems to think that 2007 will be a slow year for SVG. I certainly hope he's wrong.


jeff_schiller # 19. January 2007, 00:13
1) Put SVG:title and SVG:desc elements in there, including your name, email address, license, etc.
2) Group all countries in a continent or region using a SVG:g element
3) Put in some SVG:a elements to, say, wikipedia articles for each country?
4) Post links to these two games in the "SVG Road Trip" thread at getsvg.com
jeff_schiller # 19. January 2007, 00:15
I mentioned grouping, say all of the North American countries, into a SVG:g element (named id="NorthAmerica"). In that way, you can later transform all of NA, hide it, colour it, etc. More interesting things later.
orinoco # 19. January 2007, 09:15
1) Will do. I don't really know much about licenses but please feel free to copy/tinker as you see fit. The original map was from Wikipedia under the GNU Free Documentation License so this should be the same.
2) All elements are physically grouped together in the file (as I'm sure you've noticed) & commented accordingly. I purposefully didn't group them into a g because it would cause the getElementById operations to perform that little bit slower by having another level to traverse through to find the correct node (Had I not read this article: http://dev.opera.com/articles/view/efficient-javascript/ I probably would have done).
3) I thought about that too but decided to keep it simple as I was only really doing this as a learning exercise. It certainly add an extra level of interest though.
4) The code doesn't work in IE yet unfortunately. Once I've worked that out I'll certainly publicise it further afield.
jeff_schiller # 19. January 2007, 16:46
jeff_schiller # 19. January 2007, 16:56
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1938918D describes how getElementsByTagName() does not return an array, it returns a NodeList object (http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1938918D). Opera and Firefox allow you to use the [] operator to access elements within the NodeList, but ASV does not (it uses a very old version of the Mozilla JS scripting engine):
So using Countries[ix] is not going to work - use Countries.item(ix) instead.
Once I fixed this in two places in NewCountry(), then your file worked for me in IE+ASV.
jeff_schiller # 19. January 2007, 17:10
jeff_schiller # 19. January 2007, 17:19
So replace your Check() function with:
_Grey_ # 20. January 2007, 22:47
Nice game. Once you remember all that small stuff (Brunei, Bezile, East T...) it really comes down to concentration. I would change the game so that on each right answer, it deletes a country from the Array, so no country is selected several times. On each wrong answer, fill the Array up again completely.
(And thanks Jeff for pointing me to this game, very educational.)
orinoco # 21. January 2007, 15:49
@Jeff, thanks for spotting those 2 mistakes, all fixes are now in & everything is working in all three browsers. I'll have to remember those points for my future projects. I've renamed some of the functions & variables so the whole code is generic so I was able to port it to the map of the US States without having to change 'Country' to 'State' etc. & the code will still have meaning if someone else ports it to another map.
re: 2. One of the points in the article was "Avoid inspecting large numbers of nodes" so I just thought I'd keep the number of nodes down to an absolute minimum
I have created svgz versions (World Countries & US States) which work lightening quick in Opera. In IE it takes longer to render the compressed file than it does to download & render the standard file & I only get a parsing error in FF so I assume that Opera's servers are not set up with the correct http headers. I'll post a message on the relevant community forum to see if the server monkeys can get that sorted.
Thanks again for all your help, it is very much appreciated!
jeff_schiller # 21. January 2007, 23:42
Of course you can do this even if there are differences in your code (make two separate script files).
Regards,
Jeff
rslite # 9. February 2007, 12:48
I would also like to subscribe to the proposition of shuffling all the countries instead of randomly selecting from the list. This way you shouldn't get a country twice unless you make a mistake. I think it would make a better learning experience.
gun # 9. March 2007, 22:01
nickshanks # 13. March 2007, 11:57
Taiwan is also not internationally recognised as a country. China gets upset if you say it is, and will do daft things like block all of opera.com.
Western Sahara is claimed by Morocco.
The tranquil northern part of Somalia (formerly British Somaliland) declared its independence from the war-torn south 15 years ago, though since Somalia has no stable government no other country has bothered to recognise it.
Greenland is a province of Denmark.
Antarctica is omitted. Implementation would be 'interesting' due to overlapping claims.
As the poster above said, Crete is not a country, and neither are the Falklands, Hawaiian or Baleric Islands, Newfoundland, Corsica, Sardinia, Sicily, Jan Mayan, Hainan etc etc.
The Isle of Man has a different government from the UK, but is huighlighted along with the rest of the UK.
Perhaps you should change the name from "Find the Country" to "Find the Location" *shrug*
You could take the more accurate US outline from United States of SVG and use it here, though you may wish to remove state boundaries.
There's a good map of UK parliamentary constituencies at http://commons.wikimedia.org/wiki/Image:2005UKElectionMap.svg
You could turn that into a game too :-)
nickshanks # 13. March 2007, 11:59
dantesoft # 18. March 2007, 22:19
I maintain my comment: hitting Costa Rica instead of Nicaragua should get me a few parts of a point..
Silly question: how to scroll map to the right ? Figured out how to zoom out. (Opera 9)
orinoco # 19. March 2007, 09:02
@Dantesoft Have you got fit to width enabled (alt+P > Web pages > Fit to width? If so that stops the page from being scrollable.
dantesoft # 19. March 2007, 09:26
An option to zoom into areas of a continent would also help in Central America / West Africa / SE Asia.
UPDATE: "Click on the country specified in the South Atlantic Ocean" could use a little rewriting. May I suggest "Follow the instructions shown in blue, and click on the country as fast as possible". A little fictitious tension is all this game needs
orinoco # 19. March 2007, 11:39
Ah hold on, plug in? WHAT ARE YOU DOING NOT USING OPERA!!!!
dantesoft # 19. March 2007, 12:53
UPDATE: I think it said "Find Lebanon", I clicked it, and it said "Wrong, you clicked Lebanon".. If you have time to investigate unreproducible reports..