Simple requirement analysis. Even those who have played the connected viewing know that the connected viewing is actually testing whether to connect two points (images) with less than or equal to three connected lines ). The number of lines is 0 ~ 3. First, only the logic is implemented, and a smart test is conducted. The program can demonstrate the process of playing a link-to-play video. The interface has not been done yet. It is prepared to use QT (unfamiliar ), source code download 0 lines indicates that two points are adjacent. In the coordinate axis, the X axis is the same, the Y axis value is 1, or the Y axis is the same. The X axis value is 1. One line indicates that two vertices are the same as X or Y axis, and there are no other vertices between two points. Two lines represent the rectangles determined by two points, and there are no other three complex points connected to both points. After repeated thinking, we decided to divide the three lines into five categories: upper, lower, left, and middle (Southeast, Northwest ). This classification mainly aims to make the Code better understood and the idea looks simpler. Top: the second line connecting the three lines of the two points is above the two points: Bottom left: Left right: Right middle: the line connecting the two points is located in the Rectangular body (including the side of the cube) determined by the two points)
In all cases ~ In the case of three lines, the most important feature of the connection is even implemented. The most widely used method is to determine whether two points are in the same straight line and there are no other points in the straight line, both the two and three lines can be converted into two groups or three groups of two points on the same line. In terms of implementation, I used A two-dimensional array A [row] [column] to indicate whether an image exists at A certain point, and whether the two points are the same image. 0 indicates whether there is any image, other values indicate that there are images. If the values of the two vertices are the same, they indicate the same images. Let's test whether the two vertices can be figured out. All implementations are based on the two-dimensional array. In this version, I mainly implemented all the logic, but I didn't have an interface. The interface was ready to be implemented using QT. However, since I am not familiar with QT, I have to wait for a while, first, the general logic was implemented, and the continuous viewing process was simulated. Some errors were found during the simulation process, but at last it proved that my implementation was correct and there were no performance problems, of course, this is also related to the connection, because the main function of the connection is to test whether the two points can be connected successfully, and the command execution is very fast for the computer. Inflection point: there are at most three lines, and there are at most two inflection points. When I know the endpoint and inflection point, I know the line connecting the two points. Success or not: write down the number of points at the beginning. If two points are not successfully connected, the number of points is reduced by 2. If the remaining number of points is 0, the operation is successful, of course, you can also Scan each time to see if the remaining points are greater than 0. I personally think that using a variable to write down the remaining points will be faster. Determine whether there is no solution: If no two points can be connected, it means no solution. There are two ways to implement this function. Method 1: Scan each time you determine whether there is no solution. Check whether two points can be connected. If there is a solution, otherwise there is no solution. Method 2: perform a complete scan and write down the logarithm of the points that can be connected. If the connection fails once, subtract one from the number. Of course, this is not necessarily a minus one, but it may be a minus two, it may also increase by 1, increase by 2. As to why, we should know that here I take the subtraction. If the logarithm of the connected vertex is smaller than 1, it will be scanned once, we get the number of remaining points that can be connected. If the value is smaller than 1, no solution is available. A simple explanation of implementation: Point indicates a Point on the coordinate axis. All implementations are based on the Point concept. The image or button clicked by the user indicates a Point, one point is the two coordinate X axis and Y axis, with some other auxiliary methods. # Pragma once // indicates a Point on the coordinate axis [X, Y] struct Point {Point (): X (-1), Y (-1) {} Point (int _ x, int _ y): X (_ x), Y (_ y) {} Point (const Point & p): X (p. x), Y (p. y) {} Point & operator = (const Point & p) {X = p. x; Y = p. y; return * this;} inline bool operator = (const Point & p) {return X = p. X & Y = p. y;} inline bool operator = (Point & p) {return X = p. X & Y = p. y;} inline bool operator! = (Const Point & p) {return X! = P. X | Y! = P. Y;} inline bool operator! = (Point & p) {return X! = P. X | Y! = P. Y;} int X; // X axis int Y; // Y axis}; TwoPoint is a simple package for two vertices. The user needs to click two points. I will use this class to wrap these two points and connect them to a maximum of two inflection points (when three lines are required to connect the two points ), we can still use TwoPoint to wrap these two inflection points and attach some other auxiliary methods. # Pragma once // used to record the two points clicked by the user. class TwoPoint {public: TwoPoint ();~ TwoPoint (); // Add Point bool AddPoint (const Point & p); // The number of points int Count () const; Point First () const; void First (const Point & p); Point Second () const; void Sort (); void Clear (); private: TwoPoint (const TwoPoint & p ); twoPoint & operator = (const TwoPoint & p); Point * first; Point * second; int count ;}; PathRecord indicates the two click inflection points clicked by the user, all vertices connected in sequence are mainly used for testing. # Pragma once // stores all vertices of The Link. class PathRecord {public: // clears all elements in the Set void Clear (); void AddPoint (const Point & p ); // Add a vertex void AddPointLine (const Point & first, const Point & second); // Add void AddPoint (const Point & first, const Point & center1, const Point & second); void AddPoint (const Point & first, const Point & center1, const Point & center2, const Point & second );~ PathRecord (); Point * operator [] (int index); int Size (); private: vector <Point *> pointVector ;}; pathFind is mainly used to test whether two points can be connected successfully. The core implementation of the training is him. # Pragma once extern DType A [row] [column]; // pathing, main logic implementation class PathFind {public: PathFind ();~ PathFind (); bool Left (const Point & first, const Point & second); bool Right (const Point & first, const Point & second); bool Top (const Point & first, const Point & second); bool Bottom (const Point & first, const Point & second); bool Center (const Point & first, const Point & second ); bool OneLine (TwoPoint & endPoint); bool OneLine (const Point & first, const Point & second); bool MoreLine (TwoPoint & endPoint); bool Mo ReLine (const Point & first, const Point & second); bool Near (TwoPoint & endPoint); bool Near (const Point & first, const Point & second ); bool Search (TwoPoint & endPoint); bool Search (const Point & first, const Point & second); private: // determine whether the two points are in the same vertical line as Y bool SameY (const Point & first, const Point & second ); // determine whether the two clicks are on the same horizontal line as X bool SameX (const Point & first, const Point & second) ;}; check result to determine whether the two clicks are successful or unsolved. # Pragma once // result determination-determines whether it is a dead state or has passed the class CheckResult {public: CheckResult (); CheckResult (int _ leftPoint); int LeftPoint () const; // return the remaining vertex int LeftLinkLine (); // The connectable vertex logarithm void SearchLeftLinkLine (); // query the connectable vertex logarithm void SearchLeftPoint (); // query the remaining number of vertices bool performance2point (); // reduce the remaining two vertices bool IsSuccess (); // determine whether bool IsNoSolution () is successful; // whether it is unsolvable private: int leftPoint; // The remaining vertex is used to determine whether the volatile int leftLinkLine is terminated; // the logarithm of the connectable vertex is used to determine whether the node is dead. }; IntelligentTest: the intelligent test is to enable the computer to come and play in the Connected View. It turns out that the computer has played very fast and is mainly used for testing. After his test, he will know whether there is a problem with the program implementation. This is also a key step. Some problems have been found during the test, which is also a rare test-related code. I personally think that writing test code by myself is much better than testing manually. # Pragma once // intelligent test class IntelligentTest {public: IntelligentTest (); void Remove (const Point & p); // delete a successfully connected Point GetFirstPoint (); // obtain the first vertex Point GetSecondPoint (); // obtain the second vertex void AddHasReadPoint (const Point & p ); // Add the retrieved vertex (which does not match the vertex) to the hasReadList private: void InitDataBind (); // Add the coordinates of all non-empty points (a value) to the int firstIndex of the set noReadList; // The index int secondIndex of the first point in the Set; // Index vector <int> hasReadList; // stores the read vertex information vector <int> noReadList; // stores the remaining vertex information }; the START image and running time are as follows:
The steps for Intelligent Testing and automatic playback of a program are as follows: