Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question trying to make my character automatically leave a maze (javascript)

    im stuck.. im trying to make my character 'john' automatically leave the maze (sticking to the right wall the whole time) and stopping at object 1(the beeper) at the end of the maze. i need help with the script... i want him to do the whole thing automatically. i sketched out a design to explain what i mean in detail. this is the core idea -

    ![alt text][1]


    [1]: /storage/temp/20377-ye.png

    some main commands are:

    turnRight, frontIsClear, rightIsClear, turnLeft, nextToABeeper, move



    i know i have to use 'if' and 'while' commands, for example:

    Code:
    while(!john.nextToABeeper())
    john.move();


    ..thanks!

  • #2
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh crap..
    sorry the image didn't paste. it's basically a sketch of a maze, with a beeper at the end and a robot at the beginning. he needs to the right wall and find his way to the beeper at the end

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,076
    Thanks
    23
    Thanked 592 Times in 591 Posts
    @crysiq, your rat has the wall on his right. So he either moves forward or turns left. If the wall disappears from his right (an opening) he turns right.

    He first checks to the wall on the right and then to the front. and moves accordingly and then repeats his look-ahead to determine his next move.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •