Solving a maze with 4 exits from the inside

Hi, I'm working on an algorithm that solves a maze from the inside, and seeks out 1 of the 4 exits on the sides, and after getting 1, it goes to the next until it has them all. The maze is always 22x22, and you only have 400 steps. I asked my teacher about using a recursive method to solve it, and he said that is probably the best way to go. But, the catch is that you don't know where the walls are, and they change every time. The rat (I'm trying to get a rat to all four exits) starts in the 4x4 box in the middle that has between 1 and 5 exits (it's different every time a maze is generated). The rat can see how far away a wall is, and you are allowed to store the positions in an array if you wish. He can also build walls and get his current x and y position.
Here's an example of what a maze looks like:
http://farm4.static.flickr.com/3528/3201086335_4556d4aed7_o.jpg
I think that's everything, any help would be greatly appreciated =]

code continued...
    // recursivly find the best path-of-travel
    public int[] recursePath()
        // if in an exit, kill the recursion process
        if(x==0||x==21||y==0||y==21) {int[] bestPath = new int[1]; return bestPath; }
        // x- and y- counters are to signify how many units in each direction
        // from the current real x, y that the algorithm is at
        int curX = x+xCounter;
        int curY = y+yCounter;
        // the maximum number of moves = the closestExitRange, plus however
        // many fewer/extra moves are needed so it lands EXACTLY on the exit,
        // minus the number of places generated so far.
        moveCount = closestExitRange + neededExtraMoves - spacesMoved;
        // give the bestPath a length if it is the first time running algorithm
        if(spacesMoved==0) bestPath = new int[moveCount];
        while(spacesMoved<moveCount)
            // if the algorithm will not land in an exit in EXACTlLY
            // x number of moves, edit x acordingly, and reset algorithm.
            // if there are not enough moves to make it to the exit, crear variables,
            // add 1 to extra moves, check again.
            if( spacesMoved==moveCount-1 && ((curX>1 && curX<20) || (curY>1 && curY<20)) )
                neededExtraMoves++;
                xCounter=0;
                yCounter=0;
                spacesMoved=0;
                bestPath = new int[moveCount];
                recursePath();
            // if there are not too many moves, crear variables,
            // subtract 1 from extra moves, check again.
            else if( spacesMoved<moveCount && (curX==0 || curX==21 || curY==0 || curY==21) )
                neededExtraMoves--;
                xCounter=0;
                yCounter=0;
                spacesMoved=0;
                bestPath = new int[moveCount];
                recursePath();
            // look in all directions, and find the highest value, and
            // move in that direction
            int moveDir = findFurthestWay(lookNorth, lookEast, lookSouth, lookWest);
            if(moveDir==NORTH) { yCounter--; bestPath[spacesMoved] = NORTH; }
            if(moveDir==SOUTH) { yCounter++; bestPath[spacesMoved] = SOUTH; }
            if(moveDir==WEST)  { xCounter--; bestPath[spacesMoved] = WEST;  }
            if(moveDir==EAST)  { xCounter++; bestPath[spacesMoved] = EAST;  }
//             curX = x+xCounter;
//             curY = y+yCounter;
            spacesMoved++;
            recursePath();
        //bestPath = new int[moveCount];
        return bestPath;
    // find the path that has thegreatest line of sight (in order n, e, s, w)
    public int findFurthestWay(int a, int b, int c, int d)
        int greatestNumber = 0;
        if(a>greatestNumber) greatestNumber = a;
        if(b>greatestNumber) greatestNumber = b;
        if(c>greatestNumber) greatestNumber = c;
        if(d>greatestNumber) greatestNumber = d;
        // NORTH=1, EAST=2, SOUTH=3, WEST=4
        if(a==greatestNumber) return NORTH;
        if(b==greatestNumber) return EAST;
        if(c==greatestNumber) return SOUTH;
        if(d==greatestNumber) return WEST;
        return 0;
    // reset recursePath vars.
    public void resetCounters()
        xCounter = 0;
        yCounter = 0;
        spacesMoved = 0;
        neededExtraMoves = 0;
        moveCount = 0;
        bestPath = new int[moveCount];
    // record the positions of the walls
    public void storeWallLocations()
        // Store the locations of the walls
        if(lookNorth!=100) wallLocations[x][y-lookNorth][0]=true;
        try{wallLocations[x][y-lookNorth-1][2]=true;} catch(Exception e){}
        if(lookSouth!=100) wallLocations[x][y+lookSouth][2]=true;
        try{wallLocations[x][y+lookSouth+1][0]=true;} catch(Exception e){}
        if(lookWest!=100) wallLocations[x-lookWest][y][3]=true;
        try{wallLocations[x-lookWest-1][y][1]=true;}  catch(Exception e){}
        if(lookEast!=100) wallLocations[x+lookEast][y][1]=true;
        try{wallLocations[x+lookEast+1][y][3]=true;}  catch(Exception e){}
}

