Coding Examples

No rights reserved. Any part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise.

The moral right of the author to actively disclaim any and all ownership of this work has been asserted in accordance with the principle that intellectual property is theft, and that the newfangled notion of copyright has merely opened the floodgates of tawdry sensation-mongering in the form of 'penny dreadful' airport "thrillers", turgid and formulaic romantic fiction and vacuously aspirational "celebrity lifestyle" dross.

Feel free to use/abuse/modify/claim authorship/earn money from (unlikely!)/do absolutely anything you like with any or all of these modules. The devising and writing of them was my reward, and now I give them freely to any who want them.

An example of a small complete bot. New arrivals at the Forge often ask if they can examine a bot 'from the inside', to get a feel for what a developed bot looks like, so here is one to examine.
It's not a fully-rounded personality (it's one of the confessorbots from BJ's church in Second Life,) but exhibits a number of standard bot-building strategies and Forge features (regexes, memories, seeks, etc.) which may be useful for aspiring botmasters.

Level 1 of a text adventure game, in the style of the Infocom classics of my youth. The Forge is not the ideal development environment for such games (though with the addition of a gosub command and better variable handling, it would be pretty nearly ideal!) but it's quite possible to come up with some engaging and entertaining proglets with a little effort (whether Zany Adventure falls into that category, I leave to your judgement!)

Teach your bot to play unbeatable tic tac toe!
Teach your bot to play Tic Tac Toe Only half finished (bot plays X). Bot playing 0 and a responder plug-in for inter-bot play coming soon (that'll be very dull actually - they'll always draw. Unless I sabotage the release version :)
The code listing is in plain text (or the html codes wouldn't show up - DOH!) with a few notes (it ain't rocket science, just seeks.)

UPDATE: I have added a more complete listing of "robusticized" code, which will avoid the game aborting in the event of a comment or erroneous/invalid move being entered, but will instead prompt and ask the user if they really want to stop. It is available in plain text or as it appears in the web interface
You can't directly import this version of the game, since it relies on numeric gotos that will necessarily be different for each bot. And you will gain a better understanding of the principles involved if you "robusticize" the code yourself anyway.
The technique is to add an xnomatch to each seek, prompting "Was that a move? Sorry - I didn't recognize it. Did you want to stop playing the game?" (you'll have to change that slightly to avoid the duplicate response error, of course.) A further seek feeds back to the last game board using a goto, or xnomatches to leave the game.
I have also added a seek to each game board for all moves that have already been played - this does not prompt, but merely reloads the board to await a valid move.

Give the square root of any number under 1 million (including decimals). Without the need for 1 million lines of code!
OK here's the brief. How do you make a bot answer the question "what is the square root of x", when x is any number under 1 million? And you're not allowed to use a million lines of code. A practical demonstration of the power of regular expressions. Given that it can handle decimals of any length, a practically infinite number of lines of code would actually have been necessary without regex.

ditto for cube roots
Ditto for cube roots. Not complete yet (sorta ran out of steam and got distracted by the poker :) which makes for rather more intelligible code if you want to examine it.

How many days till Christmas? An example of how your bot can count down to a date. Pretty simple stuff, but hopefully of interest to someone.

Coming Soon!
My own PF-version is on indefinite hold, since I found a way of cramming a fully featured javascript version into Brother Jerome. He can also play Blackjack, Chess and Crab Race, as well as offering single-player versions of Solitaire, Breakout and Soul Stealers of the Apocalypse an ASCII Space Invaders clone.