-- *********************************************************************** -- * * -- * PIXELBOT.E The Happy Hippy (C) 1998 * -- * * -- *********************************************************************** constant VERSION = 1.02 -- DO NOT CHANGE THIS VALUE OR CODE WON'T RUN ! -- *********************************************************************** -- * * -- * Description : A Demonstration Euphoria Pixel Bot Program * -- * Version : 1.02a - 26th November 1998 * -- * * -- * Filename : pixelbot.e * -- * Source Code : Euphoria 2.00 * -- * * -- * Author : The Happy Hippy * -- * Copyright : The Happy Hippy (C) 1998 * -- * Contact : hippy@psynet.net * -- * * -- * Licence : You are granted the free right to use the code * -- * within this file as the basis of any Pixel Bot * -- * that you are designing providing that you do not * -- * use the code exactly as it is without including * -- * all comments in their original format. * -- * * -- * You may modify this code and comments as you wish * -- * and may use it as the basis of any Pixel Bot code * -- * that you develop free of charge and royalties. * -- * * -- * Trademarks : See http://www.psynet.net/hippy/pixelbot.htm for * -- * details of Copyright and Trademark assignments. * -- * * -- * Y2K Issues : This code does not use dates for any purpose and * -- * is therefore, by default, millennium compliant. * -- * * -- * For further information about the Euphoria Pixel Bot project * -- * please look at http://www.psynet.net/hippy/pixelbot.htm * -- * * -- * For further information about the Euphoria language please look * -- * at http://members.aol.com/FilesEu * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * KNOWN BUGS * -- * * -- * None * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * RELEASE HISTORY * -- * * -- * 1.02a 26 Nov 1998 Parent will step onto exit point if it * -- * is found ( or it won't ever win ! ) * -- * * -- * 1.02 12 Nov 1998 The code format has been changed so it * -- * is easier to find the code amongst the * -- * comments. * -- * * -- * Version control added; see arena.ex * -- * * -- * 1.01 09 Nov 1998 Changed to match API Specification 1.01 * -- * * -- * Clone_This_Pixel_Bot() renamed to * -- * Create_Clones(). Clone() renamed to * -- * Clone_Number(). * -- * * -- * 1.00 09 Nov 1998 First public release * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * NOTES * -- * * -- * 1) Do not specify any variables, functions or routines as * -- * 'global'. * -- * * -- * 2) Do not change the names of the 'Initialize' or 'MyPixelBot' * -- * routines unless the references to them in the Registration * -- * section are also changed. You can actually name these * -- * routines anyway you want as long as there is no conflict * -- * with any Euphoria reserved names or the API routine names. * -- * * -- * 3) The 'Initialize' routine must be present and registered * -- * even if it does nothing. * -- * * -- * 4) The 'MyPixelBot' routine must exit to allow the arena * -- * program to let other Pixel Bot's have their turns; you must * -- * not stay in the routine or the whole program will hang. * -- * * -- * You should not use very complex, time consuming actions in * -- * the routine as this will slow down the entire execution of * -- * the arena program and is against the spirit of the Pixel Bot * -- * Project; if the Pixel Bot needs to build up a complex data- * -- * base for itself it should do this incrementally on each of * -- * its turns or just once, the first time the execution routine * -- * is called. * -- * * -- * 5) Don't forget to change the name of your Pixel Bot in the * -- * 'constant PIXEL_BOT_NAME =' definition below. This must * -- * always conform to the Pixel Bot Naming Convention. * -- * * -- * 6) If you clone this Pixel Bot you can use the Clone_Number() * -- * function to determine which of your Pixel Bot's is being * -- * executed; this will be necessary if each requires its own * -- * local data storage. * -- * * -- * 7) When blocked; be careful that you do not get stuck in a loop * -- * that you cannot get out of if blocked on all four sides - * -- * this will bring the arena program to a halt. * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * NAMING THIS PIXEL BOT * -- * * -- *********************************************************************** -- This Pixel Bot must be given a name that conforms to the Standard -- Pixel Bot Naming Convention. -- The name may be a free form text string that can include spaces. It -- should not include any non-printable characters or any white-space -- characters other than the space character itself. Opening and closing -- square brackets ( [ and ] ) should not be used except that any of the -- following may be specified ... -- [FRIENDLY] Will not attack without provocation -- [HOSTILE] Will attack even when not provoked -- [ARENA] Created by the arena program - Do not use ! -- These character sequences should be specified in upper-case, without -- any white-space characters at the start of the Pixel Bot's name and -- there should be no white-space characters between each sequence used. -- The hash ( # ) character should not be used as this is used by the -- arena program to uniquely name Pixel Bot's when they are cloned. -- This Pixel Bot exhibits hostile behaviour ... constant PIXEL_BOT_NAME = "[HOSTILE] hippy@psynet.net - Demo Pixel Bot" -- *********************************************************************** -- * * -- * DATA USED BY THIS PIXEL BOT * -- * * -- *********************************************************************** -- Any data that this Pixel Bot needs to use or remember between -- executing each of its goes should be stored here. -- This Pixel Bot doesn't require any such data. -- *********************************************************************** -- * * -- * INITIALIZATON ROUTINE * -- * * -- *********************************************************************** -- The Pixel Bot should initialize any data that it is going to use -- when taking its turn in this routine. Even if no data is used this -- routine must still be present. -- The routine will be called once before the arena program starts -- executing the Pixel Bot's controlling program. -- The Pixel Bot should not make any calls using the Pixel Bot API -- other than to determine or change its direction using Facing() -- and Turn_Left() or Turn_Right(). Movement is inhibited and -- firing the laser will achieve nothing except to discharge the -- laser and make it unusable for a period of time. The Look() and -- Scan() functions will not return any useful information. procedure Initialize() -- No local data storage used end procedure -- *********************************************************************** -- * * -- * LOCAL FUNCTIONS AND PROCEDURES * -- * * -- *********************************************************************** -- Any local procedures that need to be used during the execution of the -- Pixel Bot's Execution Routine should be placed here. -- This Pixel Bot, when it wants or needs to change direction will turn -- either left or right; there's a 50% probability of either. We create a -- routine to make this easier ... procedure Turn_Left_Or_Right() -- Turn Left or Right if Percent(50) then -- 50% chance of left Turn_Left() -- So turn left else -- Otherwise Turn_Right() -- Turn right end if end procedure -- and that's it; done -- This is part of the Go_Berserk() routine. If we are going berserk; -- we shoot at any Pixel Bot we can see then turn left. Providing -- this routine is called four times, the Pixel Bot will have spun -- round back to where it was facing having possibly attacked another -- Pixel Bot in the process. procedure Attack_Then_Turn() -- Try an attack if Look(AHEAD) > 0 then -- Pixel Bot ahead Fire_Laser() -- Attack it end if Turn_Left() -- Turn left end procedure -- We are going to go bereserk and attack anything we can find in -- range. We call the Attack_Then_Turn() routine four times so that -- we end up facing the same way as we were travelling before. procedure Go_Berserk() Attack_Then_Turn() Attack_Then_Turn() Attack_Then_Turn() Attack_Then_Turn() end procedure -- *********************************************************************** -- * * -- * EXECUTION ROUTINE * -- * * -- *********************************************************************** -- The following routine defines the Pixel Bot's behaviour when -- it executes its go. -- The routine is executed once and only once every go and this -- Pixel Bot will sieze control from the arena program whilst -- it is running; the Pixel Bot must relinquish control to the -- arena by returning from the routine when it has done whatever -- it needs to do. -- The simple Pixel Bot described here exhibits the following -- behaviour ... -- If the Pixel Bot has been damaged; it will shoot at anything that -- it can see, otherwise it exhibits a more rational behaviour. -- If we are the parent and the exit point is in front then keep going -- that way until we get there. We don't let clones look for the exit or -- they will cluster and stop the parent getting there. -- If there's another Pixel Bot in front and we have the laser -- charged up over 50% then attack it. -- if we can go forward then keep going forward but we may take -- a random change of direction every now and again if we are the -- only Pixel Bot of this type or one of the first ten clones. -- if we can't go forward then turn left or right and go off in -- that direction. procedure MyPixelBot() integer found if Damaged() then -- Damaged, can't move Go_Berserk() -- so go berserk ! else found = Look(AHEAD) -- What's ahead ? if found = EXIT_POINT and -- The exit Clone_Number()=0 then Move_Forward() -- Head towards it else if found > 0 then -- Pixel Bot in front if Laser_Power() > 50 then -- Laser well charged Fire_Laser() -- So fire laser end if end if -- Then deal with moving if not Blocked() then -- Can go forward if Clone_Number() <= 10 then -- One of first 10 clones if Percent(10) then -- 10% chance of turn ... Turn_Left_Or_Right() -- So turn left or right end if end if -- Then ... Move_Forward() -- Move onwards else -- Can't go forward Turn_Left_Or_Right() -- Turn left or right Move_Forward() -- And move off again end if end if end if end procedure -- Relinquish control -- *********************************************************************** -- * * -- * REGISTERING THIS PIXEL BOT * -- * * -- *********************************************************************** -- In order that the arena program can initialize each Pixel Bot and -- allow each to have a go in turn; it is necessary to register both -- the initialization and execution routines used by this Pixel Bot -- and the Pixel Bot should also be given a name using the standard -- Pixel Bot Naming Convention. -- -- Registration must be done in the following order or the arena -- program will crash ... Register_Init(routine_id("Initialize")) -- Initialization call Register_Exec(routine_id("MyPixelBot")) -- Execution call Register_Name(PIXEL_BOT_NAME) -- Name the Pixel Bot Register_Vers(VERSION) -- Register version -- After you have registered this Pixel Bot you can create more than one -- Pixel Bot that uses the same Pixel Bot algorithm ... Create_Clones(99) -- Create lots of clones -- Once all the Pixel Bots included in the arena program have been -- registered; the arena program will call the initialization procedure -- for each Pixel Bot in turn and will then make calls to the execution -- routines of each Pixel Bot until the program is terminated. -- Each Pixel Bot will get the same number of goes at executing as every -- other but there is no guarantee as to the order that Pixel Bot will -- get its turn. Any Pixel Bot that has been attacked will be given the -- priority of execution so that it can take avoiding or retaliatory -- action as soon as possible. This does not however mean that a Pixel -- Bot cannot be attacked a number of times between goes. -- *********************************************************************** -- * * -- * END OF THIS PIXEL BOT'S DEFINITION * -- * * -- ***********************************************************************