private void cboSquare_SelectedIndexChanged(object sender, EventArgs e) { var cbo = sender as ComboBox; int square = 0; int val = 0; bool success = false; try { square = (int)cbo.Tag; val = (int)cbo.SelectedItem; if (_cactpot.ChoicesRemaining == 0 && _cactpot.IsUnchosenSquare(square)) { MessageBox.Show("No choices remaining!"); cbo.SelectedIndex = 0; return; } success = true; } catch (Exception) { } // Display the values of choices if (success) { _cactpot.Choose(square, val); HighlightMaxChoice(); } // Display line values if no choices left if (_cactpot.ChoicesRemaining == 0) { HighlightMaxLine(); } }
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]); }