Recreate a 'Snake' game in a console/terminal Games are fun

this codegolf here was so fun I had to make a version for other classic games similar in complexity. Shortest Way of creating a basic Space Invaders Game in Python

This time, however, try to recreate the classic 'Snake' game, in which you start out as a small shape, constantly moving to collecting pieces to increase your score. When you collect a piece, your 'tail' grows, which follows the path you have made. The objective is to last the longest without crashing into your own tail, or into the walls 

Qualifications:


You, the characters that make up the tail, the walls, and the pieces you collect should all be different characters
show an HUD with the score. The score increases by 1 point for each piece you collect
The player loses when they collide with their own tail or the wall
a piece spawns in a random area immediately after a piece is collected, not to mention at the start of the game
Speed of the game doesn't matter, as long as it is consistent
The 'cells' should be 2x1 characters, since the height of block characters is ~twice the width Can be 1x1, because 2x1 is just ugly and I didnt really think of that
The keys for changing the direction should be awsd, left, up, down, right respectively
the starting direction should always be up
You must show the edges of the wall. The score may overlap the wall


Shortest code that meets the above criteria wins. Imaginary Bonus Points for creativity
JavaScript (553 512 bytes)

Link to playable version


c=0;a=b=d=-1;e=[f=[20,7],[20,8]];i=Math.random;~function n(){if(c&amp;&amp;(87==a||83==a
))c=0,d=87==a?-1:1;if(d&amp;&amp;(65==a||68==a))d=0,c=65==a?-1:1;p([j=e[0][0]+c,k=e[0][1
]+d])||!j||39==j||!k||10==k?b+=" | GAME OVER":(e.unshift([j,k]),p(f)?(f=[1+38*i(
)|0,1+9*i()|0],b++):e.pop());for(m=h="";11&gt;h;h++){for(g=0;40&gt;g;g++)l=g+","+h,m+=
!g||39==g||!h||10==h?"X":e[0]==l?"O":p(l)?"*":f==l?"%":" ";m+="\n"}x.innerHTML=m
+b;!b.sup&amp;&amp;setTimeout(n,99)}();onkeydown=function(o){a=o.keyCode};function p(o){
return e.join(p).indexOf(p+o)+1}


I tried to make it output to the real console at first (with console.log and console.clear), but it was flickering too much, so I put it into console-like HTML. It will work with this:

&lt;pre id=x&gt;


Also I implemented it with 2x1 cells first, but it just looked worse than 1x1. That would be a minor change though.

Uses awsd keys on keyboard.

Update:

I was able to cut it down to 512 (exactly 0x200) bytes by improving the tail search and doing some more magic.

You now get 2 points when a piece spawns in your tail (it's a feature). I also fixed the overlapping when the snake bites itself.