Skip to content

Commit 4b8eabc

Browse files
author
RUBIUS\chebanovdd
committed
Refactoring.
1 parent 381a73b commit 4b8eabc

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

src/Match3.Template/GameBoardSolver.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.Linq;
4+
using System.Runtime.CompilerServices;
45
using Match3.App;
56
using Match3.App.Interfaces;
67
using Match3.Core.Interfaces;
@@ -40,21 +41,9 @@ public SolvedData<TGridSlot> Solve(IGameBoard<TGridSlot> gameBoard, params GridP
4041
continue;
4142
}
4243

43-
foreach (var specialItemDetector in _specialItemDetectors)
44+
foreach (var specialItemGridSlot in GetSpecialItemGridSlots(gameBoard, sequence))
4445
{
45-
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
46-
{
47-
foreach (var specialItemGridSlot in specialItemDetector.GetSpecialItemGridSlots(gameBoard, solvedGridSlot))
48-
{
49-
if (specialItemGridSlot == null || specialItemGridSlot == solvedGridSlot)
50-
{
51-
continue;
52-
}
53-
54-
specialItemGridSlots.Add(specialItemGridSlot);
55-
}
56-
57-
}
46+
specialItemGridSlots.Add(specialItemGridSlot);
5847
}
5948

6049
resultSequences.Add(sequence);
@@ -72,5 +61,26 @@ private bool IsNewSequence(ItemSequence<TGridSlot> newSequence, IEnumerable<Item
7261

7362
return sequencesByType.All(sequence => sequence.SolvedGridSlots.Contains(newSequenceGridSlot) == false);
7463
}
64+
65+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
66+
private IEnumerable<TGridSlot> GetSpecialItemGridSlots(IGameBoard<TGridSlot> gameBoard,
67+
ItemSequence<TGridSlot> sequence)
68+
{
69+
foreach (var itemDetector in _specialItemDetectors)
70+
{
71+
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
72+
{
73+
foreach (var specialItemGridSlot in itemDetector.GetSpecialItemGridSlots(gameBoard, solvedGridSlot))
74+
{
75+
if (specialItemGridSlot == null || specialItemGridSlot == solvedGridSlot)
76+
{
77+
continue;
78+
}
79+
80+
yield return specialItemGridSlot;
81+
}
82+
}
83+
}
84+
}
7585
}
7686
}

src/Match3.UnityPackage/Assets/Plugins/Match3/Runtime/Match3.Template/GameBoardSolver.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.Linq;
4+
using System.Runtime.CompilerServices;
45
using Match3.App;
56
using Match3.App.Interfaces;
67
using Match3.Core.Interfaces;
@@ -40,21 +41,9 @@ public SolvedData<TGridSlot> Solve(IGameBoard<TGridSlot> gameBoard, params GridP
4041
continue;
4142
}
4243

43-
foreach (var specialItemDetector in _specialItemDetectors)
44+
foreach (var specialItemGridSlot in GetSpecialItemGridSlots(gameBoard, sequence))
4445
{
45-
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
46-
{
47-
foreach (var specialItemGridSlot in specialItemDetector.GetSpecialItemGridSlots(gameBoard, solvedGridSlot))
48-
{
49-
if (specialItemGridSlot == null || specialItemGridSlot == solvedGridSlot)
50-
{
51-
continue;
52-
}
53-
54-
specialItemGridSlots.Add(specialItemGridSlot);
55-
}
56-
57-
}
46+
specialItemGridSlots.Add(specialItemGridSlot);
5847
}
5948

6049
resultSequences.Add(sequence);
@@ -72,5 +61,26 @@ private bool IsNewSequence(ItemSequence<TGridSlot> newSequence, IEnumerable<Item
7261

7362
return sequencesByType.All(sequence => sequence.SolvedGridSlots.Contains(newSequenceGridSlot) == false);
7463
}
64+
65+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
66+
private IEnumerable<TGridSlot> GetSpecialItemGridSlots(IGameBoard<TGridSlot> gameBoard,
67+
ItemSequence<TGridSlot> sequence)
68+
{
69+
foreach (var itemDetector in _specialItemDetectors)
70+
{
71+
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
72+
{
73+
foreach (var specialItemGridSlot in itemDetector.GetSpecialItemGridSlots(gameBoard, solvedGridSlot))
74+
{
75+
if (specialItemGridSlot == null || specialItemGridSlot == solvedGridSlot)
76+
{
77+
continue;
78+
}
79+
80+
yield return specialItemGridSlot;
81+
}
82+
}
83+
}
84+
}
7585
}
7686
}

0 commit comments

Comments
 (0)