Wolfenstein 3D? in 1K of JavaScript

Started by Mr. Analog, October 20, 2010, 08:42:03 AM

Previous topic - Next topic

Mr. Analog

Rather impressive technical feat:

Quote
QuoteWOLF1K features a 32?32 map ( a 1024 cells grid ) with textured walls colored by orientation ( North, South, East, West ), fog, 3 transparent bitmap graphics in 8?8, 15 rainbow characters steering smoothly across the map, collision detection, probably the most crazy optimization tricks I ever wrote.

In order to get this into 1K some crazy things had to be done:

QuoteWOLF1K works exactly like the original Wolfenstein 3D and Wolf 5k. It is using the raycasting technique. The world is built from a uniform grid of walls and corridors. In order to draw the world, a single ray is traced for every column of screen pixels and a vertical slice of wall texture is selected, scaled and colored according to where in the world the ray hits a wall and how far it travels before doing so.
The sprites and graphics are stored in a small space using a clever trick:

QuoteThe world of WOLF1K is a regular grid of 32?32 cells. Obviously storing these 1024 cells in one byte or one bit each is not feasible. It would use the 1024 bytes or 128 bytes if stored as bits. It actually is the result of a binary operation applied to the ASCII codes of the source code of WOLF1K plus a mural on each edge of the world.

http://ajaxian.com/archives/wolfenstein-3d-in-1k-of-javascript
By Grabthar's Hammer

Darren Dirt

#1
http://js1k.com/home


the idea brings back fond memories of me grinding out version 27.9.3 of Script Squisher for the 5k contest... I remember being amazed at some of the creative stuff people came up with during that contest, a few actually-fun puzzle games from what I remember.

http://www.the5k.org/ (hey look now it's a "10k" contest! http://10k.aneventapart.com/ and some pretty impressive entries, for example http://10k.aneventapart.com/Entry/416 )


update: omg it's amazing enough to scrunch cool code into 10k or 5k or 1k... but how about putting a GAME into a FavIcon??? http://www.p01.org/releases/DEFENDER_of_the_favicon/
_____________________

Strive for progress. Not perfection.
_____________________

Darren Dirt

#2
HOLY @%&# I suck at Chess.

http://js1k.com/demo/750

I couldn't even beat the damn AI. Same goes for other people: http://malevolent.com/weblog/archive/2010/09/07/1k-chess-showdown/

_____________________

Strive for progress. Not perfection.
_____________________

Mr. Analog

By Grabthar's Hammer

Thorin

Nice games.

Quote from: Darren Dirt on October 20, 2010, 01:43:28 PM
Chess .. http://js1k.com/demo/750

I beat it by following a simple points strategy (give up lower-point pieces to take higher point pieces).  Also, it wouldn't let me castle.  Pretty cool for 1k of code, though!
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Darren Dirt

#5
Quote from: Thorin on October 21, 2010, 10:47:58 AM
Nice games.

Quote from: Darren Dirt on October 20, 2010, 01:43:28 PM
Chess .. http://js1k.com/demo/750

I beat it by following a simple points strategy (give up lower-point pieces to take higher point pieces).  Also, it wouldn't let me castle.  Pretty cool for 1k of code, though!

no castling or http://en.wikipedia.org/wiki/En_passant .


I suck at Chess because I'm one of those guys willing to go "bishop-for-bishop" or even "rook-for-knight"* early on, so I have less pieces to think about... but too often I miss where opponent has 2 different ways of hitting me and I dodge one of them, once I'm down a single power piece I've got no patience to plan my recovery :)

I glanced at the code, I have NO idea how it does any kind of "strategy", it seems to focus on pawn advancing, rarely moves other pieces unless I've been stupid enough to leave myself open for an unbalanced sacrifice... but I guess it's pawn placement fortifies the other pieces, that's what kept killing me (I tried 3 games, all under 10 minutes, but still, I tried THREE times :facepalm: )



*I've always been wrong about "points", over-valuing knight and under-valueing rook, oops: http://en.wikipedia.org/wiki/Chess_piece_relative_value
_____________________

Strive for progress. Not perfection.
_____________________

Darren Dirt

Quote from: Thorin on October 21, 2010, 10:47:58 AM
I beat it by following a simple points strategy (give up lower-point pieces to take higher point pieces).

lol DAMMIT!

image URL says it all...
http://img638.imageshack.us/img638/4969/omgsrslyisosuckatchess.png
_____________________

Strive for progress. Not perfection.
_____________________

Thorin

Uhh...  I guess we just remember where the pieces are?
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Mr. Analog

Quote from: Thorin on October 22, 2010, 12:12:42 PM
Uhh...  I guess we just remember where the pieces are?

Finally someone has programmed mental chess!
By Grabthar's Hammer

Thorin

Quote from: Mr. Analog on October 22, 2010, 06:05:18 PM
Quote from: Thorin on October 22, 2010, 12:12:42 PM
Uhh...  I guess we just remember where the pieces are?

Finally someone has programmed mental chess!

I used to be good at mental chess but after 40 moves I lost track of where his bishop was and lost my queen :(
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Darren Dirt

Quote from: Thorin on October 22, 2010, 12:12:42 PM
Uhh...  I guess we just remember where the pieces are?

Your computer's fonts are doing it wrong.

edit: I mean your BROWSER'S fonts. Cuz I just tried at home, Chrome and FF = fine, IE = not so much (i.e. same result as your Difficult Chess screenshot). :shrugs:
_____________________

Strive for progress. Not perfection.
_____________________

Thorin

I first saw it in Chrome, then checked it in Firefox and IE.  I screenshotted in case it was fixed later.  Later, it was indeed back to normal.  I do realize that sometimes things are different in different browsers, and I do know to test in multiple browsers. 
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Darren Dirt

Quote from: Thorin on October 23, 2010, 06:39:08 PM
I first saw it in Chrome, then checked it in Firefox and IE.  I screenshotted in case it was fixed later.  Later, it was indeed back to normal. 

weird.
_____________________

Strive for progress. Not perfection.
_____________________