public static Factory NotifyChips(this Factory self, Destination.Bot bot, int chip1, int chip2) { if (chip1 == self.FirstWatchChip && chip2 == self.SecondWatchChip) { self.WatchBot = bot; } return(self); }
public static Destination.Bot NotifyChips(this Destination.Bot self) { if (self.LowChip.HasValue && self.HighChip.HasValue) { self.Factory.NotifyChips(self, self.LowChip.Value, self.HighChip.Value); } return(self); }
public static Destination GiveChips(this Destination.Bot self) { if (!self.LowChip.HasValue || !self.HighChip.HasValue || self.LowDest == null || self.HighDest == null) { return(self); } self.NotifyChips(); self.LowDest.TakeChip(self.LowChip.Value); self.HighDest.TakeChip(self.HighChip.Value); self.LowChip = null; self.HighChip = null; return(self); }
public static Destination TakeChip(this Destination.Bot self, int chip) { if (self.HighChip.HasValue) { throw new InvalidOperationException("Three chips"); } self.HighChip = !self.LowChip.HasValue ? (int?)null : Math.Max(chip, self.LowChip.Value); self.LowChip = !self.LowChip.HasValue ? chip : Math.Min(chip, self.LowChip.Value); if (self.LowChip.HasValue && self.HighChip.HasValue) { self.GiveChips(); } return(self); }
public static Destination.Bot GetOrMakeBot(this Factory self, int botNum) { var existing = self.Destinations.Any(d => d.Match(bot => bot.Number == botNum, bin => false)) ? self.Destinations.First(d => d.Match(bot => bot.Number == botNum, bin => false)) as Destination.Bot : null; if (existing != null) { return(existing); } var newBot = new Destination.Bot() { Factory = self, Number = botNum, HighChip = null, LowChip = null }; self.Destinations.Add(newBot); return(newBot); }