コード例 #1
0
ファイル: CPSolver.cs プロジェクト: arashout/SudokuSolveCP
        /// <summary>
        /// Assign a single value to the tile, propagate the changes via calls to Eliminate
        /// NOTE: Method mutates the CPBoard cpb parameter
        /// </summary>
        /// <param name="cpb"></param>
        /// <param name="tileIndex"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        static public bool Assign(CPBoard cpb, int tileIndex, string value)
        {
            CDebug.Assert(value.Length == 1, "Cannot assign multiple values");
            var values = cpb.Get(tileIndex);

            // Cannot assign a value that is a not possible value of the tile
            if (!values.Contains(value))
            {
                return(false);
            }

            // Attempt to eliminate values from peers
            cpb.Set(tileIndex, value);
            foreach (var peer in Peers[tileIndex])
            {
                if (!Eliminate(cpb, peer, value))
                {
                    return(false);
                }
            }

            return(true);
        }