Permalink
Browse files

Moved and updated level tools (& docs) to now build static levels.

  • Loading branch information...
1 parent 8ba100e commit be850cb56c726ed4e28402c0b75a6ca3bb73c117 @borgar committed Jun 24, 2011
Showing with 43 additions and 33 deletions.
  1. +31 −30 README.md
  2. +11 −2 {levelbuilder → }/build_levels.py
  3. +1 −1 {levelbuilder → }/filter_bin.py
View
@@ -1,36 +1,38 @@
# Orðavinda
-Orðavinda is a simple JavaScript word game. Given a set of 6 letters, the player must
-find as many correct words as possible before time runs out. In order to qualify to
-play the next level, the player
+Orðavinda is a simple JavaScript word game. Given a set of 6 letters, the
+player must find as many correct words as possible before time runs out. In
+order to qualify to play the next level, the player must guess at least one
+of the 6 letter word combinations.
-The game is written as an entry into [Þú átt orðið][1], a contest in creating solutions
-exploiting the Icelandic declension dictionary ([BÍN][2]). As such it is icelandic
-centric but can with minimal effort be made to work with other languages.
+The game is written as an entry to [Þú átt orðið][1], a contest in creating
+solutions exploiting the Icelandic declension dictionary ([BÍN][2]). As such
+it is icelandic-centric but can with minimal effort be made to work with other
+languages.
## The Game
-The game must be run from a web server to work as it fetches levels via an Ajax
-request. The game is comprised of 3 parts:
+The game must be run from a web server to work as it fetches levels via an
+Ajax request. The game is comprised of 3 parts:
* `vinda.js` - The main game logic.
* `utils.js` - JavaScript utility functions.
* `vinta.sounds.js` - Sound extensions for the game.
-The game requires [jQuery][3] JavaScript library to run. Additionally the
+The game requires [jQuery][3] JavaScript library to run. Additionally the
[Soundmanager2][4] library is needed to enable sound support.
-The levels have been cut down to a single demonstration level. You will need to build
-a level collection using the tools provided in the `levelbuilder` directory.
+The levels have been cut down to a single demonstration level. You will need
+to build a level collection using the tools provided.
## Why are the sounds not included?
-The sounds are not essential to the gameplay and take an unreasonable amount of
-space. Also, including a one more library with yet another license didn't
-
+The sounds are not essential to the gameplay and take an unreasonable amount
+of space. Also, including a one more library with yet another license
+complicated things unnecessarily.
### How to add sounds:
@@ -44,38 +46,37 @@ space. Also, including a one more library with yet another license didn't
## Why are the levels not included?
-The current license for *BÍN* does not allow redistribution or relicensing of the
-data under an open license. This may change in the future, in which case the levels will be bundled with source.
+The current license for *BÍN* does not allow redistribution or relicensing of
+the data under an open license. This may change in the future, in which case
+the levels will be bundled with source.
-You currently need to opt-in to the BÍN license and download it for yourself, and
-build the levels with the tools provided. Users are urged to adapt the game for
-more languages buy building levels for other dictionaries.
+You currently need to opt-in to the BÍN license and download it for yourself,
+and build the levels with the tools provided. Users are urged to adapt the
+game for more languages buy building levels for other dictionaries.
### How to build the levels:
1. [Download and unzip the *BÍN* data][6]. Specifically: `SHsnid.csv.zip`
- 2. Run `filter_bin.py` on `SHsnid.csv` to produce a manageable filtered subset
- of the dictionary:
+ 2. Run `filter_bin.py` on `SHsnid.csv` to produce a manageable filtered
+ subset of the dictionary:
`$ python filter_bin.py SHsnid.csv > dictionary.txt`
3. Run `build_levels.py` on the output to produce the levels.
- `$ python build_levels.py dictionary.txt > levels.txt`
-
- The output will be a large file containing JSON representations of every possible
- level combination.
+ `$ python build_levels.py dictionary.txt`
- 4. Add logic to `game/level/` to serve a single slice from this collection.
- There is a makeshift PHP script bundled, and at the very least you need to make
- sure that the levels are where that script expects to find them.
+ The output will be a large collection of JSON files, each one
+ representing a single level, written to the `game/level` directory.
+
+ 4. Open the game in your browser.
## Licence
-The game and all it's parts not specifically marked as such are licensed with the
-[GPL free software licence][5].
+The game and all it's parts not specifically marked as such are licensed with
+the [GPL free software licence][5].
@@ -1,6 +1,8 @@
# encoding: UTF-8
+from __future__ import with_statement
import sys
import random
+import shutil
usage = """
Use it like this:
@@ -39,6 +41,7 @@ def build_levels( filename ):
keywords = [ w for w in words if len(w) == 6 ]
json_template = u'{ "key":"%s", "words":["%s"] }'
+ count = 1;
skip = {}
for key in keywords:
if key not in skip:
@@ -48,10 +51,16 @@ def build_levels( filename ):
# only use levels where number of words is >=10 and <=50
if len(found) >= 10 and len(found) <= 50:
level = json_template % ( key, '","'.join( found ) )
- print level.encode( 'UTF-8' )
+ with open( u'game/level/level%s.json' % count, 'w' ) as f:
+ f.write( level.encode( 'UTF-8' ) )
+ count += 1
+ with open( u'game/level/levels.json', 'w' ) as f:
+ f.write(
+ ( u'{ "available": %d }' % (count, count)
+ ).encode( 'UTF-8' ) )
-if __name__ == '__main__':
+if __name__ == '__main__':
if len(sys.argv) < 1:
print usage
sys.exit(2)
@@ -27,7 +27,7 @@ def filter_bin ( filename ):
word = unicode( word, encoding='UTF-8' )
if len( word ) >= 3 and len( word ) <= 6 and category not in ['ism','örn','göt','fyr','föð','móð','bibl','lönd']:
lc = lowercase( word )
- if lc not in words:
+ if lc not in words and '-' not in word:
if lc == word:
words[ lc ] = lc
print word.encode('UTF-8')

0 comments on commit be850cb

Please sign in to comment.