static public bool MoveNext(this iBoard b, ref MoveType lastMove) { while (lastMove < MoveType.Stop) { lastMove = lastMove + 1; switch (lastMove) { case MoveType.Left: case MoveType.Up: case MoveType.Right: case MoveType.Down: if (b.Move(lastMove)) { return(true); } break; } } if (b.Steps.Any()) { UndoStep last = b.PeekStep(); lastMove = last._type; b.UndoMove(); return(b.MoveNext(ref lastMove)); } else { return(false); } }
static public void Solve(this iBoard b, Func <bool> canceler) { MoveType lastMove = MoveType.Start; while (!canceler() && !b.IsSolved() && b.MoveNext(ref lastMove)) { lastMove = b.IsInDeadLock() ? MoveType.Stop : MoveType.Start; Thread.Sleep(1000); } }