using HeuristicLab.Core; using HeuristicLab.Data.MoveVectorData.Interfaces; using System; using System.Collections.Generic; using System.Text; namespace HeuristicLab.Data.MoveVectorData.Moves { public struct OutgoingMove : IMove { public bool Enabled { get; set; } public override string ToString() { StringBuilder sb = new StringBuilder(); if (Enabled) sb.Append("(o"); else sb.Append(""); return sb.ToString(); } public bool TryParse(string s) { bool enable = false; if (s.StartsWith("(o") && s.EndsWith(")")) { enable = true; } else if (s.StartsWith("")) { enable = false; } else { return false; } Enabled = enable; return true; } public void Randomize(IRandom random, int min, int max, int step = 1) { Enabled = true; } public int Apply(ref StackingArea area, ref Stack inputStack, out int realMoves) { if (Enabled) { var minValue = Int32.MaxValue; var minStack = Int32.MaxValue; var minRow = Int32.MaxValue; for (int stack = 0; stack < area.Size; stack++) { for (int row = area.MaxHeight - 1; row >= 0; row--) { if(area[row, stack] != 0 && area[row, stack] < minValue) { minValue = area[row, stack]; minStack = stack; minRow = row; } } } for (int stack = 0; stack < inputStack.Capacity; stack++) { if (inputStack[stack] != 0 && inputStack[stack] < minValue) { realMoves = 0; return 1; } } if (minValue == Int32.MaxValue) { realMoves = 0; return 1; } area[minRow, minStack] = 0; int atop = 0; for (int row = minRow; row < area.MaxHeight; row++) { if (row < area.MaxHeight - 1) { area[row, minStack] = area[row + 1, minStack]; } else { area[row, minStack] = 0; } atop = atop + 1; } realMoves = atop * 2 + 1; return atop * 2 + 1; } realMoves = 0; return 0; } public IEnumerable GenerateNeighbours(IRandom random, int min, int max, int step = 1) { var moves = new List(); moves.Add(new OutgoingMove() { Enabled = !this.Enabled, }); return moves; } } }