26
Aug 16

Running stockfish or komodo on Centos 6

I wanted to try out a chess engine, but I didn't want to run it on my own computer where I have the GUI. So what to do? I had a centos 6 computer with enough cpu power, but when I downloaded and ran stockfish I got:

$ ./stockfish-7-linux/Linux/stockfish\ 7\ x64 
./stockfish-7-linux/Linux/stockfish 7 x64: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./stockfish-7-linux/Linux/stockfish 7 x64)
./stockfish-7-linux/Linux/stockfish 7 x64: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by ./stockfish-7-linux/Linux/stockfish 7 x64)

And when I ran komodo 10.1 (which you have to buy), I got:

$ ./komodo-10.1-linux 
./komodo-10.1-linux: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./komodo-10.1-linux)
./komodo-10.1-linux: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./komodo-10.1-linux)

The problem is Centos 6 has too old glibc version. So how to fix this? The short version is to download the finished files I'll show you how to create in the long answer. They are ld-linux-x64-64.so.2, libc.so.6 and libstdc++.so.6.

Short answer:

wget http://www.menneske.no/libs/chesslib.tar.gz
tar zxvf chesslib.tar.gz
./ld-linux-x86-64.so.2 --library-path . <path to komodo or stockfish>

Voila, they both works fine on Centos 6.

Long answer:
For stockfish you can download the src and compile it. But for komodo that is not possible. So, you need to compile both gcc and glibc to be able to get the files. It takes a long time, and some GB of space, but here is how you do it, if you don't trust my precompiled files:

# First we assure we have the development tools to build stuff
yum groupinstall "Development tools"
yum install -y glibc-devel glibc-i686

# Now we build glibc. This will not overwrite your current glibc, so don't worry
cd /tmp
wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
tar -xvzf glibc-2.17.tar.gz
cd glibc-2.17
mkdir glibc
cd glibc
../configure --prefix='/opt/glibc-2.17'
make
make install

# Then compile gcc
cd /tmp
wget ftp://ftp.gwdg.de/pub/misc/gcc/releases/gcc-4.6.4/gcc-4.6.4.tar.gz
tar -xvzf gcc-4.6.4.tar.gz
cd gcc-4.6.4
./contrib/download_prerequisites
mkdir objdir
cd objdir
../configure --prefix=/opt/gcc-4.6.4
make
make install

Now we have all the files, and we copy them out to our preferred directory.

cd <your path>
cp /opt/gcc-4.6.4/lib64/libstdc++.so.6 .
cp /opt/glibc-2.17/lib/libc.so.6 .
cp /opt/glibc-2.17/lib/ld-linux-x86-64.so.2 .

And then you run it with:

./ld-linux-x86-64.so.2 --library-path . <path to komodo or stockfish>

But how did I reach it from my other computer? Well, ssh to the resque.

cat <<EOT > komodo
#!/bin/sh
# ssh chess.test.com -l chess ./ld-linux-x86-64.so.2 --library-path . <path to komodo or stockfish>
ssh <yourhost> -l <youruser> <path to komodo on host>
EOT

# fix permissions
chmod 750 komodo

Remember to add pub ssh key to the host, so you don't need to write the password to login. Voila, then you just add "komodo" as the engine in your favourite GUI.

6
Jan 16

#FreeFreddy puzzle game is out

Cellar Labs new puzzle game, Free Freddy, is out for Android. Get it at Google Play.

Solve 100 puzzles to earn trophies and certificates. Or try solve random puzzles in different sizes and difficult levels. If you feel lucky, try a 10x10 insane puzzle.

The game will soon be available for iPhone and Windows Phone too.

Icon

Get it on Google Play

Get it from Microsoft

2
Dec 15

#Phaser.io phaser-swipe-pages

Find it on GitHub

phaser-swipe-pages
Phaser component to manage a state of pages

Can be useful for eg help screens etc. It will use the Phaser.Camera to move around, and take care of
positioning your objects

Install

The easies way of using it is compiling your project with browserify and install it like:

  npm install phaser-swipe-pages

