예제 #1
0
        //
        // Set a number
        //
        private void SetNumber(uint pos, uint number)
        {
            var cell = UICells[pos];

            // Wipe out possibles
            cell.ResetPossibles();

            // memorize the number
            puzzle.Guesses[pos] = number;

            // Evaluate the correctness
            userTable = creator.Evaluate(puzzle);
            if (userTable == null)
            {
                // User selection makes puzzle impossible!
                cell.SetNumberStatus(true);
            }
            else
            {
                cell.SetNumberStatus(false);

                // Update all number and all possibles
                UpdateAllNumberAndPossibleStatus();

                if (userTable.IsSolved)
                {
                    // Finished
                    UpdateSelection(uint.MaxValue);
                    PuzzleSolved?.Invoke(this, EventArgs.Empty);
                }
            }

            // Display it
            cell.SetNumber(number);
        }
예제 #2
0
        public async Task TrySolve(string number, string input, SocketGuildUser solver)
        {
            if (IsFinished != true)
            {
                if (CurrentLockNumber.HasValue)
                {
                    var curLock = Locks.FirstOrDefault(x => x.LockNumber == CurrentLockNumber.Value);
                    if (curLock.TrySolve(number, input, solver))
                    {
                        CurrentOrderIndex++;
                        if (CurrentOrderIndex >= 10)
                        {
                            IsFinished = true;
                            StringBuilder builder = new StringBuilder();
                            builder.AppendLine("```LOCK::LIFTED");
                            builder.AppendLine("SOLVERS::PRINT()");
                            var users = Locks.Select(x => x.Solver).Distinct();
                            foreach (var user in users)
                            {
                                int amountSolved = Locks.Count(x => x.Solver.Id == user.Id);
                                builder.AppendLine($"SOLVER::{user.Nickname}|ID::{user.Id}|SOLVED::{amountSolved}");
                            }
                            builder.AppendLine($"|{new string('-', 10)}PUZZLE_OVER{new string('-', 10)}|```");
                            await PresentationMessage.ModifyAsync(x => x.Content = builder.ToString());

                            PuzzleSolved?.Invoke(this.Guid);
                        }
                        else
                        {
                            if (CurrentOrderIndex > 0)
                            {
                                PreviousLockNumber = NumbersOrder[CurrentOrderIndex - 1];
                            }
                            else
                            {
                                PreviousLockNumber = null;
                            }
                            if (NumbersOrder.ElementAtOrDefault(CurrentOrderIndex) != 10)
                            {
                                CurrentLockNumber = NumbersOrder[CurrentOrderIndex];
                            }
                            else
                            {
                                CurrentLockNumber = null;
                            }
                            if (NumbersOrder.ElementAtOrDefault(CurrentOrderIndex + 1) != 0)
                            {
                                NextLockNumber = NumbersOrder[CurrentOrderIndex + 1];
                            }
                            else
                            {
                                NextLockNumber = null;
                            }
                            await LockSolved?.Invoke();
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Solves the provided puzzle.
        /// </summary>
        /// <param name="puzzle"></param>
        public void Solve(Puzzle puzzle)
        {
            this.Puzzle = puzzle;

            // Start the recursive solving from the first cell
            Task.Run(async() =>
            {
                await PerformSolve(0, 0);

                // Once this finishes, if the puzzle is solved then fire off the event.
                if (IsPuzzleSolved())
                {
                    PuzzleSolved?.Invoke(this, new PuzzleSolvedEventArgs {
                        Puzzle = Puzzle
                    });
                }
            });
        }
예제 #4
0
 private void PuzzleSolved()
 {
     puzzleSolved.Invoke();
 }