text:
aHHHH! The Beasts are HHHHere!
As we learned from the IBM PC AT, YouTube (see video), Wikipedia (see article), and Sesame Street:
The letter H is the most merciless letter of the alphabet!
(Even when actually composed from two elements in Code Page 437.  In fact, it's even MORE merciless that way.)
Like the Aliens in, uhm...er... Aliens, Beasts relentlessly pursue all who would dare come near their eggs.  There is no reasoning with them.  You must squash them if not to perish.

For this scenario we will assume you're down to your last life, and you've met plain Beasts in a terrain with no eggs (as in the Wikipedia screenshot).  You don't have a numeric keypad and can only move directly up/down/left/right...but the beasts apparently have one, and can move diagonally on their turn.
A Beast's choice of move among its options will be the one that minimizes distance from the player.  If the distances are equal then tie breaking is done favoring left+up over right+down, but here's the disambiguation matrix to be explicit about it...lowest number to tie-break:
1 3 4
2 H 5
6 8 7

A beast never sleeps, but they are fortunately a bit slower than the player.  They move every other turn (giving the player a head start by beginning their alternations on the second turn).  They must move if a move is possible, regardless of if that takes them further from the player.
You crush a beast if you move a train of movable walls where it was sitting in a closed gap.  These plain beasts are worth 2 points a head.
Input

A pair of integers indicating a map's size in columns then rows.
Row count of lines of input, each of the column size...containing either a solid wall (#), a movable wall (~), a beast (H), the player (O) or just a space.
Input that will be either U, D, L, R indicating an attempted move by the player... or W to just wait.  Note that attempting to push a movable wall which is blocked is legal input, it just will result in no action.

Output

aHHHH! if the beasts killed the player...or nothing if the player won with no beasts remaining
The score

(Note: For debugging purposes and/or amusement, you'll probably want to be able to output the state at each step; but that's too long to post here.)
Clarifications

Maps are guaranteed to be bounded by solid walls.
The order of who moves in a turn matters for the outcome.  Thus: The player always goes first, then the beasts are given an ordering based on their initial map position if you were sweeping across the screen top to bottom left to right. (A row 1 beast moves before a row 2 beast, and two beasts on the same row it would be the one with the lowest column number that would move before the other)
Diagonal moving beasts can move into any open adjacent diagonal space, regardless of if it requires squeezing between walls.
A player can push any number of movable walls in a line provided that there's a space or a beast on the other end.  But trying to push a train of walls into a Beast that is not pinned between walls treats the Beast as a wall, and won't allow the move.
A Beast's move decision during a turn is based on the player's location at the beginning of the turn.  Its desired optimization of "distance to player" is  through an "as the crow flies" calculation.  Any approximation which would give the same result as measured from the center of its square to the center of the player's square is fine.
If a Beast can't make what would have been its first preferred move in a turn because a higher priority Beast took its spot, it will take its next best choice as opposed to staying in place (if a move is still possible).

Sample Cases
Simple Crush
Input
5 3
#####
#O~H#
#####
R

Output
2

Preference Matrix -> Death
Input
5 5
#####
#O  #
# ~ #
#  H#
#####
WWDW

Output
aHHHH!
0

Preference Matrix -> Win
Input
5 5
#####
#O  #
# ~ #
#  H#
#####
WRD

Output
2

Waiting For the Reaper
Input
5 5
#####
#O  #
# ~ #
#  H#
#####
WWW

Output
aHHHH!
0

Successful Defeat in the Wikipedia Scenario
Input
40 23
########################################
#~      ~ ~~  ~  ~ ~~   ~ ~~    ~ ~ ~~ #
#~~ ~          ~~   ~   ~ ~~         ~ #
#~# ~~   ~~~~      ~  ~~~~  ~    ~~~  ~#
# ~        ~   ~ ~~ #~~       ~        #
#~~  ~~~   ~ ~ ~      ~ ~~ ~  ~  ~  ~  #
#     ~~  ~  ~ ~ ~~~       H    ~  #~  #
#  O~  ~  #  ~~~ ~      ~ ~~  ~  ~ ~~  #
#       ~ ~H~~   ~~ ~ #        ~~   ~  #
# ~~         ~ ~~~  ~~   ~~~~      ~  ~#
#~  ~    ~~~  ~   ~        ~   ~ ~~  ~~#
#     ~      # ~ ~~  ~~~   ~ ~ ~ #    ~#
#~ ~ ~~  ~  ~   H     ~~  ~~ ~ ~ ~~~   #
#       ~   ~   ~   ~  ~     ~~~ ~     #
# ~~  ~  ~ ~~   ~       ~ ~ ~     ~    #
#      ~~   ~   ~  ~         ~      ~~ #
#~ ~     #    ~~~~  ~    ~~~H   # ~    #
#  ~   ~ ~   ~        ~          ~~  ~ #
#  ~   ~     #~  ~   ~~  ~  ~         ~#
# ~~ ~ ~  ~~                ~   ~      #
#    ~~~        ~ ~~  ~  ~  ~   ~      #
# ~ ~     ~            ~~   ~   ~  ~   #
########################################
RRRUWWWRRRURWWWWRDRRWWRDWWWWD

Output
8

Map provided by me, moves and output by @bobbel, corroborated by myself and @Allbeert.
Winning Criteria
I think this is golfable, so I'll go with code golf rules unless people complain.
Extra Credit
Playable Unicode implementation with the double-wide characters to resemble the image!

Do diagonal movements jump over antidiagonal lines of walls? Given that a beast makes a move every turn, how does it break distance ties between two horizontal moves or two vertical moves? Does it move towards where the player was at the start of the turn, or after the player's movement? When you say "train of movable walls", does that mean that the player can push any number of movable walls in a line provided that there's a space or a beast on the other end?

@PeterTaylor Yes you can push any number of walls as long as it's a space or Beast on the other end.  Though I had to watch the video again to make sure they could squeeze between walls, and they can.  :-)  Clarified.  The distance calculation is "as the crow flies" and they decide their move on the position at the beginning of the turn.

The point of the question about tie-breaking was that if you have O #H then the beast can't move towards the player so has to move either up or down, and the symmetry needs breaking.

@PeterTaylor Right... I thought that was clarified by the sample data and the "horizontal favoritism => death" vs "horizontal favoritism => win"... by the rule A Beast's choice of move among its options will be the one that minimizes distance from the player, favoring a horizontal move over a vertical one if both are equal.  Er... or not?

You've given the tie-breaker between a horizontal move and a vertical move. What is the tie-breaker between "move left" and "move right"? What is the tie-breaker between "move up" and "move down"? What is the tie-breaker between "move up-left" and "move up-right"? Etc.

@PeterTaylor Ah, it got more complicated with the diagonal moves, but yes.  :-)  Okay, a preference matrix added, but suggestions welcome if that's not a good one.

Another question: what, if a Beast is directly to the right of the player, and the player moves one up? Should the Beast just move one to the left, because the Beast was calculating with the players start position of this turn? Or should the Beast move left-up? (question according to: then the beasts are given an ordering based on their initial map position)

If I'm understanding correctly, the second example is wrong, because http://pastebin.com/raw.php?i=CqPJPjTR.

@Doorknob: actually the player goes first. So the player moves down first, then the beast chooses it's move, which is to move left and eat the hapless hero. Hmm in that case the third example would be wrong ... Also in the reaper example it should only require three waits to get eaten I think

@Claudiu: the reaper example is in fact wrong... it's only 3 times W (for the beast: L, L-U, U). But the Win example is correct, since the player moves first! So before the beast can do it's second move, the player gooifies the beast! (http://pastebin.com/raw.php?i=47A8Hre7)

@bobbel: Why would the beast move left on its first move? Instead it would move up since that would bring it closer (sqrt 2 distance instead of 2 distance)

@Claudiu: because, like Doorknob also explained, the beast will decide it's next step according to the players initial position of the current turn. This is also, what I guessed that OP meant.

@bobbel: Oh yes, I missed that, my mistake.

@Claudiu Yes, the beasts moving diagonal clarification changed the example... Just 3 waits!  Tx, fixed.

@bobbel Ah yes, sorry, editing on phone.  That'd be correct.  Changed to down-wait as better examples not feasible to type :)

@Dr.Rebmu: generally I like your task very much, but there are many questions to ask for. Thanks for clarifying! So, next: what about this Two-Beast situation: http://pastebin.com/raw.php?i=FENVAkCH Is my assumption correct?

Another question: What if you move a train of walls into a beast that isn't 'pinned down'? http://pastebin.com/raw.php?i=isN4L6pJ

@Claudiu Ahh...you're straining my memory, and the video can't really help with that one since there's no visual way to see the keystrokes.  But I don't think you can push beasts, just crush them.  Let's assume they are walls in that case...clarified.

@bobbel Man, writing questions is harder than solving them!  :-)  I say given the Beasts propensity for not staying still, they will take their next best move if available instead of foregoing their move that turn, if a higher priority Beast took their ideal spot.  Clarified.

Don't worry, to golf this puzzle is a big challenge too. Or who can beat currently about 2,050 bytes? :D  By the way: the output of the last scenario is also: aHHHH!\n0

should 'We all know H is the most merciless letter of the alphabet' not be 'We all know ├┤ is the most merciless letter of the alphabet'?

Perl 6: 741 characters, 758 bytes
The golfed version is at the bottom, since it's basically linenoise. Above it is my pre-golfed version. Both are interactive (they'll read as many commands from the input file as they can and then move on to using STDIN to get commands). They try to use the original characters and colors.
Usage is like perl6 beast.p6 beast-input:
use Term::ANSIColor;
class BeastGame {
    enum BeastParts <None Player Beast M-Wall S-Wall>;

    has @.board;
    has Int $.turn = 0;
    has Int $.score = 0;

    method indices (\matcher) {
        @.board.pairs.map: {
            .key*i X+ .value[].pairs.map: {
                .key if .value ~~ matcher
            }
        }
    }
    multi postcircumfix:<[ ]> (BeastGame \SELF, Complex \c) is rw { SELF.board[c.im][c.re] }

    has Complex $!player;
    method player { $!player = $.indices(Player)[0] }
    method Bool { so $.indices(Player) & $.indices(Beast) }

    method new (@lines) {
        my @board = @lines.map:
            {[ %(' ',<O H ~ #> Z=> None, Player, Beast, M-Wall, S-Wall){ .comb } ]}

        self.bless: :@board
    }
    method gist {
        state @symbol-map = map {colored .key, .value~' on_black'},
            ('  ',<◄► ├┤ ▒▒ ██> Z=> <default cyan red green yellow>);

        @.board.map({ @symbol-map[@$_].join }).join("\n")
    }

    method step ($d) {
        my $direction = %(:W(0), :L(-1+0i), :R(1+0i), :U(-1i), :D(1i)){$d};
        $direction // return self;
        self.move($.player,$direction);

        if ++$!turn %% 2 {
            for $.indices(Beast).eager -> $c {
                for (-1-1i,-1+0i,-1i,1-1i,1+0i,-1+1i,1+1i,1i,0i)\
                        .sort({abs $c + $^d - $!player})
                {
                    last if self.move($c, $_).defined;
                }
            }
        }

        self;
    }
    method move ($cur, $by) {
        return $cur if $by == 0;

        my $to = $cur + $by;
        my &cur-is  = { self[$cur] ~~ $^o }
        my &next-is = { self[$to]  ~~ $^o }
        return if cur-is S-Wall;
        (self[$to], self[$cur]) = (self[$cur], None)
            if next-is None
            # Move wall
            or cur-is Player | M-Wall and next-is M-Wall and self.move($to, $by)
            # Kill Player
            or cur-is Beast  and next-is Player
            # Squish Beast
            or cur-is M-Wall and next-is Beast  and self[$to+$by] ~~ M-Wall|S-Wall and $!score += 2
    }
}
my $width = get.words[1];
my $game  = BeastGame.new(lines[^$width]);
my @commands = '',lines.comb,{$*IN.get.comb}...*;

while $game {
    $game.step: @commands.shift;
    print "\e[2J";
    print "\e[H";
    say $game;
}

say "aHHHH!" unless $game.player;
say $game.score;

The golfed version:
my ($u,$s,$m)=0,0;my@b=lines[^get.words[1]].map:{[%(' ',<O H ~ #>Z=>^5){.comb}]}
my@a='',lines.comb,{$*IN.get.comb}...*;sub g(\c)is rw {@b[c.im][c.re]}
my&n=->\o{@b.kv.map:{$^k*i X+$^v[].kv.map:{$^l if $^w==o}}}
my&p={$m=n(1)[0]}
my&M=->$c,$b{my$t=$c+$b;my&c={$^o==g $c}
my&x={$^o==g $t}
c(4)??0!!$b??(($c,$t)».&g=(0,g $c)
if x(0)||c(1|3)&&x(3)&&M($t,$b)||c(2)&&x(1)||c(3)&&x(2)&&2 <g($t+$b)&&($s+=2))!!1}
while n(1)&n(2) {for 1
{M p,%(:W(0),:L(-1),:R(1),:U(-1i),:D(1i)){@a.shift}//last;if $u++%2
{for n(2).eager ->$c{last if M $c,$_
for(-1-1i,-1+0i,-1i,1-1i,1+0i,-1+1i,1+1i,1i,0i).sort({abs $c+$_-$m})}}}
say "\e[2J\e[H",join "\n",map {[~]
(map {"\e[$^v;40m$^k\e[0m"},'  ',<39 ◄► 36 ├┤ 31 ▒▒ 32 ██ 33>)[@$_]},@b}
say "aHHHH!" if !p;say $s;

Happy Easter!

It's code golf rules, so given that, your solution wins...even if I don't myself like Perl very much.  ;-)  Good work with the console and color!

Java, 1,843
My first try of solving this puzzle with Java.
I know, that there are a lot of improvements to make it shorter. But in the end it works for now.
To try it, you have to create a class C and paste the code.
args[0] (strictly speaking a[0]) is for input. The print method of the map is not included since it's not necessary for the puzzle output.
class C{static char                    [][]C;static int A=
0,B=0,D=0,E=0,F=0,G                    = 0 ; public static
void main(String[]a                    ){String []b= a[0].
split("\n");int c =                    Byte. decode(b [0].
split(" ")[1]); G=a                    [ 0 ] . replaceAll(
"[^H]","").length()                    ; String d = b [ b.
length - 1 ] ;C=new                    char[c][];for(int e
=1;e<b.length-1;e++                    ) C [ e - 1 ]=b[e].
toCharArray ( ) ; f                    ();boolean X= 0> 1;
for ( char  g : d .                    toCharArray ( ) ) {
switch(g){case 'U':                    h(0,-1);break; case
'D':h(0, 1); break;                    case 'L':h( -1, 0);
break;case'R':h(1,0                    );}if(X)i();X=!X;f(
);}System.out.print                    (D);}static void f(
){for(int a= 0;a<C.                    length;a++)for( int
b=0;b<C[a].length;b                    ++)if(C[a][b]=='O')
{A=b;B= a;}}static void h(int x,int y){E =x;F =y;switch(C[
B +y][A +x]){case 'H':g();break;case ' ':j(A,B);break;case
'~':k();}}static void i(){if(G<1){return;}int[][]l=new int
[G][];int m=0;for(int r=0;r<C.length;r++){for(int c=0;c<C[
r].length; c++){if(C[r][c]=='H'){l[m++]=new int[]{c,r};}}}
for(int[]n:l){o(n[0],n[1]);}} static void o(int a, int b){
int[]c=d (a,b);E=c[0];F =c[1];if(E !=0||F !=0){ j(a,b);} }
static int[]d(int a,int b){int[][]d={{1,3,4},{2,0,5},{6,8,
7},};int[]e=new int[]{0,0};double f=999;for(int r=-1;r<2;r
++){for(int c=-1;c<2;c++){if(C[b+r][a+c]==' '||C[b+r][a+c]
=='O'){int g=a+c-A;                    int h=b+r-B; double
i=Math.sqrt(g*g+h*h                    );if(i<f){e=new int
[]{ c,r};f =i;}else                    if(i==f){if(d[r+1][
c+1]<d[e[1]+1][e[0]                    +1]){e=new int[]{c,
r};}}} }}return e;}                    static void k(){if(
p(E,F,false)){q(E,F                    );} }static void q(
int x,int y){switch                    (C[B+y][A+x]){ case
'~':q(x+E,y+F);case                    'H':case ' ':j(A+x-
E,B+y- F);}} static                    boolean p(int x,int
y,boolean h){switch                    (C[B+y][ A+x]){case
' ':return !h; case                    '~':return h?h:p(x+
E,y +F, false);case                    'H':return h?!h:p(x
+E , y+ F, true) ;}                    return h&&C[B+y][A+
x] == '#' ; }static                    void j(int a,int b)
{char c=C[b][a];if(                    C[b+F][a+E]=='O'){g
();}else if(C[b+F][                    a+E]=='H'){D+=2;G--
;c=C[b][a];C[b][a]=                    ' ';}else{C[b][a]=C
[b+F][a+E];}C[b+F][                    a+E]=c;}static void
g () { System .out.                    print("aHHHH!\n"+D)
;     System      .                    exit  ( 0  ) ;  } }

To run it, try for example:
root@host:/cygdrive/c/workspace/project/bin> java C "5 5
> #####
> #O  #
> # ~ #
> #  H#
> #####
> WWDW"
aHHHH!
0
root@host:/cygdrive/c/workspace/project/bin>

Output of the last big scenario one turn before a beast eats the player:
████████████████████████████████████████████████████████████████████████████████
██▓▓            ▓▓  ▓▓▓▓    ▓▓    ▓▓  ▓▓▓▓      ▓▓  ▓▓▓▓        ▓▓  ▓▓  ▓▓▓▓  ██
██▓▓▓▓  ▓▓                    ▓▓▓▓      ▓▓      ▓▓  ▓▓▓▓                  ▓▓  ██
██▓▓██  ▓▓▓▓      ▓▓▓▓▓▓▓▓            ▓▓    ▓▓▓▓▓▓▓▓    ▓▓        ▓▓▓▓▓▓    ▓▓██
██  ▓▓                ▓▓      ▓▓  ▓▓▓▓  ██▓▓▓▓              ▓▓                ██
██▓▓▓▓    ▓▓▓▓▓▓      ▓▓  ▓▓  ▓▓            ▓▓  ▓▓▓▓  ▓▓    ▓▓    ▓▓    ▓▓    ██
██          ▓▓▓▓    ▓▓    ▓▓  ▓▓  ▓▓▓▓▓▓                        ▓▓    ██▓▓    ██
██          ▓▓▓▓    ██    ▓▓▓▓▓▓  ▓▓            ▓▓  ▓▓▓▓    ▓▓    ▓▓  ▓▓▓▓    ██
██              ▓▓  ▓▓  ▓▓▓▓      ▓▓▓▓  ▓▓  ██                ▓▓▓▓      ▓▓    ██
██  ▓▓▓▓                  ▓▓  ▓▓▓▓▓▓    ▓▓▓▓  ├┤  ▓▓▓▓▓▓▓▓            ▓▓    ▓▓██
██▓▓    ▓▓    ├┤◄►▓▓▓▓▓▓├┤  ▓▓      ▓▓                ▓▓      ▓▓  ▓▓▓▓    ▓▓▓▓██
██          ▓▓            ██  ▓▓  ▓▓▓▓    ▓▓▓▓▓▓      ▓▓  ▓▓  ▓▓  ██        ▓▓██
██▓▓  ▓▓  ▓▓▓▓    ▓▓    ▓▓                  ▓▓▓▓    ▓▓▓▓  ▓▓  ▓▓  ▓▓▓▓▓▓      ██
██              ▓▓      ▓▓      ▓▓      ▓▓    ▓▓├┤        ▓▓▓▓▓▓  ▓▓          ██
██  ▓▓▓▓    ▓▓    ▓▓  ▓▓▓▓      ▓▓              ▓▓  ▓▓  ▓▓          ▓▓        ██
██            ▓▓▓▓      ▓▓      ▓▓    ▓▓                  ▓▓            ▓▓▓▓  ██
██▓▓  ▓▓          ██        ▓▓▓▓▓▓▓▓    ▓▓        ▓▓▓▓▓▓        ██  ▓▓        ██
██    ▓▓      ▓▓  ▓▓      ▓▓                ▓▓                    ▓▓▓▓    ▓▓  ██
██    ▓▓      ▓▓          ██▓▓    ▓▓      ▓▓▓▓    ▓▓    ▓▓                  ▓▓██
██  ▓▓▓▓  ▓▓  ▓▓    ▓▓▓▓                                ▓▓      ▓▓            ██
██        ▓▓▓▓▓▓                ▓▓  ▓▓▓▓    ▓▓    ▓▓    ▓▓      ▓▓            ██
██  ▓▓  ▓▓          ▓▓                        ▓▓▓▓      ▓▓      ▓▓    ▓▓      ██
████████████████████████████████████████████████████████████████████████████████

Without silly line spaces: http://pastebin.com/raw.php?i=QhpxKcCT
So the players way is ending after the moves RRDDDRRRWW, because on the last Wait, the beast to the left will go to the right to eat the player.

Another example of the original big map but different moves:
http://pastebin.com/raw.php?i=nBWjC3PZ
See this animation:  http://youtu.be/0DIhEhjWd6s

And the last example with original map and different moves (according to the new beast movement rules):
http://pastebin.com/raw.php?i=NNmgzx7U
See on youtube: http://youtu.be/jXPzL88TU2A

HHHa!  :-)  Very cool.  So long as you've gotten it, care to play a few games and give more test case data on that map?

I've added a new scenario with original map and different moves. But you can't really follow the steps, because I didn't want to paste all 75 steps to pastebin :)

So, I added a video to see the result as an animation!

Good video...though it seems to show the beasts move too quickly to be any fun!  Should we change the rule so they move every other turn instead of every turn?

I don't mind. About ten bytes more for me! But I totally agree. It's hard to win like it is now :)

Okay, I slowed them down in the spec.  They start on the second turn and move on alternating turns after that... oops, now I have to fix the examples :-)

Great! Just one little thing: the win example should be WWRD instead of WRD, because the beast should decide it's next step from each initial position of the second turn of the player, shouldn't it? So the beast will move to the left instead of moving up!

The player's "initial position" on the second turn will still be in the upper left, right?  So the beast's decision is based on where the player was before the R is executed on the same turn it moves on.

Ah.... yes.... you're right! Unbelievable how this makes me crazy :D

Next edit to come up to the new beast movement rules. Also the extra credit change is done ;)    Edit: oh, playable! Okay, I have to go back to my basement ;D

I love the shape -- so great!

Big points here on creativity, the video, and your help in making the question better!  But I did say "code golf rules", so the "accepted" answer needs to be golfed.  :-)  Nevertheless, I've opened a bounty to award you extra points for being awesome... have to wait 24 hours though...

@Dr.Rebmu: Thank you very much for the bounty!! It was a pleasure for me! :) It's really nice that you dug out this cool old game!! I'm sure I would have forgotten this game forever :)

@bobbel I'm very happy you got the bounty, you deserve it :)

aHHH, I see the HHHH: Nice work, bobbel - +1

C - 1004 984 917
Ahh, the beauty of C. Following the spirit of the other answer, I tried to format mine as well :)
I imagine there are still some improvements here and there, but this was really fun to write and golf. The character count includes all necessary spaces and new lines.
#define M(y,x,c) {t[y][x]=32;t[p][q]=c;y=p;x=q;}
   #define E {printf("aHHHH!\n%d",Z);exit(0);}
    #define A sqrt(pow(X-Q,2)+pow(Y-P,2))*30
           #define L (char)(m[s]>>8)
            #define G (char)(m[s])
             #define B(b) if(T==b)
              #define J M(Y,X,79)
               #define T t[P][Q]

r,c,X,Y,H,i,j,k,Z,p,q,P,Q,u,v,s,w,m[99],b[8]={
-1,255,65280,65281,1,511,257,256},t[999][999],
x[99],y[99];main(){char N[99];m[85]=b[2];m[68]
=256;m[76]=255; m[82]=1; scanf("%d %d",&c,&r);
for(;P<r;P++)                    for(Q=0;Q<c&&
scanf("%c",&T                    );T-10&&T-13?
Q++:Q){B(79){                    Y=P;X=Q;}B(72
){y[H]=P ;x[H                    ++]=Q;}}scanf
("%s",N);for(                    ;i<strlen(N);
i++){s=N[i];P                    =p=Y+L;Q=q=X+
G;B(32)J B('~')                  {while(P+=L,Q
+=G,T=='~');B                    (72){u=P+L;v=
Q+G;if(t[u][v]                   ==35||t[u][v]
=='~'){Z+=2;T=                   '~';J}}B(32){
T='~';J}}else                    B(72)E if(r=!r)
for(j=0;j<H;j                    ++){P=y[j];Q=
x[j];if(T-72)continue;v=A;s=0;for(k=0;k<8;k++)
{P=y[j]+(char)(b[k]>>8);Q=x[j]+(char)(b[k]);u=
A;B(32)if((c=v-u+99)>s){s=c;q=Q;p=P;}B(79)E}if
(s)M(y[j],x[j],72)}}printf("%d",Z);}//////////

