. , / / (, ).
- , , , . . , , . 3 6 9 . , :
0 1 2
3 4 5
6 7 8
, 4, 1, 3, 5, 7 , , . 4 3,5 2371 . 4, 1, 5, 2, 7, 8, 3, 0, 6, 1,2 813 , . , - , (0, 1, 3, 4, 2, 5, 6, 7, 8). , , .
Step[] Steps = {
new Step() { Type = 0, Position = 4 },
new Step() { Type = 1, Position = 1, MatchP1 = 4, MatchO1 = 0 },
new Step() { Type = 1, Position = 5, MatchP1 = 4, MatchO1 = 1 },
new Step() { Type = 2, Position = 2, MatchP1 = 5, MatchO1 = 0, MatchP2 = 1, MatchO2 = 1 },
new Step() { Type = 1, Position = 7, MatchP1 = 4, MatchO1 = 2 },
new Step() { Type = 2, Position = 8, MatchP1 = 7, MatchO1 = 1, MatchP2 = 5, MatchO2 = 2 },
new Step() { Type = 1, Position = 3, MatchP1 = 4, MatchO1 = 3 },
new Step() { Type = 2, Position = 0, MatchP1 = 1, MatchO1 = 3, MatchP2 = 3, MatchO2 = 0 },
new Step() { Type = 2, Position = 6, MatchP1 = 3, MatchO1 = 2, MatchP2 = 7, MatchO2 = 3 },
};
, , , . 1 - , 2 - , 3 - /, 4 - . xor 0x10, , . , xor 2 0x10, , , xor 0x10, .
Card[] cards = {
new Card(0x01, 0x03, 0x14, 0x12),
new Card(0x02, 0x14, 0x13, 0x01),
new Card(0x03, 0x11, 0x12, 0x04),
new Card(0x01, 0x13, 0x12, 0x04),
new Card(0x11, 0x13, 0x04, 0x03),
new Card(0x04, 0x11, 0x12, 0x01),
new Card(0x04, 0x02, 0x14, 0x13),
new Card(0x02, 0x14, 0x13, 0x01),
// new Card(0x01, 0x13, 0x12, 0x04) // no solution
new Card(0x01, 0x11, 0x12, 0x04) // 4 solutions
};
, , , . NextType ( ) , :
public CardImageOrientation[][] Orientations { get; set; }
public struct CardImageOrientation
{
public int CardIndex;
public int TypePosition;
public int NextType;
}
:
public bool Method1Step(int stepIndex)
{
StepCalls++;
if (stepIndex > 8)
{
FindCount++;
return !Exhaustive;
}
Step step = Steps[stepIndex];
switch (step.Type)
{
case 0:
for (int i = 0; i < 9; i++)
{
PlaceCard(i, 4, 0);
steppedUp = true;
if (Method1Step(stepIndex + 1))
return true;
RemoveCard(4);
}
break;
case 1:
case 2:
Card card = Cards[CardIndices[step.MatchP1]];
int type = card.Types[(step.MatchO1 - card.Orientation + 4) & 0x03];
int orientation2 = (step.MatchO1 + 2) & 0x03;
int searchType = type ^ 0x10;
for (int i = 0; i < Orientations[searchType].Length; i++)
{
CardImageOrientation cio = Orientations[searchType][i];
if (Cards[cio.CardIndex].Position < 0)
{
if (step.Type == 1 || (
step.Type == 2 &&
(Cards[CardIndices[step.MatchP2]].Types[(step.MatchO2 - Cards[CardIndices[step.MatchP2]].Orientation + 4) & 0x3] ^ cio.NextType) == 0x10)
) {
int newOrientation = (orientation2 - cio.TypePosition + 4) & 0x03;
PlaceCard(cio.CardIndex, step.Position, newOrientation);
if (Method1Step(stepIndex + 1))
return true;
RemoveCard(step.Position);
}
}
}
break;
}
return false;
}
: 4 9999 , 1 9999. , 3,465 1555 7,2 , .72 . 4,16 Method1Step().