// this is used to recursively place the missing Mines into the available boxes for the probability line private List <ProbabilityLine> DistributeMissingMines(ProbabilityLine pl, NextWitness nw, int missingMines, int index) { //console.log("Distributing " + missingMines + " missing mines to box " + nw.newBoxes[index].uid); this.recursions++; if (this.recursions % 100000 == 0) { information.Write("Solution Counter recursision = " + recursions); } List <ProbabilityLine> result = new List <ProbabilityLine>(); // if there is only one box left to put the missing mines we have reach the end of this branch of recursion if (nw.GetNewBoxes().Count - index == 1) { // if there are too many for this box then the probability can't be valid if (nw.GetNewBoxes()[index].GetMaxMines() < missingMines) { //console.log("Abandon (1)"); return(result); } // if there are too few for this box then the probability can't be valid if (nw.GetNewBoxes()[index].GetMinMines() > missingMines) { //console.log("Abandon (2)"); return(result); } // if there are too many for this game then the probability can't be valid if (pl.GetMineCount() + missingMines > this.maxTotalMines) { //console.log("Abandon (3)"); return(result); } // otherwise place the mines in the probability line pl.SetMineBoxCount(nw.GetNewBoxes()[index].GetUID(), new BigInteger(missingMines)); pl.SetMineCount(pl.GetMineCount() + missingMines); result.Add(pl); //console.log("Distribute missing mines line after " + pl.mineBoxCount); return(result); } // this is the recursion int maxToPlace = Math.Min(nw.GetNewBoxes()[index].GetMaxMines(), missingMines); for (int i = nw.GetNewBoxes()[index].GetMinMines(); i <= maxToPlace; i++) { ProbabilityLine npl = ExtendProbabilityLine(pl, nw.GetNewBoxes()[index], i); List <ProbabilityLine> r1 = DistributeMissingMines(npl, nw, missingMines - i, index + 1); result.AddRange(r1); } return(result); }
// create a new probability line by taking the old and adding the mines to the new Box private ProbabilityLine ExtendProbabilityLine(ProbabilityLine pl, Box newBox, int mines) { //console.log("Extended probability line: Adding " + mines + " mines to box " + newBox.uid); //console.log("Extended probability line before" + pl.mineBoxCount); ProbabilityLine result = new ProbabilityLine(this.boxes.Count); result.SetMineCount(pl.GetMineCount() + mines); result.CopyMineBoxCount(pl); result.SetMineBoxCount(newBox.GetUID(), new BigInteger(mines)); //console.log("Extended probability line after " + result.mineBoxCount); return(result); }