Homework Help Question & Answers

please help with the code that would solve this Choose Ultrakarel as your starting point. World #1 RESET II » RUN Wo...


Choose Ultrakarel as your starting point. World #1 RESET II » RUN World: Dog Maze1 Instructions: Write an algorithm that help please help with the code that would solve this
Choose Ultrakarel as your starting point. World #1 RESET II » RUN World: Dog Maze1 Instructions: Write an algorithm that helps Karel find the tennis ball (your algorithm must include some of following: if / then statements, for & while loops, boolean statements, and functions). Feel free to write your own functions that would help simplify the task. Note: use this document to copy a link to your program with the solution to the given worlds using www.codehs.com
0 0
Next > < Previous
ReportAnswer #1

There are many ways to solve a maze, here we are going to consider the maze as a 2 dimensional array of values.

in our maze we can consider it as a 10x10 matrix.. (see the no. of dots vertically and horizontally).. let us consider 10 as the height of the maze and the other 10 as the width of the maze. now for each position we will assign a value. By doing that we will come to know the starting point the ending point,the ways that are blocked by walls,and the route taken.

so, it can be explained in simple steps:

step 1: enter the starting position.(in our case it is 0x0)

step 2: enter the end position..(in our case it is 10X10)

step 3: the row will increment , if the current position is not on a wall, the function will check other possible values for further movement,if such a value is not already visited it will follow that path, else if it is visited it will backtrack,visited positions are stored

step 4: if the current position is on the wall,then also it will do backtracking,

step 5: all above steps are repeated till it reaches the end position.

Algorithm:

int dog_maze[][] = new dog_maze[w][h];//we enter the maze in matrix

int x1,y1 //starting position

int x2,y2// end position

boolean[][] already_visited=boolean[w][h];// as i said already there will be a visited set

boolean[][] solution=boolean[w][h]// after reaching end position path is saved.

void help_dog()//function for solving the puzzle

{

dog_maze = createmaze()

for(row 0 to length)

for(column 0 to length)

already_visited[row][coloumn]=false;

solution[row][coloumn]=false;

}

public boolean tracking(int a, int b)

{

if(a==x2&&b==y2)//end position

return true;

if(dog_maze==2||already_visited)

return false;

already_visited=true;

if(a!=0)

if(help_dog(a-1,b))

{

solution[a][b]=true;

return true;

}

if(a!=w-1)

if(help_dog(a+1,b))

{

help_dog[a][b]=true;

return true;

}

if(b!=0)

if(help_dog(a,b-1))

{

solution[a][b]=true

}
}

now this function gets repeated till the end node is visited...

Know the answer?
Add Answer of:
please help with the code that would solve this Choose Ultrakarel as your starting point. World #1 RESET II » RUN Wo...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • objective The Milestone Assignments are based on the Projects and Cases for use with the Systems Analysis and Design Methods textbook by Whitten & Bentley

    objective The Milestone Assignments are based on the Projects and Cases for use with the Systems Analysis and Design Methods textbook by Whitten & Bentley. There are six (6) parts to the Project, consisting of twelve (12) milestones. During Weeks 2-7, you will be required to complete two (2) milestones. Each milestone is worth 40 points. Milestones 5 and 10 are included as already completed work, so you only need submit them as part of the assignment. Guidelines Be sure...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
Share Your Knowledge

Post an Article
Post an Answer
Post a Question with Answer

Self-promotion: Authors have the chance of a link back to their own personal blogs or social media profile pages.