// Determines if any particular group of cells must overlap with itself // for both the min and max case /*public void Apply(CellLine line) * { * int length = line.Length; * int minimumWidth = line.Hints.Sum() + line.Hints.Count - 1; * int remainder = length - minimumWidth; * * if (remainder >= line.Hints.Max()) * { * return; * } * * int offset = 0; * for (int group = 0; group < line.Hints.Count; group++) * { * int numberKnown = Math.Max(line.Hints[group] - remainder, 0); * int numberUnknown = line.Hints[group] - numberKnown; * offset += numberUnknown; * * for (int i = 0; i < numberKnown; i++) * { * line[offset + i].State = Cell.CellState.Filled; * } * * // Special case: hints give a complete picture of the line * // I.E. remainder = 0, there are no unknown cells * // We can fill in the rest of the 'unknowns' with Blanks. * if (remainder == 0 && group + 1 != line.Hints.Count) * { * line[offset + numberKnown].State = Cell.CellState.Blank; * } * * offset += numberKnown + 1; * } * }*/ public bool Apply(CellLine line) { var min = line.Min(); var max = line.Max(); if (min == null || max == null) { // Min or Max was given conflicting information and cannot be filled. // Can't do anything, so return now. return(false); } bool madeChanges = false; for (int i = 0; i < line.Length; i++) { var minCell = min[i]; var maxCell = max[i]; if (minCell == maxCell) { if (line[i].State != minCell.State) { madeChanges = true; } line[i].State = minCell.State; } } return(madeChanges); }
public void FillingPartOfALineThatHasStateOutsideThatPartWithStateAndFlagFillsTheSectionWithThatStateAndFlagAndReturnsFalse() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l[0].State = Cell.CellState.Blank; Assert.IsTrue(l.Fill(1, 2, Cell.CellState.Filled, 42)); var expectedStates = new Cell.CellState[5] { Cell.CellState.Blank, Cell.CellState.Filled, Cell.CellState.Filled, Cell.CellState.Unknown, Cell.CellState.Unknown }; var expectedFlags = new int[5] { 0, 42, 42, 0, 0 }; for (int i = 0; i < 5; i++) { Assert.AreEqual(expectedStates[i], l[i].State); Assert.AreEqual(expectedFlags[i], l[i].Flag); } }
public void CellLineMaxFunctionsWithSomeKnownCells_5_3_last() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 3 }); l[4].State = Cell.CellState.Filled; var expectedStates = new Cell.CellState[5] { Cell.CellState.Blank, Cell.CellState.Blank, Cell.CellState.Filled, Cell.CellState.Filled, Cell.CellState.Filled }; var expectedFlags = new int[5] { 0, 1, 0, 0, 0 }; var max = l.Max(); Assert.IsNotNull(max); for (int i = 0; i < 5; ++i) { Assert.AreEqual(expectedStates[i], max[i].State); Assert.AreEqual(expectedFlags[i], max[i].Flag); } }
public void CellLineMaxFunctionsWithSomeBlockedCells() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 2, 1 }); l[2].State = Cell.CellState.Blank; var expectedStates = new Cell.CellState[5] { Cell.CellState.Filled, Cell.CellState.Filled, Cell.CellState.Blank, // forced blank Cell.CellState.Blank, Cell.CellState.Filled }; var expectedFlags = new int[5] { 0, 0, 0, 1, 1 }; var max = l.Max(); Assert.IsNotNull(max); for (int i = 0; i < 5; ++i) { Assert.AreEqual(expectedStates[i], max[i].State); Assert.AreEqual(expectedFlags[i], max[i].Flag); } }
public void CellLineMinFunctionsWithAllUnknownCells_5_2_1() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 2, 1 }); var expectedStates = new Cell.CellState[5] { Cell.CellState.Filled, Cell.CellState.Filled, Cell.CellState.Blank, Cell.CellState.Filled, Cell.CellState.Blank }; var expectedFlags = new int[5] { 0, 0, 0, 1, 1 }; var min = l.Min(); Assert.IsNotNull(min); for (int i = 0; i < 5; ++i) { Assert.AreEqual(expectedStates[i], min[i].State); Assert.AreEqual(expectedFlags[i], min[i].Flag); } }
public void IsValidReturnsTrueWhenAllUnknown() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); Assert.AreEqual(true, l.IsValid()); }
public void DistinctGroupsReturnsZeroWithAllUnknowns() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); Assert.AreEqual(0, l.DistinctGroups()); }
public void IsValidReturnsFalseWhenHintIsNotPossible_Hint32() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 3, 2 }); Assert.AreEqual(false, l.IsValid()); }
public void IsValidReturnsTrueWhenHintMatchesContents_Hint0_Contents0() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(Cell.CellState.Blank); Assert.AreEqual(true, l.IsValid()); }
public void DistinctGroupsReturnsOneWithAllFilled() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(Cell.CellState.Filled); Assert.AreEqual(1, l.DistinctGroups()); }
public void DistinctGroupsReturnsZeroWithAllBlank() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(Cell.CellState.Blank); Assert.AreEqual(0, l.DistinctGroups()); }
BubbleCell _StickToBuffer(ref FlyingBubble bubble) { if (!bubble.stopped) { return(null); } var cell = bubble.destResult; CellLine line; if (cell.y >= m_buffer.Count) { line = new CellLine { cells = new BubbleCell[m_bubbleLevelData[0].Length], root = null }; m_buffer.Insert(0, line); } else { line = m_buffer[m_buffer.Count - 1 - cell.y]; } var slot = line.cells[cell.x] ?? new BubbleCell(); if (slot != null && slot.go != null) { return(null); } line.cells[cell.x] = slot; GameObject go = null; Material mat = null; var x = m_bubbleRadius * cell.x + m_bubbleRadius; var y = cell.y * m_lineHeight + m_bubbleRadius; slot.x = cell.x; slot.y = cell.y; go = UnityEngine.Object.Instantiate <GameObject>(m_bubbleGO); go.name = String.Format("cell+{0}", cell.x); if (line.root == null) { var n = m_bubbleLevelData[0].Length; var lineRoot = new GameObject(String.Format("line+{0}", m_buffer.Count)).transform; lineRoot.parent = m_cellRoot; lineRoot.localScale = Vector3.one; line.root = lineRoot; } go.transform.parent = line.root; go.transform.localPosition = bubble.transform.localPosition; go.transform.DOLocalMove(new Vector3(x, y, 0), TweenTime * 0.5f); mat = go.GetComponent <Renderer>().material; slot.go = go; slot.mat = mat; slot.color = bubble.color; SetColor(mat, bubble.color); return(line.cells[cell.x]); }
public void DistinctGroupsReturnsActualNumberOfGroupsWithThreeGroupsOfOne() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l[0].State = l[2].State = l[4].State = Cell.CellState.Filled; l[1].State = l[3].State = Cell.CellState.Blank; Assert.AreEqual(3, l.DistinctGroups()); }
public void DistinctGroupsReturnsActualNumberOfGroupsWithTwoGroupsOfTwo() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(Cell.CellState.Filled); l[2].State = Cell.CellState.Blank; Assert.AreEqual(2, l.DistinctGroups()); }
public void IsValidReturnsFalseWhenHintsExistButAllBlank() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(Cell.CellState.Blank); l.Hints.AddRange(new int[] { 1 }); Assert.AreEqual(false, l.IsValid()); }
public void ReversingACellLineReversesItsContents() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l[0].State = Cell.CellState.Blank; l.Reverse(); Assert.AreEqual(Cell.CellState.Blank, l[4].State); }
public void IsValidReturnsTrueWhenNotEnoughGroups_Hint111_Contents11() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l[0].State = l[2].State = Cell.CellState.Filled; l[1].State = l[3].State = Cell.CellState.Blank; l.Hints.AddRange(new int[] { 1, 1, 1 }); Assert.AreEqual(true, l.IsValid()); }
public void IsValidReturnsFalseWhenGroupIsTooLarge_Hint3_Contents4_right() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l[0].State = Cell.CellState.Blank; l.Fill(1, 4, Cell.CellState.Filled); l.Hints.AddRange(new int[] { 3 }); Assert.AreEqual(false, l.IsValid()); }
public void IsValidReturnsFalseWhenNoPossibleSolutionsExist() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(0, 3, Cell.CellState.Filled); l[4].State = Cell.CellState.Filled; l.Hints.AddRange(new int[] { 3 }); Assert.AreEqual(false, l.IsValid()); }
public void IsValidReturnsTrueWhenPossibleSolutionsExist() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Fill(0, 3, Cell.CellState.Blank); l[4].State = Cell.CellState.Blank; l.Hints.AddRange(new int[] { 1 }); Assert.AreEqual(true, l.IsValid()); }
public void CellLineMaxReturnsNullWhenNotPossibleToFill() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 2, 2 }); l[1].State = Cell.CellState.Blank; var max = l.Max(); Assert.IsNull(max); }
public void CellLineIsCompleteIsTrueWhenAllBlank() { Nonogram n = new Nonogram(5, 5); CellLine l = n.Row(0); foreach (var cell in l) { cell.State = Cell.CellState.Blank; } Assert.IsTrue(n.Row(0).isComplete); }
public void FillingALineWithStateFillsTheEntireLineWithThatStateAndReturnsTrue() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); Assert.IsTrue(l.Fill(Cell.CellState.Filled)); for (int i = 0; i < 5; i++) { Assert.AreEqual(Cell.CellState.Filled, l[i].State); } }
public void CellLineMaxReturnsNullWhenGivenConflictingInformation() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 3 }); l[0].State = Cell.CellState.Filled; l[4].State = Cell.CellState.Filled; var max = l.Max(); Assert.IsNull(max); }
public void CellLineIsCompleteIsTrueWhenAllNotUnknown() { Nonogram n = new Nonogram(5, 5); CellLine l = n.Row(0); bool setToFilled = false; foreach (var cell in l) { cell.State = setToFilled ? Cell.CellState.Filled : Cell.CellState.Blank; setToFilled = !setToFilled; } Assert.IsTrue(n.Row(0).isComplete); }
public void CellLineIsCompleteIsFalseWithOneUnknown() { Nonogram n = new Nonogram(5, 5); CellLine l = n.Row(0); bool setToUnknown = false; foreach (var cell in l) { cell.State = setToUnknown ? Cell.CellState.Unknown : Cell.CellState.Filled; setToUnknown = true; } Assert.IsFalse(n.Row(0).isComplete); }
public override void Init() { if (Prefs.DevMode) { Log.Message("[Carnivale] Carnival is in defending mode."); } foreach (var lord in Map.lordManager.lords) { lord.ReceiveMemo("DangerPresent"); } if (lord.ownedPawns.Count > 10) { var steel = ThingMaker.MakeThing(ThingDefOf.Steel); steel.stackCount = 75; GenPlace.TryPlaceThing(steel, Info.setupCentre, Map, ThingPlaceMode.Near); var aveHostilePos = Map.attackTargetsCache.TargetsHostileToFaction(lord.faction) .Where(targ => !targ.ThreatDisabled()) .Select(targ => targ.Thing.Position) .Average(); var closestPos = Info.carnivalArea.ClosestCellTo(aveHostilePos); var line = CellLine.Between(closestPos, aveHostilePos); if (line.Slope > 1f || line.Slope < -1f) { for (int i = -3; i < 3; i++) { var spot = closestPos + IntVec3.West * i; if (AIBlueprintsUtility.CanPlaceBlueprintAt(spot, ThingDefOf.Sandbags)) { AIBlueprintsUtility.PlaceBlueprint(ThingDefOf.Sandbags, spot); } } } else { for (int i = -3; i < 3; i++) { var spot = closestPos + IntVec3.North * i; if (AIBlueprintsUtility.CanPlaceBlueprintAt(spot, ThingDefOf.Sandbags)) { AIBlueprintsUtility.PlaceBlueprint(ThingDefOf.Sandbags, spot); } } } } }
public void CellLineMaxDoesNotModifyOriginalLine() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); l.Hints.AddRange(new int[] { 1, 1 }); var max = l.Max(); for (int i = 0; i < 5; ++i) { Assert.AreNotSame(l[i], max[i]); Assert.AreEqual(Cell.CellState.Unknown, l[i].State); Assert.AreEqual(0, l[i].Flag); } }
public void FillingPartOfALineWithStateFillsTheSectionWithThatStateAndReturnsTrue() { Nonogram n = new Nonogram(5, 1); CellLine l = n.Row(0); Assert.IsTrue(l.Fill(1, 2, Cell.CellState.Filled)); var expectedStates = new Cell.CellState[5] { Cell.CellState.Unknown, Cell.CellState.Filled, Cell.CellState.Filled, Cell.CellState.Unknown, Cell.CellState.Unknown }; for (int i = 0; i < 5; i++) { Assert.AreEqual(expectedStates[i], l[i].State); } }
public static bool TryFindCastPosition(CastPositionRequest newReq, out IntVec3 dest) { req = newReq; casterLoc = req.caster.Position; targetLoc = req.target.Position; verb = req.verb; avoidGrid = newReq.caster.GetAvoidGrid(onlyIfLordAllows: false); if (verb == null) { Log.Error(req.caster + " tried to find casting position without a verb."); dest = IntVec3.Invalid; return(false); } if (req.maxRegions > 0) { Region region = casterLoc.GetRegion(req.caster.Map); if (region == null) { Log.Error("TryFindCastPosition requiring region traversal but root region is null."); dest = IntVec3.Invalid; return(false); } inRadiusMark = Rand.Int; RegionTraverser.MarkRegionsBFS(region, null, newReq.maxRegions, inRadiusMark); if (req.maxRangeFromLocus > 0.01f) { Region locusReg = req.locus.GetRegion(req.caster.Map); if (locusReg == null) { Log.Error("locus " + req.locus + " has no region"); dest = IntVec3.Invalid; return(false); } if (locusReg.mark != inRadiusMark) { inRadiusMark = Rand.Int; RegionTraverser.BreadthFirstTraverse(region, null, delegate(Region r) { r.mark = inRadiusMark; req.maxRegions++; return(r == locusReg); }); } } } CellRect cellRect = CellRect.WholeMap(req.caster.Map); if (req.maxRangeFromCaster > 0.01f) { int num = Mathf.CeilToInt(req.maxRangeFromCaster); CellRect otherRect = new CellRect(casterLoc.x - num, casterLoc.z - num, num * 2 + 1, num * 2 + 1); cellRect.ClipInsideRect(otherRect); } int num2 = Mathf.CeilToInt(req.maxRangeFromTarget); CellRect otherRect2 = new CellRect(targetLoc.x - num2, targetLoc.z - num2, num2 * 2 + 1, num2 * 2 + 1); cellRect.ClipInsideRect(otherRect2); if (req.maxRangeFromLocus > 0.01f) { int num3 = Mathf.CeilToInt(req.maxRangeFromLocus); CellRect otherRect3 = new CellRect(targetLoc.x - num3, targetLoc.z - num3, num3 * 2 + 1, num3 * 2 + 1); cellRect.ClipInsideRect(otherRect3); } bestSpot = IntVec3.Invalid; bestSpotPref = 0.001f; maxRangeFromCasterSquared = req.maxRangeFromCaster * req.maxRangeFromCaster; maxRangeFromTargetSquared = req.maxRangeFromTarget * req.maxRangeFromTarget; maxRangeFromLocusSquared = req.maxRangeFromLocus * req.maxRangeFromLocus; rangeFromTarget = (req.caster.Position - req.target.Position).LengthHorizontal; rangeFromTargetSquared = (req.caster.Position - req.target.Position).LengthHorizontalSquared; optimalRangeSquared = verb.verbProps.range * 0.8f * (verb.verbProps.range * 0.8f); EvaluateCell(req.caster.Position); if ((double)bestSpotPref >= 1.0) { dest = req.caster.Position; return(true); } float slope = -1f / CellLine.Between(req.target.Position, req.caster.Position).Slope; CellLine cellLine = new CellLine(req.target.Position, slope); bool flag = cellLine.CellIsAbove(req.caster.Position); foreach (IntVec3 item in cellRect) { if (cellLine.CellIsAbove(item) == flag && cellRect.Contains(item)) { EvaluateCell(item); } } if (bestSpot.IsValid && bestSpotPref > 0.33f) { dest = bestSpot; return(true); } foreach (IntVec3 item2 in cellRect) { if (cellLine.CellIsAbove(item2) != flag && cellRect.Contains(item2)) { EvaluateCell(item2); } } if (bestSpot.IsValid) { dest = bestSpot; return(true); } dest = casterLoc; return(false); }