// This is a horrible way to do this but I am sick of trying to do the right algorithm to find all subset sums public static HashSet<int> Sums( DiceCollection diceVals ) { HashSet<int> toReturn = new HashSet<int>(); DiceCollection bag = new DiceCollection( 0, 6 ); SumComboFinder comboFinder = new SumComboFinder(); foreach( KingsburgDie i in diceVals ) { KingsburgDie d; d = new KingsburgDie( i.Type ); d.Value = i.Value; bag.Add( d ); } foreach( int i in new Range( 1, 18 ) ) { if( comboFinder.Find( i, bag ).Count > 0 ) { toReturn.Add( i ); } } return toReturn; }
public override DiceCollection DisplayChooseDice( Player p, Advisor a ) { switch( this.Mode ) { case graphicsMode.CLI: DiceCollection toReturn; SumComboFinder sc = new SumComboFinder(); List<List<KingsburgDie>> combos = sc.Find( a.Order, p.RemainingDice ); // Return the only combo if there is only one if( combos.Count == 1 ) { toReturn = new DiceCollection( combos[0] ); } else { Console.WriteLine( "\n{0}, pick which dice combo to use:", p.Name ); foreach( List<KingsburgDie> combo in combos ) { Console.Write( "{0}: ", combos.IndexOf( combo ) ); foreach( KingsburgDie d in combo ) { Console.Write( "{0}, ", d ); } Console.WriteLine(); } Console.WriteLine( "\"*\" indicates a white die." ); int chosenCombo = -1; do { string input = Console.ReadLine(); chosenCombo = int.Parse( input ); } while( chosenCombo == -1 || chosenCombo + 1 > combos.Count ); toReturn = new DiceCollection( combos[chosenCombo] ); } return toReturn; case graphicsMode.GUI: throw new NotImplementedException(); default: throw new Exception(); } }