Sudoku Algorithm 4

Cell-ALS link class(UCellLink)

The base class of the link connecting the cell and ALS.

public class LinkCellAls: IComparable{
    public readonly UCell UC;
    public readonly UALS  ALS;
    public readonly int   nRCC=-1; //no:0...8 (doubly の場合は個別にリンクを作る)
    public LinkCellAls( UCell UC, UALS ALS, int nRCC ){
        this.UC=UC; this.ALS=ALS; this.nRCC=nRCC;
    }
    public  override bool Equals( object obj ){
        var A = obj as LinkCellAls;
        return (this.ALS.ID==A.ALS.ID);
    }
    public int CompareTo( object obj ){
        LinkCellAls A = obj as LinkCellAls;
        return (this.ALS.ID-A.ALS.ID);
    }
}

Management class of cell-ALS link(LinkCellAls)

This class is a generation function of a link connecting a cell and ALS. Links are generated for each analysis stage. Multiple algorithms may be used on the same board, and if it is already generated, use it.
Generation is performed in the following procedure.

  1. Select ALS to focus on.
  2. ALS element numerals are taken as focused numbers.
  3. Aggregate the position of the focused number in the ALS by row/column/block(rcbDir)。
  4. When the row/column/block is only one direction, look for the number of interest in the cell in that direction.
    Register in the array(LinkCeAlsLst) with the corresponding cell position as an index.

public partial class CellLinkMan{
    public List[]   LinkCeAlsLst;
    
    public void Create_Cell2ALS_Link( ALSMan ALSman ){
        if( LinkCeAlsLst!=null ) return ;
        LinkCeAlsLst = new List<LinkCellAls>[81];
        if( ALSman.ALSLst==null || ALSman.ALSLst.Count<2 )  return;

        List<UCell>  qBDL=pSA.pGP.BDL;
        foreach( var PA in ALSman.ALSLst.Where(P=>P.singly) ){
            foreach( var no in PA.FreeB.IEGet_BtoNo() ){
                if( !PA.singly )  continue;
                int noB=(1<<no);
                int rcbDir=0;
                foreach( var P in PA.UCellLst.Where(q=>(q.FreeB&noB)>0) ){
                    rcbDir |= ( (1<<(P.b+18)) | (1<<(P.c+9)) | (1<<(P.r)) );
                }

                for( int tx=0; tx<27; tx+=9 ){
                    int d = rcbDir&(0x1FF<<tx);
                    if( d.BitCount()!=1 ) continue;
                    int tfx=d.BitToNum(27);

                    foreach( var P in qBDL.IEGet(tfx,noB) ){
                        if( PA.B81.IsHit(P.rc) ) continue;

                        var Q = new LinkCellAls(P,PA,no);
                        if( LinkCeAlsLst[P.rc]==null ){
                            LinkCeAlsLst[P.rc]=new List<LinkCellAls>();
                        }
                        else if( LinkCeAlsLst[P.rc].Contains(Q) ) continue;
                        LinkCeAlsLst[P.rc].Add(Q);
                    }
                }
            }
        }
        for( int rc=0; rc<81; rc++ ) if( LinkCeAlsLst[rc]!=null ) LinkCeAlsLst[rc].Sort();
    }
}