Usage

    var SwipePages = require('phaser-swipe-pages');
    
    // in create
    this.pages = new SwipePages(this.game, 3);
    
    // If you want standard menus. Else you can create your own and pages.addToStationary(obj);
    this.pages.createMenu({}, this.back, this);
    
    // Create your pages. All objects should be created as positioned on the primary screen. The component will
    // move them to correct place
    var text = this.game.add.text(0,0,'page 1');
    this.pages.addToPage(1, text);
    
    // Here we add a text to page 2. But the positioning is still 0,0
    var text2 = this.game.add.text(0,0,'page 2');
    this.pages.addToPage(2, text2);
    
    // Go to page 1
    this.pages.goPage(1);
    
    this.back = function() {
      // This.will be called when the user presses SKIP on the menu
    }
24
Nov 15

phaser-swipe for #phaser.io

I've created a swipe component for Phaser.io. You can find it on GitHub

You can grab the swipe.js file and include it in your project, or you can use npm or bower:

   npm install phaser-swipe
   bower install phaser-swipe

Usage

You can use it in two ways. With or without a model. This is without model

  var Swipe = require('phaser-swipe');
  
  // in create
  this.swipe = new Swipe(this.game);
  
  // in update
  var direciton = this.swipe.check();
  if (direction!==null) {
    // direction= { x: x, y: y, direction: direction }
    switch(direction.direction) {
       case this.swipe.DIRECTION_LEFT: // do something
       case this.swipe.DIRECTION_RIGHT:
       case this.swipe.DIRECTION_UP:
       case this.swipe.DIRECTION_DOWN:
       case this.swipe.DIRECTION_UP_LEFT:
       case this.swipe.DIRECTION_UP_RIGHT:
       case this.swipe.DIRECTION_DOWN_LEFT:
       case this.swipe.DIRECTION_DOWN_RIGHT:
    }
  }

This is with a model. Here you define your methods in your model. Only those methods defined will be used. So if you do not want the diagonals, you can just omit those methods.

   function YourModel() {
      up: function(point) {},
      down: function(point) {},
      left: function(point) {},
      right: function(point) {},
      upLeft: function(point) {},
      upRight: fuction(point) {},
      downLeft: function(point) {},
      downRight: fuction(point) {}
   };
   
   // in create
   this.swipe = new Swipe(this.game, yourmodel);
   
   // in update. The methods will only be called if you have a swipe.
   // point: { x: x, y: y }
   this.swipe.check();
23
Nov 15

phaser-updatable-label

I created an animated updatable label for the Javascript framework Phaser.io. You can find it on github.

You can use it like:

 // If you used browerify. Else just add it in script tag and use class UpdatableLabel.
  var UpdatableLabel = require('phaser-updatable-label');

  // Sample style for the label text
  var textStyle = { font: '50px Arial', fill: '#00', align: 'center'};

  // The initial value of the label
  var initValue = 0;

  // Create the label. The true is to set if the label is ment to be positive
  var label = new UpdatableLabel(this.game, startX, startY, initValue, textStyle, true);

  // Add a value to the label. We define the start position for the value we add
  // This will start the animation and add the value
  label.addValue(10, {x: 100, y: 100});

  // Get the new value. This is the updated value even though the label is not
  var newValue = label.getValue();

  // We can also add multiplications. If the value was 1 and we add multiplier by 2
  // the new value will be 2
  label.addMultiplier(value, {x: 100, y: 100});

  // And remove it. The module take care of correct number, so you should use
  // the value of 2 if you used 2 in addMultiplier
  label.removeMultiplier(value);
23
Nov 15

Chicken Hatch Puzzle Game for iOS

We have published the iOS version of our Chicken Hatch game.

Try it out at iTunes.

Can you solve them all with 3 stars? If you're stuck, try YouTube

31
Oct 15

Chicken Hatch Puzzle Game for Android

We have published a new fun puzzle game called Chicken Hatch. Try to get the hens to hatch the chickens. It is not that hard to find a solution for the puzzle, but finding the 3 stars solution is much harder.

