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); }
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; }); }
public Player(int id) { Id = id; SelfPot = new Pot(Id); }
public void Move(Pot target) { this.Chips--; target.Chips++; }