Core game algorithm round 18-proof of NP completeness of the Zen puzzle garden level)

Source: Internet
Author: User

Well, after glow puzzle is over, let's talk about the previous game-Zen puzzle garden. Here we mention a person, sevenkplus, Gu Weizhou, who is called Gu Shen, last week, I happened to join the poj Organizing Committee, and I happened to have met the ghost edition of Gu xiaozhou kids shoes, and I accidentally added him, some of them are accidental (some pictures can prove it !). The so-called sevenkplus means 7 K +, and 7 K + means that the code length (length) is more than 7 kb, that is, about 350 lines. In ACM, the total number of lines of code is less than 150, so an occasional 7 K + is a terrible thing.

The logic code of the Zen puzzle garden section is complicated. I am still asking the teacher to fully understand it. When studying the AI of this game, I accidentally found a paper that was found on daokebaba. This paper is in English and has not been translated yet. So I have to translate it myself.

The original article proves that the game's level is NP complete, I add the original English site here, for readers as a reference: http://www.doc88.com/p-608927729422.html

Zen puzzle garden is NP-complete

Robin Houston, joseph white, Martyn Amos
(Translated by Wu Hao)
Key words: computing complexity NP-completeness puzzles (I think of Niya)


1. Introduction


Zen puzzle Garden (zpg) is a single machine puzzle game that occurs on a two-dimensional square partition. It is called Garden ). Blocks can be sand, stones, or open spaces ). The game's task is to move a monk around the square to cover all the squares. Monks can freely move on the open space. In the sand, monks can only move along the neighborhood of von noiman (for example, diagonal movement is not allowed ). When walking on the sand, the monk continued to move straight toward him until he met a square that he could walk (he would move to the top ), A square or stone that covers the sand (in either case, he stops moving ). The Monk does not stop moving on the sand. The example of a garden is described in the form of Figure 1 and a sample solution is given.

 

1: zpg sample garden with an answer. The sand is white, the area where you can walk is blue, and the stones are black.

Although this problem has been studied in an experiment (based on a method similar to Monte Carlo), there has been no formal proof of its time complexity up to now. We now claim that the complexity of zpg's solution is NP-complete.

Theorem 1: determine that the solution of a Zen puzzle garden instance is NP complete.
Next, let's create a proof for the next NP complete problem and give a cubic plot. Does it contain a one or two Hamilton loops? We construct a zpg garden that corresponds to any cubic plot, and any garden we build will have a solution when and only when the corresponding chart has a Hamilton loop.

 

Figure 2: The picture on the left is in the form of a straight line, and the picture on the right has a corner


2. Proof


To create a zpg garden that reflects a cubic plot G, we first draw this figure in a grid. This is often done in this way-the area of the grid is the second side of the graph size. We convert the lattice into zpg garden as follows. Each grid block is converted into a 7*7 tile consisting of stones, sand, or walking areas. Each square in the grid is composed of a straight edge, a corner, or a node where three event edges meet. The previous two tiles are described in the form of Figure 2, which can be rotated as needed.

 

In Figure 3, the left side is the knots, and the right side is a sample path.

Node bricks and tiles are built in this way. No matter which sandland is first covered, we can always overwrite the remaining sandland, and from any of the remaining directions (3 ).

 

(Figure 4: Cube Plan)

In Figure 4, we show a cubic plot and Its zpg presentation. The Start Node is marked in red, and the Hamilton circuit is highlighted in bold.

 

(Figure 4: zpg)

In the zpg presentation, the starting node can be regarded as composed of two tiles, occupying the positions (3, 6) AND (3, 5 ). The top-level tiles are completely described as walking blocks, which are the initial locations of monks. The following tiles are a simple "ENTRANCE" tile, it is described in the third image in Figure 4. This brick is a simulated node Brick, where two of the top stone has been converted into sand. The first sand to be covered can only be one of the two, and the last sand to be crossed must also be another. This helps to exit and return to the starting node. Any solution must be available only once through all other nodes. Therefore, any solution to the zpg problem must have an Hamilton loop in the figure.

(Figure 4: entrance tiles)

We learned from [3] that a cube with N nodes can be implemented by area O (N ^ 2) of a grid, the implementation of this grid can be calculated as time complexity O (nlogn), so the map from the cubic plot to the zpg Garden (game interface) is of the polynomial type. A solution can be easily found in polynomial time, because a solution will not be greater than the solution described above ), this completely proves that the zpg level is NP-complete.

 

 

 

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.