using HeuristicLab.Core; using HeuristicLab.Data.MoveVectorData.Interfaces; using System; using System.Text; using System.Collections.Generic; namespace HeuristicLab.Data.MoveVectorData.Moves { public struct IngoingMove : IMove { public bool Enabled { get; set; } public int putdown; public override string ToString() { StringBuilder sb = new StringBuilder(); if (Enabled) sb.Append("(i"); else sb.Append(""); return sb.ToString(); } public bool TryParse(string s) { bool enable = false; if (s.StartsWith("(i") && s.EndsWith(")")) { enable = true; } else if (s.StartsWith("")) { enable = false; } else { return false; } string[] valueStrings = s.Substring(2, s.Length - 1).Split(' '); int val; if (!int.TryParse(valueStrings[0], out val)) { return false; } putdown = val; if (!int.TryParse(valueStrings[1], out val)) { return false; } Enabled = enable; return true; } public void Randomize(IRandom random, int min, int max, int step = 1) { int numbers = (int)Math.Floor((max - min) / (double)step); putdown = random.Next(numbers) * step + min; Enabled = true; } public int Apply(ref StackingArea area, ref Stack inputStack, out int realMoves) { if (Enabled && area[putdown].CurrentHeight < area[putdown].Length) { area[putdown].Push(inputStack.Pop()); realMoves = 1; return 1; } realMoves = 0; return 0; } public IEnumerable GenerateNeighbours(IRandom random, int min, int max, int step = 1) { var moves = new List(); moves.Add(new IngoingMove() { Enabled = !this.Enabled, putdown = this.putdown }); if(putdown + step <= max) moves.Add(new IngoingMove() { Enabled = true, putdown = this.putdown + step }); if (putdown - step >= min) moves.Add(new IngoingMove() { Enabled = true, putdown = this.putdown - step }); return moves; } } }