Similar Messages

  • How to exit from the button test in diagnostic mode

    Hi,
    I am having some trouble with my ipod 7th gen.
    First my lightning cable wont be recognize. show the error Accesory incompatible.
    I try to solve the problem cleaning the golden pins in the cable and in the ipod. Don't work
    I enter in diagnostic mode in my ipod and I get stucked in the button counter test..
    In the screen appear a mesage 'Please reset the unit to end'. I don't know how to reset the unit
    I press any button and only increase the counter for every button.
    First how acan exit from the button counter test and how can fix the issue with the lightning cable

    Your problem is that you are trapped inside an event case. It is not a good idea to run extended code inside event cases, else the event structure cannot service other events.
    Why don't you use the outer loop for everything? Now things don't step on each others toes. What good is an event structure if it cannot react at all times???
    Message Edited by altenbach on 07-25-2008 12:26 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    event_problemMOD.vi ‏17 KB

  • I have a 13.5 month old Ipad2, wifi only that has had problems with wifi com from the beginning. I am learning that this is not unusual for apple. Any suggestions?

    I have a 13.5 month old Ipad2, wifi only that has had problems with wifi com from the beginning. I am learning that this is not unusual for apple. Any suggestions?
    ronald1094

    Try #5.
    Some things to try first:
    1. Turn Off your iPad. Then turn Off (disconnect power cord for 30 seconds or longer) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    2. Go to Settings>Wi-Fi and turn Off. Then while at Settings>Wi-Fi, turn back On and chose a Network.
    3. Change the channel on your wireless router (Auto or Channel 6 is best). Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    4. Go into your router security settings and change from WEP to WPA with AES.
    5.  Renew IP Address: (especially if you are droping internet connection)
        •    Launch Settings app
        •    Tap on Wi-Fi
        •    Tap on the blue arrow of the Wi-Fi network that you connect to from the list
        •    In the window that opens, tap on the Renew Lease button
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    iOS 6 Wifi Problems/Fixes
    How To: Workaround iPad Wi-Fi Issues
    http://www.theipadfan.com/workaround-ipad-wifi-issues/
    Another Fix For iOS 6 WiFi Problems
    http://tabletcrunch.com/2012/10/27/fix-ios-6-wifi-problems-ssid/
    Wifi Doesn't Connect After Waking From Sleep - Sometimes increasing screen brightness prevents the failure to reconnect after waking from sleep. According to Apple, “If brightness is at lowest level, increase it by moving the slider to the right and set auto brightness to off.”
    Fix For iOS 6 WiFi Problems?
    http://tabletcrunch.com/2012/09/27/fix-ios-6-wifi-problems/
    Did iOS 6 Screw Your Wi-Fi? Here’s How to Fix It
    http://gizmodo.com/5944761/does-ios-6-have-a-wi+fi-bug
    How To Fix Wi-Fi Connectivity Issue After Upgrading To iOS 6
    http://www.iphonehacks.com/2012/09/fix-wi-fi-connectivity-issue-after-upgrading- to-ios-6.html
    iOS 6 iPad 3 wi-fi "connection fix" for netgear router
    http://www.youtube.com/watch?v=XsWS4ha-dn0
    Apple's iOS 6 Wi-Fi problems
    http://www.zdnet.com/apples-ios-6-wi-fi-problems-linger-on-7000004799/
    ~~~~~~~~~~~~~~~~~~~~~~~
    How to Fix a Poor Wi-Fi Signal on Your iPad
    http://ipad.about.com/od/iPad_Troubleshooting/a/How-To-Fix-A-Poor-Wi-Fi-Signal-O n-Your-iPad.htm
    iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    WiFi Connecting/Troubleshooting http://www.apple.com/support/ipad/wifi/
    How to Fix: My iPad Won't Connect to WiFi
    http://ipad.about.com/od/iPad_Troubleshooting/ss/How-To-Fix-My-Ipad-Wont-Connect -To-Wi-Fi.htm
    iOS: Connecting to the Internet http://support.apple.com/kb/HT1695
    iOS: Recommended settings for Wi-Fi routers and access points  http://support.apple.com/kb/HT4199
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Connect iPad to Wi-Fi (with troubleshooting info)
    http://thehowto.wikidot.com/wifi-connect-ipad
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
    Fix Slow WiFi Issue https://discussions.apple.com/thread/2398063?start=60&tstart=0
    How To Fix iPhone, iPad, iPod Touch Wi-Fi Connectivity Issue http://tinyurl.com/7nvxbmz
    Unable to Connect After iOS Update - saw this solution on another post.
    https://discussions.apple.com/thread/4010130
    Note - When troubleshooting wifi connection problems, don't hold your iPad by hand. There have been a few reports that holding the iPad by hand, seems to attenuate the wifi signal.
    ~~~~~~~~~~~~~~~
    If any of the above solutions work, please post back what solved your problem. It will help others with the same problem.
     Cheers, Tom

  • How to exit from the class execution process?

    I am invoking an exe from my Java application using the Runtime.getRuntime().exec() method.
    though the process is completed, the class is still running.
    how do i exit from the class execution, but with the process still running??

    To sabre150 :
    I am directly executing the command through the exec() method:
    Runtime.getRuntime().exec("...../iexplore.exe");This way, the control is going to the opened IE window and only on closing it, my class is exiting.
    Is there any other way where I can come out of the class, but ensure that the process which i run through the exec() method, is still running?

  • Can`t exit from the app corner mode in windows phone 10 technical preview at Nokia Lumia 520

    After upgrading to windows phone 10, I just face several bugs as expected, including screen unlock bug. I just try app corner feature on my phone. That`s led to a big mistake. I can`t exit from the app corner mode. While pressing the power off
    button and swap right, nothing happens. (In lock screen, it doesn`t show that swap right to exist. I think this problem also related to locks screen bug.  Even I try  to remove the battery. But, still I struck at app corner. Please
    help me come out this problem!!!
    Thanks in advance
    Mohamed Usman
    www.neotech4u.weebly.com

    Very very disappointed. Sorry about windows phone. I have argued quit a lot with friends. Trying to convince them that WP are extremely good and nice to work with. Unfortunately they keep telling me about the poor apps of WP. Unfortunately I can now start seeing the problem. Guess what, I wasconsidering of buying my father a WP. Guess what. I will probably stick to android. Badly played about that. Farewell. Disappointed 7.8 WP customer from Athens Greece.

  • Recently, when I create a new album (untitled), it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    Recently, when I create a new album (untitled), it immediately fills it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    When a new album is created it will fill with whatever is in the right hand window,  If you're in the Events or Photos mode it will contain all photos in the library.  Yes, strange behavior.
    OT

  • Ff comes on, I go to site w/ pics the screen goes black & then w/ with a bubble from the bottom saying recovery from igfx display failure..Chr & Op = OK

    Firefox comes on, I go to a site rich w/ visual content & then the screen goes black & then white w/ with a bubble from the bottom bar saying recovery from igfx display failure..this used to happen on my Chrome browser (the Chr browser recovered spontaneously But I removed & reset it... still the problem went on & I quit using Chr for2-3 mos. There never was a problem on Opera. Hey! OPERA rule. As foe IE 8. That instrument is completely useless. Even all areon IE appears to be dead...Thanx!

    Try disabling hardware acceleration in Firefox.
    https://support.mozilla.org/en-US/kb/upgrade-graphics-drivers-use-hardware-acceleration#w_turning-off-hardware-acceleration

  • What is the best way to zero a 'custom voltage with excitation' sensor from the front panel?

    What is the best way to zero a 'custom voltage with excitation' sensor from the front panel?
    Thanks for any help

    Hi Donavan,
    There are two options for zeroing with the NI-9237.  You can perform offset nulling and shunt calibration with a strain task, or if you use custom excitation you can use software compensation.
    See the Bridge Balancing, Offset Nulling section in  the Load, Force, and Torque Measurements tutorial. Take a measurement before the strain is applied and subtract this from all subsequent measurements.  See the above tutorial to consider the tradeoff in accuracy between these two options.
    Hope this helps,
    Jennifer O.
    Applications Engineer
    National Instruments

  • My folders take forever to open and then the docs within take a long time for the icon to pop up. the same thing with moving itmes from the desktop to a folder, and also emptying the trashh

    my folders take forever to open and then the docs within take a long time for the icon to pop up. the same thing with moving itmes from the desktop to a folder, and also emptying the trashh

    Don't know if that would be a failing hard drive, but it may be that you are out of available space. How much hard drive space do you have available? Please highlight the Macintosh HD icon and then press Command and I for a get info window. Once open, please copy and post the following:
    Capacity:
    Used:
    Available:
    Mac OS requires a minimum of 10 - 15% of total hard drive space available and empty at all times in order to operate properly.

  • Problem accessing R/3 with SSO ticket from the EP6.0

    Hi all,
    I have seen this thread: Problem accessing R/3 with SSO ticket from the EP6.0
    I know that it is possible to read SSO ticket from the Cookie in WebDynpro application.
    Now we are at the first step, we don't know how to read SSO ticket from the Cookie in WebDynpro application with java code.
    So anyone can help us?

    Hi,
    This has been discussed in a previous forum.Check this link.A code snippet is also there to read a cookie in webdynpro with this question
    How to implement SSO between Portal, Webdypro and ABAP system?
    I am not able to send the link exactly.
    Regards,
    Sowjanya.
    Message was edited by: Sowjanya Chintala

  • ANN: Dreamweaver CS5 with PHP: Training from the Source - Rough Cuts

    If you would like to get early access to my next book "Adobe Dreamweaver CS5 with PHP:  Training from the Source", the first six chapters (of 12) are now  available as Rough Cuts in Safari  Books Online.
    If you have a Safari Library subscription, you can  view the chapters free of charge, and see new ones as they're added.  Without a subscription, you can get access to the book in PDF format for  $34.99, including the finished ebook version when the book is complete.  You can also opt for the Rough Cuts PDF and Print bundle for $67.48.  The print version is expected to be released in early August.

    FIXED!!
    1)
    i finally did get the message problem was with:
    $mailhost='ssl://mail.domain.com';
    ssl:// was just nonsense and been removed
    2)
    'auth' => 'true' was changed to 'auth' => 'login'
    3)
    for bluehost i got information that it was tls secure connection protocol not ssl
    'ssl' => 'tls'
    4)
    port used '25' not 465.
    Didnt still tried 26 and 465 maybe they would work too.

  • I had to replace my i4s with another one from the apple store.shouldn't i be able to go to the cloud to get all my contact info and other stuff that was stored in the cloud from the first phone?

    i had to replace my i4s phone with another one from the apple store. i need to download all my contact info and other stuff from the cloud to my new phone.i see a screen that says  RESTORE I PHONE   and are you sure you want to restore the iphone to its facory settings?  all of your media and other data will be erased. they i tunes will verify restore with apple. After this you will have the option to restore your contacts and other settins.  The question is will it restore my first phones info?  I am hesitant to delete anything  lol.

    No. If you made your backup to iCloud, iTunes will not restore from an iCloud backup. See:
    iOS: Backing Up and Restoring Data to a New Device

  • How to make an appointment with a contact from the address book directly to iCal

    What is the easiest way to make an appointment with a contact from the address book. My idea is that once you identify a contact down the bottom where it has Text message Share contact, add to favorites it would be nice if it had make appointment in iCal. The open up iCal to todays date and go from there with all the relevant details?

    In the Print dialogue box select Lists in the Style drop down box.

  • Since I upgraded to os x maverick when I try to close with cmd + q from the drop-down menu the app store and I IMOVE reopen continuously.

    since I upgraded to os x maverick when I try to close with cmd + q from the drop-down menu the app store and I IMOVE reopen continuously.

    2 GB of RAM is pretty tight. I imagine that's at the very low end of what Yosemite wants, which could slow things down.
    As far as scroll direction, you can always change it in the trackpad settings. Unsure why it got flipped, but you can fix it in about 5 seconds. Choose "natural" (or don't) depending on how you like it.

  • How to track exit from the PageFragment Lifecycle

    Hi,
    I have a requirement of keeping track of exit from a pageFragment.
    My structure contains: a TaskFlow which contains a train . This train node contains the page Fragments. Now when i navigate from one PageFrag to another ie. when i exit the currently selected node having a page Fragment, i need to fire a logic.
    I tried using creating a bean which implements RegionController interface which has refreshRegion(RegionContext ) method.I got hold of RegionBinding interface which has only one of the following values: Entry, Execute_Model, Prepare_Model, Refresh_Unknown, Render_Model and Type_executable_region.
    Also in this case i am not exiting the TaskFlow during the navigation.
    My doubt is how do i or can i use RegionController to keep track of exit from the currently rendered PageFragment's  Lifecycle.
    Also , can i use PagePhaseListener to keep track of the PageFragment lifecycle stage. (My understanding is PagePhaseListener is to be used for Jspx not Jsff). Plz do correct me if i am wrong.
    Thanks,
    Prasenjit
    Edited by: user586616 on Aug 31, 2009 3:54 AM
    Edited by: user586616 on Aug 31, 2009 3:57 AM

    Hi Frank,
    I have created a ControllerClass which implements RegionController. I have registered the same as controller class in my pageFragments PageDef.
    So, on navigation from one train node to another. due to post back call to leaving node and freshcall to the arriving node in the train flow. i am able to get the leaving as well approaching node.
    My doubt is can i get similar or better control over the nodes traversed using trainModel or anyother adfinternal controller class? Kindly suggest any better way of getting handle to the navigating train nodes.
    Sample Code which i have implemented:
    public class RegionControllerBean implements RegionController {
    public boolean refreshRegion(RegionContext regionContext) {
    System.out.println("**********************************");
    System.out.println("inside refreshRegion method call");
    String selectedView = ControllerContext.getInstance().getCurrentViewPort().getViewId(); ------> this gives me the handle to the viewId of the curently selected pageFragment
    System.out.println(ControllerContext.getInstance().getCurrentViewPort().getViewId().toString());
    String pageName = selectedView.split("/")[2];
    System.out.println("Current PageName:"+pageName);
    System.out.println("name: "+regionContext.getRegionBinding().getName());
    int refreshFlag = regionContext.getRefreshFlag();
    if(refreshFlag == RegionBinding.PREPARE_MODEL){
    System.out.println("Inside prepare Model phase"); ------> on entering of that node i need to call some logic before prepare_model phase
    if(refreshFlag == RegionBinding.EXECUTE_MODEL){
    System.out.println("Inside execute model phase");
    if(refreshFlag == RegionBinding.RENDER_MODEL){
    System.out.println("Inside render model phase");
    // propagate refresh to inner binding container
    regionContext.getRegionBinding().refresh(refreshFlag);
    return false;
    public boolean validateRegion(RegionContext regionContext) {
    // propagate the validate to inner binding container
    System.out.println("inside validate region method");
    regionContext.getRegionBinding().validate();
    return false;
    thanks,
    Prasenjit

Maybe you are looking for

  • Data from two tables in the same row in XML transformation

    Hi,     I am using XML transformation for generating excel file which is to besent as email attachment.     Here  I want to display the data from two internal tables in the same row in the excel. .I am using   <tt:loop ref=".<table name>"> ...  </tt:

  • Error while loading journal template in fdm 11.1.1.2

    Hi Guys, I am using Fdm 11.1.1.2. I am getting the following error while loading a journal template The following error I am getting while loading the template while using the option Select file from inbox Error- The remote server machine does not ex

  • Query --Insert no of records in target based on count

    The source table has a count column. Now, depending on the value in the count field of that record, that particular record has to be loaded that number of times with consecutive dates. For e.g. the source table structure looks like: Resource ID Proje

  • Change state option in SM51

    Hello, I would like to know if activate/deactivate option in SM51 (see below) menu--->edit - >change state - >activate/deactivate is used for activating and deactivating servers? If not what is its functionality? mm

  • Window.close doesn't work with Firefox

    I have used the code from the followinging reference on OTN to close my window: Closing brower window It works fine for IE, but not for Firefox. How can I make it work with Firefox?