Schnee (schnee) wrote,
Schnee
schnee

Taikyoku shogi

According to Wikipedia, taikyoku shogi is the largest (known) variant of shogi, the game sometimes called Japanese chess; it is played on a 36x36 board, with each player initially possessing 402 pieces of 209 types that can move in a total of 253 distinct ways.

Pieces can be promoted in this game, and when looking at the table that Wikipedia helpfully provides, I noticed that there are chains of promotions — conceptually, if not in the game itself (a piece can only be promoted once, naturally, just like in chess or checkers).

Nonetheless, my curiosity was piqued. What does the promotion graph look like?

I ended up copying and pasting the table from Wikipedia into a text file (from the rendered article, not its source!), and turned it into a DOT file with a short Perl script:

#!/usr/bin/perl

use strict;
use warnings;
use feature qw/say/;

say "digraph taikyokushogi {";

while(<>) {
    chomp;

    my @F = split/\t/, lc;
    $F[0] =~ s/^\*//;

    $F[$_] = join " ", map { ucfirst } split " ", $F[$_] for(0,3);

    say qq/    "$F[0]"/, ($F[3] ne "—") ? qq/ -> "$F[3]"/ : "";
}

say "}";

After manually fixing the two Mountain Eagles and Howling Dogs that Wikipedia unhelpfully combined into one in the table, I then fed the resulting file to Graphviz (specifically dot) to get a rendered graph:

$ perl taikyokushogi.pl taikyokushogi.txt >taikyokushogi.dot
$ joe taikyokushogi.dot
$ dot -Tpng taikyokushogi.dot -o taikyokushogi.png
$ 

It's fairly disconnected, as expected, but there's a few slightly larger components; here's a particularly neat one:

The largest "promotion chain" is that of the Pawn, BTW, whose hypothetical career path'd take him from Gold General to Rook to Dragon King to Soaring Eagle and finally Great Eagle. (Again, keep in mind that this cannot happen in the game.)

The full graph is available here (27630x539 PNG, 433 KiB), if you're curious. Other Graphviz engines (e.g. neato) will produce different files, but I thought dot's looked the best. All files can be found here.

The whole thing's just a bit of fun, of course. But I gotta say, it's nice to have tools available to do this sort of thing — and to know how to wield them.

Tags: board games, perl, programming, shogi
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments