QQ connection check plug-in core algorithm (check whether two points can be connected)

Source: Internet
Author: User
Bool Check2p (POINT a, POINT B) // The p1, p2 {CChessPoint p1 (a), p2 (B) of the two target pawns are transmitted here ); // two class objects are declared here. The specific class contains the upper and lower POINT pa and pa of p1 and p2; // Two Corner Points if (. x = B. x) & (. y = B. y) // a is the p1 pawn, B is the p2 pawn {return false;} else if (chessdata [. y] [. x] = 0) | (chessdata [B. y] [B. x) = 0) // if the p1 pawns are empty {return false;} // false else if (chessdata [. y] [. x]! = Chessdata [B. y] [B. x]) // if the p1 value is different from p2 {return false;} // false if (. y = B. y) // p1 and p2 are in the horizontal line (y coordinate is the same) {// 2 points are adjacent to the horizontal line if (p1.right. x = p2.left. x) | (p1.left. x = p2.right. x) {return true;} // checks whether this line has a path if (CheckLine (p1.right, p2.left) // checks two points, and submits the result to CheckLine {return true ;} // detect the upper and lower inflection points, with the target chess piece as the center // vertical direction: Upper (y direction: Upper) pa = a; pb = B; // The p1 attribute gives the inflection point pa, and the p2 attribute gives pb. In any case, Initialization is the most time for them! If (p1.up. y> = 0) & (p1.up. y <= 10) // It is controlled within 11 cells for (y = 0; y <p1.up. y; y ++) // from the top loop, to the p1 stop loop, two upward rays are displayed vertically, {pa. y = y; pb. y = y; // The two inflection points are parallel, so y is the same if (CheckLine (pa, p1.up) & CheckLine (pb, p2.up) & CheckLine (pa, pb) // two upward rays are displayed along the longitudinal direction, check whether the "inflection point" pa can connect to the point above p1 & check whether the point above p2 is connected to the point above the "inflection point" pb & whether the two inflection points can be connected, all three are OK, {return true ;}// the vertical direction is: Bottom (y direction: Bottom) pa = a; pb = B; if (p1.down. y> = 0) & (p1.down. y <= 10) for (y = p1.down. y; y <= 10; y ++) // starts from its own cycle and stops at 11 cells (bottom) {pa. y = y; pb. y = y; // The two inflection points are parallel, so y is the same if (CheckLine (pa, p1.down) & CheckLine (pb, p2.down) & CheckLine (pa, pb) // same as {return true ;}} else // if (. x = B. x) {// x adjacent upper and lower if (p1.down. y = p2.up. y) | (p1.up. y = p2.down. y) {return true;} // check whether a path is the same as if (CheckLine (p1.down, p2.up) {return true ;} // check up and down // horizontal left pa = a; pb = B; for (x = 0; x <= p1.left. x; x ++) {pa. x = x; pb. x = x; if (CheckLine (pa, p1.left) & CheckLine (pb, p2.left) & CheckLine (pa, pb) {return true ;}} // x right pa = a; pb = B; for (x = p1.right. x; x <= 18; x ++) {pa. x = x; pb. x = xif (CheckLine (pa, p1.right) & CheckLine (pb, p2.right) & CheckLine (pa, pb) {return true ;}} else // xy axes are different {pa = a; pb = B; if (. x> B. x) {// p1.x> p2.x (p1 on the right, p2 on the left) for (x = 0; x <= p2.left. x; x ++) // from the Left Loop, to p2 stop the loop, two upward rays are displayed horizontally {pa. x = x; pb. x = x; // two left-facing rays if (CheckLine (pa, p1.left) & CheckLine (pa, pb) & CheckLine (pb, p2.left. x) {return true ;}// end forfor (x = p2.right. x; x <p1.left. x, x ++) // loop to p1.left, proximity principle {pa. x = x; pb. x = x; if (CheckLine (p2.right, pb) & CheckLine (pa, pb) & CheckLine (p1.left, pa) {return true ;}} for (x = p2.right. x; x <= 18; x ++) {pa. x = x; pb. x = x; if (CheckLine (p1.right, pa) & CheckLine (p2.right, pb) & Check (pa, pb) {return true ;}} ///// // find the Y axis path. Because the path is tested from top to bottom, p1.y> p2.ypa. x =. x; pb. x = pb; // initialize the inflection point for (y = 0; y <= p1.up. y; y ++) // segment 1 {pa. y = y; pb. y = y; if (CheckLine (pb, pa) & CheckLine (pa, p1.up) & CheckLine (pb, p2.up) {return ture ;}} for (y = p1.down. y; y <= p2.up. y; y ++) // proximity principle {pa. y = y; pb. y = y; if (CheckLine (pb, pa) & CheckLine (p1.down, pa) & CheckLine (pb, p2.up) {return ture ;}} for (y = p2.down. section y; y <= 10; y ++) // you can think about the {pa. y; pb. y = y; if (CheckLine (pb, pa) & CheckLine (p1.down, pa) & CheckLine (p2.down, pb) {return ture ;}}} else ////////// point p2 on the right. x> B. x {pa. y =. y; pb. y = B. y; // initialize coordinates for (x = 0; x <= p1.left. x; x ++) {pa. x = x; pb. x = x; if (CheckLine (pa, pb) & Check (pa, p1.left) & CheckLine (pb, p2.left) {return true ;}} for (x = p1.right. x; x <= p2.left. x; x ++) {pa. x = x; pb. x = x; if (CheckLine (pa, pb) & CheckLine (p1.right, pa) & CheckLine (pb, p2.left) {return true ;}} for (x = p2.right. x; x <= 18; x ++) {pa. x = 0; pb. x = x; if (CheckLine (pa, pb) & CheckLine (p1.right, pa) & CheckLine (p2.right, pb) {return ture ;}}} //// yyyyyyyyyyyyyyyyyy Y-axis gradient pa. x =. x; pb. x = B. x; // initialize the inflection point if (p1.up. y> = 0) & (p1.up. y <= 10) {for (y = 0; y <= p1.up. y; y ++) {pa. y = y; pb, y = y; if (CheckLine (pa, pb) & CheckLine (p1.down, pa) & CheckLine (pb, p2.up )) {return true ;}}/// pa. x =. x; pb. x = B. x; // initialize the inflection point if (p1.down. y <= 10) & (p2.up. y> = 0) {for (y = p1.down. y; y <= p2.up. y; y ++) {pa. y = y; pb. y = y; if (CheckLine (pa, pb) & CheckLine (p1.down, pa) & CheckLine (pb, p2.up) {return true ;}} //// pa. x =. x; pb. x = B. x; // initialize the inflection point if (p2.down. y <= 10) for (y = p2.down. y; y <= 10; y ++) {pa. y = y; pb. y = y; if (CheckLine (pa, pb) & CheckLine (p1.down, pa) & CheckLine (p2.down, pb) {return true ;}}}}}} // bool ends

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.