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]); }
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(); }
public frmCactpotSolver() { InitializeComponent(); _cactpot = new MiniCactpot(); }
public MiniCactpot(MiniCactpot copiedCactpot) : this() { copiedCactpot.CactpotSquares.CopyTo(this.CactpotSquares, 0); }