I tested this with all the sample cases and a few more of mine, and it seems to be working properly. If anyone finds any situation in which it doesn't answer properly, please let me know.
Input is from stdin, and output to stdout. There are no checks for incorrect input. And, it returns the score if the player gets eaten, or if the player is alive after all movements are executed (even if there are still H's around.
Ungolfed version:
#define M(y,x,c) {t[y][x]=32;t[p][q]=c;y=p;x=q;}
#define E {printf("aHHHH!\n%d",Z);exit(0);}
#define A sqrt(pow(X-Q,2)+pow(Y-P,2))*30
#define L (char)(m[s]>>8)
#define G (char)(m[s])
#define B(b) if(T==b)
#define J M(Y,X,79)
#define T t[P][Q]

r, c, X, Y, H, i, j, k, Z, p, q, P, Q, u, v, s, w, m[99], b[8] = { -1, 255,
        65280, 65281, 1, 511, 257, 256 }, t[999][999], x[99], y[99];
main() {
    char N[99];
    m[85] = b[2];
    m[68] = 256;
    m[76] = 255;
    m[82] = 1;
    scanf("%d %d", &c, &r);
    for (; P < r; P++)
        for (Q = 0; Q < c && scanf("%c", &T);T-10&&T-13?Q++:Q) {
            B(79) {
                Y=P;
                X=Q;
            }
            B(72) {
                y[H]=P;
                x[H++]=Q;
            }
        }

    scanf("%s", N);
    for (; i < strlen(N); i++) {
        s = N[i];
        P = p = Y + L;
        Q = q = X + G;
        B(32)
            J
        B('~') {
            while (P += L, Q += G, T=='~');
            B(72) {
                u=P+L;
                v=Q+G;
                if(t[u][v]==35||t[u][v]=='~') {
                    Z+=2;
                    T='~';
                    J
                }
            }
            B(32) {
                T='~';
                J
            }
        } else B(72)E
        if (r = !r)
            for (j = 0; j < H; j++) {
                P = y[j];
                Q = x[j];
                if (T-72)
                continue;

                v = A;
                s = 0;

                for (k = 0; k < 8; k++) {
                    P = y[j] + (char) (b[k] >> 8);
                    Q = x[j] + (char) (b[k]);
                    u = A;
                    B(32)
                        if ((c = v - u + 99) > s) {
                            s = c;
                            q = Q;
                            p = P;
                        }

                    B(79)
                        E
                }
                if (s)
                    M(y[j], x[j], 72)
            }
    }
    printf("%d", Z);
}

Nice!!  Though on @bobbel's input RRRUWWWRRRURWWWWRDRRWWRDWWWWD on the big map, you get 6 while he gets 8.  He made a video, you could perhaps print each step and look for any anomaly...

(noticing of course that I changed the rule to make beasts move every-other-turn when I saw how unplayable the beasts-move-every-turn was...!)

To be honest: I'm not sure, if my solution works 100% properly, too. But it looks like to me :)

@Dr.Rebmu I realized you edited the question around the same time I posted mine. So I just did a quick hack that seemingly worked.  I'll re-check it this weekend and update it. I'll also post a "nice" version so that any errors could be easier to spot by other people as well :)