Try it out at Google Play. iOS version will come later.

Can you solve them all with 3 stars?

27
Jun 15

#nodejs module for parsing key/value strings

Since my regexp test on parsing a string was a success, I created a #nodejs module for parsing strings. And the funny part, I scrapped the regexp 🙂 It now supports multiple keys and multiple values.

So you can do something like this:

var res = ps.parse('"foo bar" bar,"foo bar"=1 bar,"foo bar"=bar,"foo bar"');
res = [
   ['foo bar', undefined],
   ['bar', '1'],
   ['foo bar', '1'],
   ['bar', ['bar', 'foo bar']],
   ['foo bar', ['bar', 'foo bar']]
]

You can find the code at GitHub or as a npm module

24
Jun 15

#javascript and parsing param string

Got a little challenge parsing strings like:

Little brown="and yellow" fox=1 jumps over=lazy dog

I wanted to split it into an array with key/value pairs, so the result would be:

var res =
[ [ 'Little', undefined ],
  [ 'brown', 'and yellow' ],
  [ 'fox', '1' ],
  [ 'jumps', undefined ],
  [ 'over', 'lazy' ],
  [ 'dog', undefined ] ]

And here the regexp guy in me popped out and wanted to go for a short version. I ended up with

var text = 'Little brown="and yellow" fox=1 jumps over=lazy dog';

var res = text.match(/([^=\s]+="[^"]+")|\S+/g).map(function (p) {
    return p.match(/^([^=\s]*)(?:="?([^"]*)"?)?$/).splice(1, 2);
})

console.log(res);

The first one (/([^=\s]+="[^"]+")|\S+/g) splits the string into an array of param|param=value|param="value with space". The second one (/^([^=\s])(?:="?([^"])"?)?$/) split that array into separate arrays which contains key,value and remove the possible double quote on the value. Since match return all the splits, I splice out the values from the new array, 1 and 2.

And there you go.

You can find the last version at GitHub

PS: This rely on that array.map() exists, which it does in #nodejs

18
Jun 15

@nodejs and object sort speed

I was coding a scheduler and needed a sorted array of the schedules, so I started to investigate the speed of different sorting variants I could use.

I created a little program (https://gist.github.com/flogvit/c9df93ab37ca4dbd2d7f) to test 4 different variants.

For the test I created an array with 100000 objects { v: num }, where num is 100000 to 1. v is the value I want to sort on. Then I did the sort 10 times for each variant, and then again running this 5 times.

The first variant was standard compare (compare):

function compare(a, b) {
  if (a.v < b.v)
    return -1;
  if (a.v > b.v)
    return 1;
  return 0;
}

sortarray.sort(compare);

The second was a value only version doing the minus variant (compareValue):

function compareValue(a, b) {
  return a.v - b.v;
}

sortarray.sort(compareValue);

Third variant is using async (async):

   async.sortBy(sortarray, function (entry, callback) {
      callback(null, entry.v);
    }, function (err, results) {
      sortarray = results;
    });

And last variant is using underscore (underscore):

sortarray = _.sortBy(sortarray, 'v');

The result where smaller is better:

compare 36.00
compareValue 36.58
underscore 50.84
async 228.48

And the full output from each run:

$ node --expose-gc sort.js
Running compare for average 30.8 ms
Running compareValue for average 38 ms
Running async for average 227 ms
Running underscore for average 51.8 ms
Running compare for average 38.8 ms
Running compareValue for average 36.6 ms
Running async for average 230.7 ms
Running underscore for average 49.5 ms
Running compare for average 37.2 ms
Running compareValue for average 35.2 ms
Running async for average 234.7 ms
Running underscore for average 52.6 ms
Running compare for average 37.4 ms
Running compareValue for average 37.1 ms
Running async for average 224.4 ms
Running underscore for average 49.4 ms
Running compare for average 35.8 ms
Running compareValue for average 36 ms
Running async for average 225.6 ms
Running underscore for average 50.9 ms