private OperationOutput.Episode DoRefill() { var ret = new OperationOutput.Episode(OperationOutput.EpisodeType.REFILL); ret.refillFlow = refillRule.Apply(foreground); ret.refillSlots = new SlotAttribute[foreground.Height, foreground.Width]; foreground.ForeachSlot((x, y, slot) => { if (null == foreground.WrapperRect[y, x]) { background.ClearSlot(x, y); background.FillSlot(x, y); } }); MakeContainerStable(background); background.ForeachSlot((x, y, slot) => { if (slot.slotAttribute.category != SlotAttribute.Category.INSULATOR) { foreground.SetSlot(x, y, slot); } }); background.FlushAsFirmware(); foreground.ForeachSlot((x, y, slot) => { ret.refillSlots[y, x] = slot.slotAttribute; }); return(ret); }
public override RefillFlowRecord Apply (Container2D_Rectangular container) { var key = GetType().Name + "-" + "RefillInfoMap"; FillInfo[,] fillInfoMap = null; if (!container.UserData.ContainsKey(key)) { List<Pos2D> pores = new List<Pos2D>(); container.ForeachSlot((x, y, slot)=>{ if (null == slot){ pores.Add(new Pos2D(x, y)); container.WrapperRect[y, x] = new SlotWrapper2D(); container.WrapperRect[y, x].pos = new Pos2D(x, y); } }); fillInfoMap = GenerateRefillTrendMap(container); container.UserData.Add(key, fillInfoMap); GlobalDebug.refillInfoMap = fillInfoMap; foreach (var p in pores) { container.ClearSlot(p.x, p.y); } } else { fillInfoMap = container.UserData[key] as FillInfo[,]; } return DoApply(container, fillInfoMap); }
public override RefillFlowRecord Apply(Container2D_Rectangular container) { var key = GetType().Name + "-" + "RefillInfoMap"; FillInfo[,] fillInfoMap = null; if (!container.UserData.ContainsKey(key)) { List <Pos2D> pores = new List <Pos2D>(); container.ForeachSlot((x, y, slot) => { if (null == slot) { pores.Add(new Pos2D(x, y)); container.WrapperRect[y, x] = new SlotWrapper2D(); container.WrapperRect[y, x].pos = new Pos2D(x, y); } }); fillInfoMap = GenerateRefillTrendMap(container); container.UserData.Add(key, fillInfoMap); GlobalDebug.refillInfoMap = fillInfoMap; foreach (var p in pores) { container.ClearSlot(p.x, p.y); } } else { fillInfoMap = container.UserData[key] as FillInfo[, ]; } return(DoApply(container, fillInfoMap)); }
private void MakeContainerStable(Container2D_Rectangular container) { var lmRecords = SeekContainerLM(container); if (lmRecords.Count <= 0) { return; } var sandbox = CollectContainerEliminate(container, lmRecords); container.ForeachSlot((x, y, slot) => { if (sandbox[y, x]) { container.ClearSlot(x, y); container.FillSlot(x, y); } }); MakeContainerStable(container); }
public OperationOutput PerformOperation(OperationInput op) { var ret = new OperationOutput(); ret.IsRejected = true; foreach (var plm in plmRecords) { if ((plm.x1 == op.x1 && plm.y1 == op.y1 && plm.x2 == op.x2 && plm.y2 == op.y2) || (plm.x1 == op.x2 && plm.y1 == op.y2 && plm.x2 == op.x1 && plm.y2 == op.y1)) { ret.IsRejected = false; break; } } if (ret.IsRejected) { return(ret); } else { ret.episodes = new List <OperationOutput.Episode>(); } foreground.SwapSlot(op.x1, op.y1, op.x2, op.y2); var lmRecords = new List <LMRecord2D_Retangular>(); lmRecords = SeekContainerLM(foreground); do { var elimination = new OperationOutput.Episode(OperationOutput.EpisodeType.ELIMINATION); elimination.elimination = new List <Pos2D>(); var sandbox = CollectContainerEliminate(foreground, lmRecords); foreground.ForeachSlot((x, y, slot) => { if (sandbox[y, x]) { elimination.elimination.Add(new Pos2D(x, y)); foreground.ClearSlot(x, y); } }); ret.episodes.Add(elimination); foreach (var sc in scoreRules) { sc.Apply(sandbox); } ret.episodes.Add(DoRefill()); lmRecords = SeekContainerLM(foreground); if (0 == lmRecords.Count) { plmRecords = SeekContainerPLM(foreground); if (plmRecords.Count >= minimalPlayablePLM) { break; } else { foreground.RecreateSubjects(true); MakeContainerStable(foreground); MakeContainerPlayable(foreground); var shuffle = new OperationOutput.Episode(OperationOutput.EpisodeType.SHUFFLE); shuffle.shuffle = new SlotAttribute[foreground.Height, foreground.Width]; foreground.ForeachSlot((x, y, slot) => { shuffle.shuffle[y, x] = slot.slotAttribute; }); ret.episodes.Add(shuffle); plmRecords = SeekContainerPLM(foreground); break; } } }while (true); return(ret); }