FWIW I solved this today in Rebol and am getting @bobbel's answer of 8 as well.

@Dr.Rebmu Updated and fixed! :). I actually had two problems. My beasts were moving taking into account the position of the player after it had moved, and the calculation of the distance was just plain wrong! It's giving the proper answer of 8 on the large map, and I checked step by step and it follows the same path as Bobbel's answer

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
All possible permuations in lexicographical order
Given a string of English alphabet characters, write the shortest code to print all possible permuations in lexicographical order without using any language based library.
def function('bca'):
    return all_permutation.

This should return :
abc,
acb,
bac,
bca,
cab,
cba

The code-golf and fastest-code tags are very often not compatible...

The previous question Code-Golf: Permutations didn't impose the lexicographic order, but I think most answers provide it anyway and for those that don't it's a trivial change to call sort.

Its about lexicographical order

Python - 131 129 chars
def g(a,z):
 if len(a)<1:print(z)
 else:
  for i in range(len(a)):g(a[:i]+a[i+1:],z+a[i])
def f(s):
 a=list(s)
 a.sort()
 g(a,'')

Only after coding it I noticed that you wrote both "print" and "return" in the question... my solution prints the permutations, I hope that's alright.

you can combine entire f(s) into g(list(s).sort(),'')

The sort function doesn't return the sorted list... but apparently there's a sorted function that does that, which is great to know.

