Thread: Help! Robot Programming

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Just a thought:

    Every box you try to move, you'll need to find the depth of the box. Although you'll be pushing on the side of the box facing the robot, the BACK of the box will be the determining factor in how far the box can be pushed.

    When the back of the box hits up against a wall, then the whole push must make no more progress, at least until the robot has been re-positioned so it can push the box in a new direction. Then the new back of the box will determine if a push in that direction, can succeed.

    In programs like this, working out what you need to do in pseudocode, with pencil and paper, is a real time-saver. Here, I recommend working the same way to solve the problems that remain with your program.

    Edit: OK, I see your request for help with the robot's movement. Here's how I'd do it:

    1) You have a global CD = robot's current direction
    2) Use a switch statement to then determine which way the robot should turn, in psuedocode, something like:

    Code:
    switch cd
       CD is UP:
        if keypress is L then CD is LEFT
        else if keypress is R then CD is RIGHT
        else if keypress is D then CD is DOWN
        else if keypress is U then call your Move(UP) function and make the move.
    
       CD is RIGHT
        if keypress is L then CD is UP
        else if keypress is R then call Move(RIGHT) and make the move
        else if keypress is D then CD is DOWN 
        else if keypress is U then CD is UP
    
    etc.
    After changing the CD, you may want to call a TURN(CD) function to show the robot has actually turned, on the screen with a change of direction to the robot's char.

    Move() must check ahead that the robot's grid at that point (x,y), is not a wall, or a box. If it's a wall, the robot just stops, if it's a box, the robot calls PushBox(), to see if the box can be pushed one point in the grid.

    Hope that gives you some helpful idea's. If you're learning C, I wouldn't get all caught up with using pointers and unions and such. Try to keep your program at your level, or just a bit more. Making a program too complicated is just the opposite of what you want to do. KISS will help with the problem solving needed.


    Adak
    Last edited by Adak; 09-27-2006 at 07:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Continuous Navigation while X for a Robot
    By Creighton in forum C Programming
    Replies: 3
    Last Post: 06-29-2009, 08:38 PM
  2. New Problem with the Robot output!
    By tx1988 in forum C++ Programming
    Replies: 0
    Last Post: 04-18-2009, 04:02 PM
  3. Generate keypresses like the Robot class in java
    By samel_tvom in forum Game Programming
    Replies: 3
    Last Post: 10-06-2008, 05:37 AM
  4. Help with moving robot in a maze
    By Killahkode in forum C Programming
    Replies: 2
    Last Post: 09-25-2006, 10:51 AM
  5. Replies: 5
    Last Post: 09-08-2001, 09:18 AM