Esempio n. 1
0
        public bool Play(Pot left, Pot center, Pot right)
        {
            var tries = SelfPot.Tries;

            if (tries == 0)
            {
                return(false);
            }
            for (int z = 0; z < tries; z++)
            {
                var o = (Outcome)_random.Next(4);
                switch (o)
                {
                case Outcome.Center:
                    SelfPot.Move(center);
                    break;

                case Outcome.Left:
                    SelfPot.Move(left);
                    break;

                case Outcome.Right:
                    SelfPot.Move(right);
                    break;

                case Outcome.Dot:
                    break;

                default:
                    throw new InvalidOperationException("Invalid outcome!");
                }
            }
            return(true);
        }
Esempio n. 2
0
        private void OnStartCommand()
        {
            GameRunning = true;
            Pot.Reset();
            CenterPot = new Pot(-1);
            Players   = new ObservableCollection <Player>();
            for (int i = 0; i < PlayerCount; i++)
            {
                var player = new Player(i);
                Players.Add(player);
            }

            var _stat = new GameStat()
            {
                Duration = new TimeSpan(), Iterations = 0
            };

            Stats.Add(_stat);
            Task.Factory.StartNew(() =>
            {
                var startTime = DateTime.Now;
                var play      = true;
                while (play)
                {
                    var index = 0;
                    foreach (var p in Players)
                    {
                        if (p.Play(
                                index == 0 ? Players.Last().SelfPot : Players[index - 1].SelfPot,
                                CenterPot,
                                index == (PlayerCount - 1) ? Players.First().SelfPot : Players[index + 1].SelfPot))
                        {
                            NonZeroPlayers = Pot.GetValids().Count();
                            if (NonZeroPlayers == 1)
                            {
                                play         = false;
                                _stat.Winner = Pot.GetValids().First().PlayerId.ToString();
                                break;
                            }
                        }
                        _stat.Iterations++;
                        _stat.Duration = DateTime.Now - startTime;
                        index++;
                    }
                }

                _stat.Duration = DateTime.Now - startTime;

                FastestGame = _Stats.Min(x => x.Duration.TotalMilliseconds);
                AverageGame = _Stats.Average(x => x.Duration.TotalMilliseconds);
                GameRunning = false;
            });
        }
Esempio n. 3
0
 public Player(int id)
 {
     Id      = id;
     SelfPot = new Pot(Id);
 }
Esempio n. 4
0
 public void Move(Pot target)
 {
     this.Chips--;
     target.Chips++;
 }