Exemplo n.º 1
0
    public double ChosenSquareValue(int squareChosen)
    {
        if (ChoicesRemaining < 0)
        {
            throw new ArgumentException("No choices to make!");
        }
        if (CactpotSquares[squareChosen] != 0)
        {
            return(-1);
        }
        long choiceHash = (long)this.GetHashCode() * 10 + squareChosen;

        if (!ChosenSquareValueStore.ContainsKey(choiceHash))
        {
            // Value of a chosen square is the average of the values of all possible boards that follow that choice
            double totalNextBoardValue = 0;
            foreach (int value in RemainingValues)
            {
                var newBoard = new MiniCactpot(this);
                newBoard.Choose(squareChosen, value);
                totalNextBoardValue += newBoard.BoardValue;
            }
            ChosenSquareValueStore.Add(choiceHash, totalNextBoardValue * 1.0 / RemainingValues.Count());
        }
        return(ChosenSquareValueStore[choiceHash]);
    }
Exemplo n.º 2
0
    static void Main(string[] args)
    {
        var testBoard = new MiniCactpot();

        //MiniCactpot.LoadValueStore();
        //testBoard.Choose(0, 4);
        //Console.WriteLine("Max: " + testBoard.BoardValue);
        for (int i = 0; i < testBoard.CactpotSquares.Length; i++)
        {
            Console.WriteLine("{0}: {1}", i, testBoard.ChosenSquareValue(i));
        }
        //MiniCactpot.SaveValueStore();
        Console.ReadLine();
    }
Exemplo n.º 3
0
 public frmCactpotSolver()
 {
     InitializeComponent();
     _cactpot = new MiniCactpot();
 }
Exemplo n.º 4
0
 public MiniCactpot(MiniCactpot copiedCactpot)
     : this()
 {
     copiedCactpot.CactpotSquares.CopyTo(this.CactpotSquares, 0);
 }