X01.Weiqi. 11

Source: Internet
Author: User

X01.Weiqi. 11

In go, a pair of dual functions can be described as a magic bullet, while a pair of three functions can be called a magic bullet. When solving the issue, I accidentally came up with the following code:

// Subquery: p1 and p2 are gas, p2 is the forward direction, and p is the child of escape. Bool CanLevy (Pos p1, Pos p2, Pos p, bool isBlack = true) {if (! IsCusp (p1, p2) return true; if (p = m_InvalidPos) return true; List <Pos> selfPoses = isBlack? BlackPoses: WhitePoses; List <Pos> otherPoses =! IsBlack? BlackPoses: WhitePoses; // when called, don't laugh? Var p1_links = LinkPoses (p1 ). intersect (otherPoses ). toList (); if (p1_links.Count = 1 & p1_links.Intersect (EmptyPoses ). count () = 2) return false; var p2_links = LinkPoses (p2 ). intersect (otherPoses ). toList (); if (p2_links.Count = 1 & p2_links.Intersect (EmptyPoses ). count () = 2) return false; int count = 0; while (true) {if (! InRange (p2.Row, p2.Col) break; bool isRow = p2.Row-p. Row = 0? True: false; int rowOffset = isRow? (Count = 0? P1.Row-p2.Row: p2.Row-p1.Row): 0; int colOffset = isRow? 0: (count = 0? P1.Col-p2.Col: p2.Col-p1.Col); Pos pos = new Pos (p2.Row + rowOffset, p2.Col + colOffset); var rounds = count <5? LinkPoses (pos): RoundTwoPoses (pos); foreach (var r in rounds) {if (isBlack & count <2) continue; // black requires two steps first if (selfPoses. contains (r) return false; if (otherPoses. contains (r) {return true;} count ++; p1 = p; p = p2; p2 = pos;} return true ;}

Among them, the count variable controls the symbol Conversion (count = 0), excluding the old (count <5) and Black play (count <2, in addition, all three cases are indispensable.

Now we can look at it:

When the White 10 expedition, can not escape, the computer chooses the Black 11, and the white 12, can escape, the computer is a smart choice of the Black 13, is perfect!

For more information about downloading the complete code, see the previous blog.

Related Article

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.