public unsafe Direction Solve(byte *grid) { GridStack stack = new GridStack(128); GridFunctions.CloneGrid(grid, stack.current); Dictionary <Direction, int> scores = new Dictionary <Direction, int>(); foreach (Direction direction in Enum.GetValues(typeof(Direction))) { //Console.WriteLine(direction); if (GridFunctions.GridCanCollapse(grid, direction) == false) { //Console.WriteLine("\tCant Collapse"); continue; } stack.pushCurrent(); GridFunctions.CollapseGridInPlace(stack.current, direction); scores[direction] = ScoreForGrid(stack, 1); stack.pop(); //Console.WriteLine("\tScore: " + scores[direction]); } return(scores.OrderByDescending(x => x.Value).First().Key); }
void Debugger_OnInstructionChanged(object sender, Instruction instruction) { GridOpCode.CurrentCell = GridOpCode.Rows[instruction == null ? 0 : (int)instruction.Location.Index].Cells[3]; Jumps.RefreshDynJumps(Debugger); GridOpCode.Refresh(); GridAltStack.Refresh(); GridStack.Refresh(); Registers.Refresh(); }
private unsafe int ScoreForGrid(GridStack stack, int depth) { int permutations = GridFunctions.CountEmptySquares(stack.current); if (permutations == 0) { return(0); } int startIndex = 0; int score = int.MaxValue; for (int i = 0; i < permutations; i++) { stack.pushCurrent(); GridFunctions.TryAddPermutation(stack.current, ref startIndex); //if(!success) //{ // //GridFunctions.printGrid(grid); // //GridFunctions.printGrid((grids + i * 16)); // //GridFunctions.TryAddPermutation((grids + i * 16), startIndex, out startIndex); // throw new Exception(); //} startIndex++; int subScore = -1; foreach (Direction subDirection in Enum.GetValues(typeof(Direction))) { stack.pushCurrent(); GridFunctions.CollapseGridInPlace(stack.current, subDirection); if (depth == 1) { subScore = Math.Max(subScore, FinalScoreForGrid(stack.current)); } else { subScore = Math.Max(subScore, ScoreForGrid(stack, depth - 1)); } stack.pop(); } stack.pop(); score = Math.Min(score, subScore); } return(score); }
public void TestCalculation1_3() { var underTest = new GridHelperHandler(); var renderingContext = new RenderingContext(null); var gridStack = GridStack.FromContext(renderingContext); gridStack.Push(960); underTest.EvaluateAsync(null, renderingContext, new Dictionary <string, string> { { "ratio", "1/3" } }); var result = gridStack.Current; Assert.AreEqual(320, result.Width); }
/// <summary> /// Set stack items /// </summary> /// <param name="items">Items</param> public void SetStackSource(StackItem[] items) { GridStack.DataSource = items; GridStack.ClearSelection(); }
/// <summary> /// Refresh grids /// </summary> public void RefreshGrids() { GridAltStack.Refresh(); GridStack.Refresh(); }
void Stack_OnChange(object sender, EventArgs e) { GridStack.DataSource = Debugger?.Stack.ToArray(); GridStack.ClearSelection(); }