C++代写 代写C++程序 C++作业代写 C++程序代写

CPP编程代写 代写CPP作业 代写CPP编程

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                       
                                       
                                                                                                                                                                       

1 Introduction

                                                                                                                                               
                                       
                                                                                                                                                                                                                         

1.1 Summary

                                                               

In this assignment you will implement a version of Trémaux’s algorithm for solving simple mazes. The algorithm in this assignment has a slight variation, so make sure you check the details here!

                                                               

In this assignment you will:

                                                               

• Practice the programming skills covered throughout this course, such as: – Pointers

                                                               

– Dynamic Memory Management

                                                               

– Provided API
• Correctly Implement a pre-defined API
• Implement a medium size C++ program
• Use a prescribed set of C++11/14 language features

                                                               

This assignment is marked on three criteria, as given on the Marking Rubric on Canvas:

                                                               

• Milestone 1: Writing Tests
• Milestone 2-4: Implementation of the Maze Solving Task
• Style & Code Description: Producing well formatted, and well documented code.

                                                               

1.2 Relevant Lecture/Lab Material

                                                               

To complete this assignment, you will requires skills and knowledge from lecture and lab material for Weeks 2 to 4 (inclusive). You may find that you will be unable to complete some of the activities until you have completed the relevant lab work. However, you will be able to commence work on some sections. Thus, do the work you can initially, and continue to build in new features as you learn the relevant skills.

                                                               

! For Assignment 1, you may only use C++ languages features and STL elements that are covered in class. 1.3 Academic Integrity and Plagiarism

                                                               

! CLO 6 for this course is: Demonstrate and Adhere to the standards and practice of Professionalism and Ethics, such as described in the ACS Core Body of Knowledge (CBOK) for ICT Professionals.

                                                               

Academic integrity is about honest presentation of your academic work. It means acknowledging the work of others while developing your own insights, knowledge and ideas. You should take extreme care that you have:

                                                               
  •                                                                         
  •                                                                                 

    Acknowledged words, data, diagrams, models, frameworks and/or ideas of others you have quoted (i.e. directly copied), summarised, paraphrased, discussed or mentioned in your assessment through the ap- propriate referencing methods

                                                                            
  •                                                                        
  •                                                                                 

    Provided a reference list of the publication details so your reader can locate the source if necessary. This includes material taken from Internet sites. If you do not acknowledge the sources of your material, you may be accused of plagiarism because you have passed off the work and ideas of another person without appropriate referencing, as if they were your own.

                                                                                   

    RMIT University treats plagiarism as a very serious offence constituting misconduct. Plagiarism covers a variety of inappropriate behaviours, including:

                                                                                   

    • Failure to properly document a source
    • Copyright material from the internet or databases • Collusion between students

                                                                                   

    For further information on our policies and procedures, please refer to the RMIT Academic Integrity Website.

                                                                                   

    The penalty for plagiarised assignments include zero marks for that assignment, or failure for this course. Please keep in mind that RMIT University uses plagiarism detection software.

                                                                            
  •                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

2

                                                                                                                                               
                

               

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                       
                                       
                                                                                                                                                                       

2 Background

                                                                                                                                               
                                       
                                                                                                                                                                       

A maze is a very typical puzzle. To solve a maze you must find a path that connect the entry (starting) and exit (ending) points of the maze.

                                                               

In this assignment, we will represent a simple 2D maze as a grid of ASCII characters. For example:

                                                                                                                                                                                                                                                                                                                               

Aspects of the maze are represented by different symbols:

                                                                                                                                                                                                                                                                               
========== S........= ========.= =......=.= ==.=.=...= =..=..=.== =.===....= =..==.==.= =====E====
                                                                                                                                                                                                                                                                                                                               

Symbol

                                                               

= (equal) . (dot) S
E

                                                                                                                                                                               

Meaning

                                                               

Wall or Obstacle within the maze. The robot cannot pass obstacles Empty/Open Space.
The starting point (entry) of the maze.
The ending point (exit) of the maze.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

* (asterisks)                                                                         Used to show the solution of the maze, which is a trail of breadcrumbs The solution to the above maze can be shown as:

                                                                                                                                                                                                                                                                                                                                                                                 
========== S********= ========*= =...***=*= ==.=*=***= =..=**=.== =.===*...= =..==*==.= =====E====
                                                                                                                                                                                                                                                                               

Each location in the maze (including the maze edges) is indexed by a cartesian (x,y) co-ordinate. The top-left corner of the maze is always the co-ordinate (0,0), the x-coordinate increases right-wards, and the y-coordinate increases down-wards. For the above maze, the four corners have the following co-ordinates:

                                                               

Finally, we also define 4 cardinal directions, so we can talk in terms of moving/walking about the maze.

                                                                                                                                                                                                                                                                                                                               

(0,0) . . (10,0) .. ..

                                                               
(0,10) . . (10,10)
                                                                                                                                                                                                                                                                                                                               

north ^

                                                               
west <- | ->  east        v
                                                               

south

                                                                                                                                                                                                                                                                               

3

                                                                                                                                               
                

               

                                                                                                

Mazes can be designed in different ways. For the purposes of this assignment we will use mazes where:

                                       

1. There is one starting and one ending point.
2. The maze is always surrounded by walls, except for the starting/ending points. 3. The maze only contains junctions and corridors.

                                       

In this assignment you will implement a simplified version of Trémaux Algorithm for these types of mazes. ! You MUST implement this algorithm. While there are many ways to solve a maze, y must implement

                                       

this algorithm. If you don’t, you will receive a NN grade.

                                       

2.1 Simplified Trémaux Algorithm.

                                       

This algorithm let us simulate “walking” about the maze leaving a trail of breadcrumbs behind us as we go. Along the way we can encounter dead-ends, so we will have to backtrack. As we back-track we will make some of the breadcrumbs “stale”. Once we reach the end (goal), our trail of “good” (fresh/non-stale) breadcrumbs will be the path for solving the maze.

                                       

! While a maze might have multiple solutions, this algorithm will only find one solution. It might not be the best or optimal, but it will be the same solution each time.

                                       

The basic premise of the algorithm is:

                                       
  1.                                                 
  2.                                                         

    We “walk” along a corridor, dropping a breadcrumb at each location

                                                    
  3.                                                
  4.                                                         

    When we hit a junction, we head down a corridor that we haven’t been down before (we know this from

                                                           

    our breadcrumbs!)

                                                    
  5.                                                
  6.                                                         

    If we reach a dead-end, then we backtrack along our trail of breadcrumbs, marking these previously laid

                                                           

    breadcrumbs as “stale”, until we get back to a junction.

                                                    
  7.                                                
  8.                                                         

    Then we choose a different path to head down

                                                    
  9.                                                
  10.                                                         

    This keep on going until we reach the end of the maze.

                                                    
  11.                                         
                                       

The following is a more explicit form of this algorithm in pseudocode: Pseudocode for the Simple Maze Solving

                                                                                                                                                                                                                                                           

1 2 3 4 5 6 7 8

                                       

9 10 11 12

                                       

13 14 15 16 17

                                                                                                       

Let M be the maze
Let T be the trail of breadcrumbs that we leave
Let S and E be the starting and ending points of the maze respectively Let b be track our current place in the maze, and set b = S
repeat

                                       

if The trail has no bredcrumb for our current location, b then
Add a breadcrumb for b to the end of the trail, that is T.addback(b)

                                       

end

                                       

// Look for a place to go next
In order of north, east, south, west from b find the first location l, such that: if l is empty and we havent left a breadcrumb in the trail T then

                                       

Movefrombtol. Thatis,b=l else

                                       
      // We need to Backtrack, as there is no-where we can go
                                       

Mark b (current breadcrumb) as “stale”. (Make sure to update this within T) Find the last good breadcrumb in the Trail T, call it bgood.
Go to this breadcrumb, that is b = bgood.

                                       

end
until We reach the end, that is b == E

                                                                                                                                                                                                                                                           

On Canvas, you will find a short video stepping through this algorithm. In particular, it goes over the importance of maintaining the order of the breadcrumb trail. This is crucial to the backtracking. If we keep the breadcrumb trail in the right order, then we can figure out how to backtrack, by searching backwards from the end of the trail. This is because the trail is the exact order in which we have explored the maze. So the reverse of the trail, is the order to go back the way we came.

                                                                                                                                                       

4

                                                                       

               

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                       
                                       
                                                                                                                                                                       

3 Task

                                                                                                                                               
                                       
                                                                                                                                                                       