Python - 83 bytes
p=lambda a,*s:sorted(sum([p(a[:i]+a[i+1:],a[i],*s)for i in range(len(a))],[]))or[s]

Sample usage:
>>> p=lambda a,*s:sorted(sum([p(a[:i]+a[i+1:],a[i],*s)for i in range(len(a))],[]))or[s]
>>> p('abc')
[('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]

Without the sorted call, this narrowly beats out ugoren's answer to the linked question at 75:
p=lambda a,*s:sum([p(a[:i]+a[i+1:],a[i],*s)for i in range(len(a))],[])or[s]

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Shortest code to write longest code
Your challenge is to create a shortest code in your language of choice which writes on a .txt file the longest code to multiply two numbers by taking two numbers as input and output the answer.
NO INPUT NEEDED TO YOUR CODE WHICH IS DOING THE WRITING JOB!
The generator code and generated code can be in any languages
Do NOT use unlimited series or progression to make text file big.
Do NOT use unnecessary statements to increase the score.
SCORING
( size of text file generated in bytes )  (without any unnecessary white spaces, tabs or newlines)
-----------------------------------------
     ( size of your code in bytes )

Winner
Winner will be chosen after 1 week from now with the highest score.
EDIT : range of input in code multiplying two numbers should be in between -32768 to 32767

I eventually figured out, but the fact that you use code formatting for the output made it seem like you were looking for the literal string "the longest code to...".

I think you can just use this answer by Comintern, changing the + to * in the generator program he provides, and you probably already know this, since you answered that question as well.

@Geobits I tried to keep my question away from that answer, but I think the effort is not enough, what should I ask to generate then, so that The question has nothing to relate from other question-answers?

I don't know what you should ask, it just seems like any winner here is going to be eerily similar to the answers there.

@MukulKumar maybe the long code should generate the short code? But don't change this question to that, the change is way too substantial. But it might be an idea for another quine-related challenge (if it hasn't been asked before).

@Geobits how about concatenating two strings?

@m.buettner You got me a nice idea for my next question :)

