📜 ⬆️ ⬇️

6 games in 6 weeks - the third game

On Friday must be seals. I have them.

image

Game three - B4 .
This is real solitaire. Difficult, as request in Perl.
Therefore, success will be enjoyed only by mathematicians from Habr and travelers on the Moscow-Yekaterinburg train.
')
In my report, I briefly (lines 40) will talk about the generation of layouts, put forward a lemma on the convergence of any alignment that has two degrees of freedom and demonstrate how I was a boot, and became a grandfather.

For comments, zikher has proposed a counter-example that seems to disprove the lemma. But an example decided.



rules


The rules are the same as in the game Four rooms . The room is colored trash. Garbage can be driven around the room with a finger movement across the screen - either horizontally or vertically.
Red trash can be thrown through the red wall. Yellow trash - through the yellow. Blue through blue. Blue - blue. No more rules.

Is it clear? Let us turn to examples.

Look at Figure 1. It is necessary to clear the room of colored debris.

image
Figure 1. The simplest alignment

The alignment solution in Figure 1 consists of two moves.
  1. move the chips to the right (the red garbage will disappear through the red wall)
  2. move the chips up (blue trash disappears)

Solitaire resolved.

In Figure 2, the example is more complicated.

image
Figure 2. If the first move to make up - solitaire does not converge.

The alignment solution in Figure 2 consists of five moves.
  1. move the chips to the right
  2. move the chips down
  3. move the chips to the left (yellow trash disappears)
  4. move the chips up (blue trash disappears)
  5. move the chips to the right

Solitaire resolved.

Example number 66




Hand Generation


Solitaire generation is very important. On the one hand, they should be random, on the other hand, there should always be an opportunity to repeat a random alignment - either toss it to a friend on the weak !, or to play it again.

The problem is that my game is universal - there is a game for iPhone, and there is an Internet option. How to achieve the same alignment in Objective C and JavaScipt?

Oddly enough - the solution lies in Visual Studio from Microsoft.

I climbed into the VS library math and pulled out the code for the function of pseudo-random number generation.

- (int)microsoft_rnd { holdrand = holdrand * 214013 + 2531011; return ((holdrand >> 16) & 0x7FFF); } 


Setting the initial value in the global variable holdrand - I can repeat a random sequence as many times as I want. For convenience, I started 1,000,000 initial layouts and expanded the functionality of my class.

 - (int) microsoft_rand:(int) number{ return [self microsoft_rnd] % number; } //    -      1 - 4 ... int k = 1 + [self microsoft_rand:4]; ... 


This function looks slightly different in JavaScript
 function microsoft_rnd() { var r; var big = 4294967295+1; microsoft_rnd.seed = (microsoft_rnd.seed * 214013 + 2531011)%big; r = microsoft_rnd.seed; r = Math.floor(r/65536); r = r%32768; return r; } function microsoft_rand(number) { return (microsoft_rnd())%number; }; 


It was experimentally verified that the result of the function in all systems is identical.

Thus, setting the holdrand equal, for example, 2015, I get the same layout both on the iPhone and in the browser.

How I checked the game



The first time I started the game, I was upset. The alignment I chose did not converge. I wound up. That is, he started a big picture with a pretty aunt, closed it with buttons from 256 first layouts and started playing with the mind. With the right decision of the next scenario, the button disappeared and the aunt became exposed.
As a result, on the third day I decided to 255 out of 256 hands. I could not solve only one - in which initially there was no movement across.

This is where the lemma was born, which it could not prove - in the presence of two degrees of freedom, any complete solitaire is collected on a board 5 to 5 and higher.

Have a great weekend everyone


Thank you for your attention, the animation of the seals dancing the Nanai boys - exclusively to the sages who have created solitaire.

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


All Articles