Exemplo n.º 1
0
 public MatchModel(ushort id, ushort currentPlayerClientID)
 {
     Id = id;
     CurrentPlayerClientID = currentPlayerClientID;
     slates        = new SlateStatus[9];
     OnBoardChange = new BoardChangeEvent();
 }
Exemplo n.º 2
0
        private bool BacktrackingContinue(Board board)
        {
            bool isComplete;

            try
            {
                isComplete = board.IsComplete();
            }
            catch (Exception)
            {
                return(false);
            }

            if (isComplete)
            {
                return(true);
            }

            for (var i = 0; i < _cells.Length; i++)
            {
                if (board[i].Digit == 0)
                {
                    var posDigit = board[i].Candidates;
                    foreach (var x in posDigit)
                    {
                        var newBoard = (Board)board.Clone();
                        var result   = newBoard.SetDigit(i, x, true);
                        newBoard[i].IsGiven = false;
                        BoardChangeEvent?.Invoke(newBoard, new SudokuEvent {
                            Action = CellAction.SetDigitInt, ChangedCellBase = newBoard[i]
                        });
                        if (!result.Successful)
                        {
                            continue;
                        }

                        try
                        {
                            isComplete = newBoard.IsComplete();
                        }
                        catch (Exception)
                        {
                            return(false);
                        }

                        if (isComplete)
                        {
                            for (var s = 0; s < _cells.Length; s++)
                            {
                                _cells[s]._candidateValueInternal = 0;
                                _cells[s]._digit = newBoard._cells[s].Digit;
                            }

                            return(true);
                        }

                        if (BacktrackingContinue(newBoard))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
            }

            return(false);
        }