It's too bad this is /so hard/ in ~-~!, as you can only take multiple inputs to a function via currying but it's insanely hard to put a function inside a function and it'd take thousands of characters to take base 10 input from the console...and it's really bad for compression. Imagine doing this with wires and a battery, then you've got how hard it is to do it in ~-~!.

Can you specify a range? Otherwise many answers will just make arbitrarily large bases and their score will continue to diverge towards infinity. To see why, consider let's say I handle the range MININT..MAXINT, and I have them set to -128 and 127. I could easily increase my score by setting MININT and MAXINT to -32768 and 32767 (orders of magnitude more output code, only 4 more chars in the source), and then again by moving to 32 bit, 64 bit, etc.

possible duplicate of Longest code to add two numbers

I don't understand, are the numbers you want to multiply supposed to be parameters for the original program or the generated program?

@Tal the long program generated by your short program should take input and output answer not the short program.

"Do NOT use unnecessary statements to increase the score. " Would you give an example as to what would qualify as an unnecessary statement?

Also, why write to a .txt file? It's not plaintext, it's code.

@user80551 That is simple, you have to write the longest code in only necessary statements like cout<<"ab/b/b" would display ab then erase them from the output screen making then unnecessary. I ASKED TO WRITE THE LONGEST CODE IN .TXT FILE THROUGH THE SHORTEST CODE!!!

perl/perl, unlimited score under original rule with unlimited range
Here's some code which doesn't win:
$l=-2**5-1;
$h=2**5;
sub p{print@_}
p"sub add {(\$i,\$j)=\@_;\n";
for($i=$l;$i<=$h;++$i){
  for ($j=$l;$j<=$h;++$j){
    p" return ".($i*$j)." if (\$i == $i) && (\$j == $j);\n";
  }
}
p"}print add(<>,<>)\n";

The output has this form:
sub add {($i,$j)=@_;
 return 1089 if ($i == -33) && ($j == -33);
 return 1056 if ($i == -33) && ($j == -32);
 return 1023 if ($i == -33) && ($j == -31);
 return 990 if ($i == -33) && ($j == -30);
...
 return 928 if ($i == 32) && ($j == 29);
 return 960 if ($i == 32) && ($j == 30);
 return 992 if ($i == 32) && ($j == 31);
 return 1024 if ($i == 32) && ($j == 32);
}print add(<>,<>)

the output file is 181030 bytes long, but after stripping spaces and newlines, it is only 133109 bytes long. so, the score is 133109/248 = 536.7289...
Here's some other code that doesn't win - it is the same program except the first 2 lines:
$l=-2**6-1;
$h=2**6;

the output file is 718138 bytes long, but after stripping spaces and newlines, it is only 532233 bytes long. so, the score is 532233/248 = ~2146. better! using 7 yields a score of ~8750, 8 yields ~35347, 9 yields ~149129, 10 yields 151100000 non-space / 250 = 604,400 ....
of course we can do this as long as we want. the size of the source program, n, will increase as O(log(n)). the size of the output program is O(2*n). The limit of 2*n/log(n) as n goes to infinity is clearly infinity, so if I just substitute in my favorite large number, a googolplex, I win (until someone suggests googolplex+1).

