Understanding Gratings

I am studying a computer question that they burned me in my second test interview test after a very successful first interview. Otherwise, I would consider it a slipper.

Basically, I was supposed to use a minesweeper using lattice cells in less than 2 hours.

Where, if it's 1X1, there is one cell.

Then, if it is 2X2, one cell has four cells (children?), Each of which is twice connected to the parent. In addition, 2 children are doubly connected to each other. And two other children.

Switching from a child cell to another child cell means that you just have to go to the next link (laughs), or first return to the parent and then to the recipient in another child link pair (Note: the idea of ​​tree is just my idea, not a requirement)

The general idea that I had was to create a mechanism for creating a template, which then becomes more and more, implicitly, according to the depth parameter. It seems that looking at the tree structure was the best approach.

It seemed simple enough. But I just could not make out the logic for creating the template:

Tree structures with several children are light enough (oct-tree, quad-tree, binary tree, etc.), but they come up with an elegant system where, when a parent gives birth to several children, the children are also implicitly related to me were only single brothers and sisters. So, in essence, in my idea, the root is the center of the trellis diagram, and the furthermost child nodes are located at the edges.

In addition, there may be many aspects of lattice cells that I do not understand. I rummaged through the Internet, trying to find an explanation of why, and how it is useful. I found a tutorial on this subject that talks about the basics of logic: partially ordered sets, force sets, reflexivity, and trellis diagrams based on these principles, such as the Hasse diagram.

However, this is still not enough for me: there were no C ++ examples or even pseudocode.

I understand hash tables, linked lists, reversed linked lists (recursive / iterative), binary trees (balanced / unbalanced), vectors, rows, reversals, etc. (all basic fundamentals). Trig, linear algebra, quaternions. Some Calc. And many graphical programming tricks / tricks. I even wrote two game engines from scratch, but due to problems with the grill I managed to avoid. I am embarrassed. I want to learn more about gratings, so I never burn again. However, the required documentation is difficult to find.

I'm looking for a good tutorial on the topic of lattices (as regards writing algorithms in C ++) - I hope the one that holds my hand (from beginner to forward) like a typical Sam teaches himself C ++ in 21 days or something in that kind of thing. Since the gratings seem intermediate and very advanced, this may not be possible.

If not for the textbook, if any of you could kindly give me what knowledge you have on this topic, I would be very grateful.

Thanks.

+4
source share
1 answer

The confusion arises from the misleading use of the word lattice: in mathematics, the lattice is a collection in which each two elements have lub (the smallest upper bound) and glb (the largest lower bound). The "tree" of the game (nodes are states of the board, the edges of the movements obviously do not have any glb due to the unique property of the tree paths), even if you join identical states that are achieved using different sequences of moves (in this case, the tree becomes a directed graph ), will not have glb, if from a given state you can reach two different final states. I have not played minesweeper for a decade, but I have the impression that you can end the game like that. Thus, the basic data structure that you should think about is a directional (possibly acyclic) graph, which is sometimes a grid (ignoring the directions at the edges) in a mathematical sense, but not always.

+1
source

Source: https://habr.com/ru/post/1434495/


All Articles