public Monte MonteLoop(int Tries, int Seed) { Monte Values = new Monte(); Random Rnd = new Random(Seed); double x, y; Values.InCircle = 0; for (int i = 1; i < Tries; i++) { x = Rnd.NextDouble(); y = Rnd.NextDouble(); if (Math.Sqrt(x * x + y * y) <= 1) Values.InCircle++; //Optimization Note: Sqrt is not needed 1^2=1 } Values.Tries = Tries; return (Values); }
public MainWindowVM() { dice = new List<int>(); status = new StringBuilder(); addHuman = new DelegateCommand(() => { var human = new HumanPlayer(startingDice); status.Insert(0, string.Format("{0} was added to the game\n", human)); GameState.Instance.AddPlayer(human); Console.WriteLine("I did get hit"); NotifyPropertyChanged("GameStatus"); startGame.RaiseCanExecuteChanged(); }); addMonte = new DelegateCommand(() => { var comp = new Monte(startingDice); status.Insert(0, string.Format("{0} was added to the game\n", comp)); GameState.Instance.AddPlayer(comp); NotifyPropertyChanged("GameStatus"); startGame.RaiseCanExecuteChanged(); }); addMaybeBluff = new DelegateCommand(() => { var comp = new MaybeBluff(startingDice); status.Insert(0, string.Format("{0} was added to the game\n", comp)); GameState.Instance.AddPlayer(comp); NotifyPropertyChanged("GameStatus"); startGame.RaiseCanExecuteChanged(); }); addRandomMonte = new DelegateCommand(() => { var comp = new RandomMonte(startingDice); status.Insert(0, string.Format("{0} was added to the game\n", comp)); GameState.Instance.AddPlayer(comp); NotifyPropertyChanged("GameStatus"); startGame.RaiseCanExecuteChanged(); }); startGame = new DelegateCommand(() => { GameState.Instance.Rolling = true; roll.RaiseCanExecuteChanged(); RollHandler(); }, ()=> { return GameState.Instance.TotalPlayers > 1; }); call = new DelegateCommand(() => { status.Insert(0, string.Format("{0} Calls.\n", GameState.Instance.CurrentTurn)); status.Insert(0, GameState.Instance.GetAllRolls()); var result = GameState.Instance.EndRound(); status.Insert(0, string.Format("{0}.\n", result)); dice = new List<int>(); NotifyDiceChange(); NotifyPropertyChanged("GameStatus"); RoundHandler(); //}, //() => //{ // return GameState.Instance.ValidMove(new PlayerMove() { Call = true }); }); guess = new DelegateCommand(async () => { var move = new PlayerMove() { GuessAmount = amount, DiceNumber = diceValue }; status.Insert(0, string.Format("{0} guesses {1}.\n", GameState.Instance.CurrentTurn, move)); GameState.Instance.AddMove(move); GameState.Instance.EndTurn(); NotifyPropertyChanged("GameStatus"); dice = new List<int>(); NotifyDiceChange(); NotifyPropertyChanged("LastMove"); await TurnHandler(); //}, //() => //{ // return GameState.Instance.ValidMove(new PlayerMove() {DiceNumber = diceValue, GuessAmount = amount }); }); roll = new DelegateCommand(() => { GameState.Instance.CurrentTurn.Roll(); dice = GameState.Instance.CurrentTurn.hand; NotifyDiceChange(); rollOk.RaiseCanExecuteChanged(); }, () => { return GameState.Instance.Rolling; }); rollOk = new DelegateCommand(() => { GameState.Instance.EndTurn(); dice = new List<int>(); NotifyDiceChange(); RollHandler(); }, () => { return dice.Count != 0 && !dice.Contains(0) && GameState.Instance.Rolling; }); if (hideDice) diceVisibility = Visibility.Hidden; else diceVisibility = Visibility.Visible; }