What is the kind of output ? like you may give first non-repetitive lines.

First time I could actually read Perl. It generates a function named add which takes two parameters. It then populates that function with return statements looking like return 39 if ($i == 13) && ($j == 3);, using all values from $l to $h for $i and $j. Smartass bending of the "only unnecessary statements" rule.

Mukul, I edited the answer to include some sample output.

@skibrianski well that's finite then, because the value the variables i,j can hold are finite. But, quite large.

Mujul. Finite, but unlimited. Give me any number and I can choose a larger size output (or score) by simply adjusting those variables.

@skibrianski to get user's attention you should use @ character before the name. and please show me how would you multiply 99999^(99999) to itself through your generated program.

@MukulKumar, like any other combination of numbers, you simply go down the list until you get to the case for $i == $BIGNUM && $j == $BIGNUM. According to Wolfram Alpha, 99999^99999 < 2^1660946 ( wolframalpha.com/input/?i=99999%5E99999+%3C+2%5E1660946 ). So, simply replace the first two lines with: $h=21660946; $l=-21660946-1; and you'll output a program that can deal with 99999^99999.

C, 27297/245 = 111.4
Source code (245 bytes)
#include<stdio.h>
main(int c,char**v){char*s;FILE*f=fopen("/tmp/x.c","w");fprintf(f,"#include<stdio.h>\n#include<stdlib.h>\nmain(){int a=%s,b=%s;printf(\"%s * %s = %%d\\n\",a*b);}",v[1],v[2],v[1],v[2]);fclose(f);system("cc -E /tmp/x.c >add.c");}

When compiled and run with two integer arguments on the command line, this generates another C file containing the necessary code to calculate their product, and compiles it with the -E flag. This flag specifies that the compiler should stop after the preprocessing stage and output the processed source code (which will include the entire contents of stdio.h and stdlib.h).
Output file (27297 bytes)
# 1 "/tmp/x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/tmp/x.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 64 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/_types.h" 1 3 4
# 27 "/usr/include/_types.h" 3 4
# 1 "/usr/include/sys/_types.h" 1 3 4
# 32 "/usr/include/sys/_types.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 33 "/usr/include/sys/_types.h" 2 3 4

********* LINES 13-1273 OMITTED *********
long long
  strtoq(const char *, char **, int);
unsigned long long
  strtouq(const char *, char **, int);

extern char *suboptarg;
void *valloc(size_t);

# 3 "/tmp/x.c" 2
main(){int a=6,b=7;printf("6 * 7 = %d\n",a*b);}

Result of running the output code
The output file is saved as add.c, which can be compiled and run normally:
$ ./a.out 6 7
$ cc add.c -o add
$ ./add
6 * 7 = 42
$

perl, 125 chars, score 1,630,326,497.312
Same basic approach as my other answer, but this time bounded between -32768 and 32767 per the updated rules, and all unnecessary whitespace stripped completely:
$l=-($h=32767)-1;print"sub a{";for$i($l..$h){print"return ".$i*$_." if\$_[0]==$i&&\$_[1]==$_;"for$l..$h;}print"}print a<>,<>"

The output program begins like so:
sub a{return 1073741824 if $_[0]==-32768&&$_[1]==-32768;return 1073709056 if $_[0]==-32768&&$_[1]==-32767;

and ends:
return 1073643522 if $_[0]==32767&&$_[1]==32766;return 1073676289 if $_[0]==32767&&$_[1]==32767;}print a<>,<>

The output program is 190GB long. More precisely, 203790812164 bytes. Score = 203790812164 / 125 = 1630326497.312

Windows Command Script: ~1,000,000,000 pts
Code:    158 bytes
Output: ~158000000000 bytes
echo>.txt @goto :%%1_%%2
set,=for /l %%a in (-32768 1 32767) do call :
%,%1 %%a
:1
%,%2 %1 %%a
:2
set/a]=%1*%2
echo :%1_%2>>.txt
echo @echo.%]%^&exit/b0>>.txt

The output pretty much consists of:
@goto :%1_%2
:-32768_-32768
@echo.1073741824&exit/b0
:-32768_-32767
@echo.1073709056&exit/b0
...
:32767_32767
@echo.1073676289&exit/b0

Python, 142 bytes
c='def m(a,b):\n'
L=32768
a=-L
while(a<L):
 b=-L
 while(b<L):c+=f' if a=={a}and {b}==b:return {a*b}\n';b+=1
 a+=1
F=open('c.txt','w')
F.write(c)

Score unknown for the moment, but I think it's more than a billion. Nope, probably just below a billion.
Score update
The program has a minimum length of 111669149696 or about 111 billion. This means that the minimum score of this answer is roughly 780 million.
It also has a maximum length of roughly 150 billion, which indicates that the score is between 730 and 1050 million. My score is most likely in the middle of that range, i.e. about 890 million.
Basically writes a function m to a file c.txt using two while loops.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/