Closed Thread Icon

Topic awaiting preservation: October 20lines Javascript Contest - A.I. - Entries (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23519" title="Pages that link to Topic awaiting preservation: October 20lines Javascript Contest - A.I. - Entries (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: October 20lines Javascript Contest - A.I. - Entries <span class="small">(Page 1 of 1)</span>\

 
BillyRayPreachersSon
Bipolar (III) Inmate

From: London
Insane since: Jul 2004

posted posted 10-02-2004 18:55

This month's theme is: A.I. (Artificial Intelligence )
You can make anything you like, as long as it has some sort of A.I. engine.
It could be a game of noughts-and-crosses, chess, "Attaxx" (classic arcade game), an Eliza-type program, or general A.I program.

The entries belong in this thread, the comments in thread October 20lines Javascript Contest - A.I. - Comments

quote:
a code monkey said once:
As usual, the main rule is to make your script in 20 lines of (effective) code.
Comas shouldn't be used to execute several instructions on the same line
See the code sample below to illustrate the basic rules :

code:
<script type="text/javascript">

/* */ document.body.onclick = function()
/* */ {
/* 01 */ val = prompt( 'enter a number' );
/* 02 */ for( i=0; i<10; i++ )
/* */ {
/* 03 */ alert( stupidFunction( val, i ) )
/* */ }
/* */ }

/* */ function stupidFunction( a, b )
/* */ {
/* 04 */ return a>b?a:b; // I said it was a stupid function
/* */ }

</script>



The document.body.onclick = function() does not count as a line as it's not some effective code and the function call could be put in the BODY tag ( or anyother HTML tag ).
The declaration of the stupidFunction() does not count either for the same reasons.
The coma in the line /* 03 */ is ok, since it simply separates the parameters of a function.




(Edited by BillyRayPreachersSon on 10-02-2004 18:55)

BillyRayPreachersSon
Bipolar (III) Inmate

From: London
Insane since: Jul 2004

posted posted 10-08-2004 13:48

I think I've realised how tricky a lot of AI implementations seem to be, so was quite happy when I found something I could do in 20 lines . It's a conversion of a program I wrote at the beginning of last year for an online MUD (Multi User Dungeon) game I play occasionally, called Storms of Time.

In the game, the Griffons run the Griffon Bank and Travel Company, whose subsidiary company, Griffon Airlines, is resonsible for flying punters from one Griffon Airport to another (you climb on their wings for the duration). All very in keeping with the whole role-playing / D&D / fantasy scene

There are 16 airports, with a pre-determined "map" of how they link together (much like airports IRL, which fly set routes to certain destinations). Flights cost different amounts, depending on the route chosen (how many 'hops'). This made the job of building a route planner the perfect task. And as pathfinding is a subset of AI, I felt it was fitting to convert my old 2003 code into 20 lines for 2004

I wrote the orignal in JS by following a tutorial on Dijkstra's pathfinding algorithm (with some VB snippets). It was surprisingly easy, as the tutorial was extremely well-written. After a few tweaks, it worked pretty much straight away.

Anyway - getting the original code (236 lines all up) down to 20 lines was not an easy task. It took many hours, but was good fun, and quite enjoyable (going over old code is always fun - I think seeing how you have learned from your mistakes is always beneficial).

The code is here: http://www.soterm.com/dan/griffonRoutePlanner.html

There are more details on the page about the original version, and the MUD, should you feel like passing some time by killing a few nasties!

Incidentally, the final route will be te cheapest route, not necessarily the shortest. I felt saving gold coins was far more important than a few seconds of travel. You can see the flight costs in the data section at the top of the code.

Enjoy!

Dan

shingebis
Nervous Wreck (II) Inmate

From: UK
Insane since: Aug 2004

posted posted 10-12-2004 00:03

Still on the path-finding theme , but path-finding of a slightly different sort...

CheeseMaze

I believe I've managed to condense it into 4 lines of Javascript while still following the contest rules, with the algorithm itself embedded in a single-line 'for' loop approximately 1320 characters long.
I haven't actually removed all the extra line breaks to make it really 4 lines long, but hopefully nobody will have any problems taking that as read, and I figured that this way would be more useful should anyone want to try reading my code...

Oh, and it works perfectly in both Mozilla and IE for a change

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 10-31-2004 11:36

Here's my first real entry.

www.geocities.com/therulers3000/fish/fish.htm

It's a flocking AI (or rather AL, as in Artificial Life.) designed to simulate fish behaviour.

I was going to write my own algorithm for this but I ran out of time because of school...
So instead I found a functioning JS implementation of a flocking algorithm and reduced it to 20 lines.
I added some new stuff like the sprite handler and I thought about making the fish avoid the top
and bottom of the fishbowl but I decided to leave that as it is. It makes the enviroment less realistic but
it becomes easier to see when the fish try to stick together.

/TwoD

Schitzoboy
Maniac (V) Inmate

From: Yes
Insane since: Feb 2001

posted posted 10-31-2004 18:50

Cool stuff guys, maybe with a bit more practice with JS I'll put in an entry this round or next. TwoD, yours doesn't seem to work in firefox

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 10-31-2004 23:04

Ok, I've uploaded a new version with support for FireFox (and possibly some other browsers).
Had to use the 0*isNaN() workaround to keep line 16 on one line but I hope you forgive that considering the extended support
Oh btw, Schitzoboy, comments go in the Name of the contest - Comments thread.

/TwoD

« BackwardsOnwards »

Show Forum Drop Down Menu