The task for this assignment is to write a full C++ program that:

                                                               

1. Reads in a 20x20 maze from standard-input (std::cin).
2. Solves the maze (using the Simplified Trémaux Algorithm in Section 2.1).
3. Prints out the solution to the maze to standard output (std::cout).
4. (Optionally) prints out walking/navigation directions (that you could follow to walk through the maze).

                                                               

For the purposes of this assignment (except for Milestone 4), you may assume that the maze is always a fixed size of 20x20.

                                                               

This assignment is divided 4 Milestones. To receive a PA grade, you only need to complete Milestones 1 & 2. To receive higher grades, you will need to complete Milestones 3 & 4.

                                                               

! Take careful note of the Marking Rubric on Canvas. Milestones form a sequence. For example, if you attempt Milestone 3, but your Milestone 2 is buggy, you won’t get any marks for Milestone 3.

                                                               

3.1 Milestone 1: Writing Tests

                                                               

Before starting out on implementation, it is good practice to write some tests, so that you can know if your implementation is 100% correct. We are going to use I/O-blackbox testing. That is, we will give our program a maze to solve (as Input), and then test that the program’s Output is what we expect it to be.

                                                               

This a test consists of two text-files:
1. .maze - The input maze for the program to solve

                                                               

2. .out - The expected output which is the solution to the maze. A test passes if the output of your program matches the expected output.

                                                               

You should write enough tests so that, if your program passes all of your tests pass, you are confident that your program is 100% correct.

                                                               

Recall that you can “run” a test, by I/O redirection, and capturing your programs output: ! ./assign1 program.out

                                                               

Then you can test if the actual and expected outputs match with the diff command: diff program.out testname.out

                                                               

3.2 Milestone 2: Maze Solving

                                                               

Even for a relatively small algorithm, it is important to have the right design for our programs, and use appropriate data structures and classes. To help you in Assignment 1, we done this design for you to implement1. We will implement 3 classes, plus a main file:

                                                               

• Breadcrumb class - to represent a single breadcrumb in the trail.
• Trail class - to and update the trail of breadcrumbs as we explore the maze.
• MazeSolver class - to encapsulate the maze solving algorithm.
• The main file that uses these classes, and does any reading/writing to standard input/output.

                                                               

You are given these classes as header files in the starter code. You may add any of your own code, but you must not modify the provided class methods and fields. If you implement the class, you will have a working Milestone 2.

                                                               

3.2.1 Breadcrumb Class

                                                               

The Breadcrumb class represents one breadcrumb in our trail. It is a tuple (x,y,stale), which is the x-y location of the breadcrumb in the maze, and whether breadcrumb is fresh or stale. It has accessor methods for this information and one method to change if the breadcrumb is fresh or stale.

                                                               

1This won’t be the case for Assignment 2, where you will have to make these decisions for yourself. 5

                                                                                                                                                                                                                                                                                                                                                                                                    
                

               

                                                                                                                         
  // Constructor/Desctructor
                                       
  Breadcrumb(int x, int y, bool stale);
  ~Breadcrumb();
                                       
  // x-co-ordinate of the particle
                                       
  int getX();
  // y-co-ordinate of the particle
                                       
  int getY();
  // Get if the Breadcrumb is stale. (If false, it is good/fresh)
                                       
  bool isStale();
  // Mark this Breadcrumb as stale (or not)
                                       
  void setStale(bool stale);
                                       

3.2.2 Trail Class
The Trail class stores a trail of breadcrumbs in the correct order, using an array of breadcrumb objects.

                                       
  // Trail of breadcrumb objects  // You may assume a fixed size for M1 & M2
  Breadcrumb* breadcrumbs[TRAIL_ARRAY_MAX_SIZE];
                                       
  // Number of breadcrumbs currently in the trail
                                       

int length;
Remembers, since it’s an array we also need to track the number of breadcrumbs in the trail.

                                       

! You must implement the Trail class using an array.

                                       

The constant TRAIL_ARRAY_MAX_SIZE is the maximum number of breadcrumbs that can be in any trail. For this milestone, we can assume no trail will every get longer than this maximum size. This constant is given in the Types.h header file.

      &nbs
京ICP备2025144562号-1
微信
程序代写,编程代写
使用微信扫一扫关注
在线客服
欢迎在线资讯
联系时间: 全天