public PhraseCombineInfo(PowerPhraseData pd, PowerPhraseInfo p1, PowerPhraseInfo p2, CombineType combineType, PhraseMetricType metricType) { PrevPhrase = p1; NextPhrase = p2; this.CombineType = combineType; IntersectionLen = CalcIntersectionLen(p1.Phrase, p2.Phrase); if (combineType == CombineType.Overlap && IntersectionLen == 0) throw new Exception(); CommandsStr = p2.Phrase.Substring(IntersectionLen); var fakeUnitState = new UnitState(new Cell(0, 0), 0); Commands = MovesPrinter.GetCommands(CommandsStr); MinX = 0; MaxX = 0; foreach (var cmd in Commands) { fakeUnitState = UnitState.MoveFuncs[cmd](fakeUnitState); MinX = Math.Min(MinX, fakeUnitState.Pivot.x); MaxX = Math.Max(MaxX, fakeUnitState.Pivot.x); } DY = fakeUnitState.Pivot.y; switch (combineType) { case CombineType.Overlap: EffectiveLen = pd.CalcEffectiveLen(p1.Phrase + CommandsStr) - p1.EffectiveLength; break; case CombineType.Append: EffectiveLen = p2.EffectiveLength; break; case CombineType.MoveDownAppend: EffectiveLen = p2.EffectiveLength; ++DY; break; } switch (metricType) { case PhraseMetricType.Div: Metric = (double)EffectiveLen / DY; break; case PhraseMetricType.Diff: Metric = (double)EffectiveLen - DY; break; case PhraseMetricType.Div2: Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]]); break; case PhraseMetricType.Div3: Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]] * 2); break; default: throw new ArgumentOutOfRangeException("metricType"); } DebugPrinter.WriteLine("Phrase combine: \"{0}\" and \"{1}\" with type {2}, effective len {3}, DY {4}, metric {5}", p1.Phrase, p2.Phrase, combineType, EffectiveLen, DY, Metric); }
public GameData(InputData inputData, ArgParser argParser) { InputData = inputData; Units = inputData.units.Select(inputUnit => new Unit(inputUnit)).ToArray(); var phrases = new List<PowerPhraseInfo>(); phrases.Add(new PowerPhraseInfo("", -1)); phrases.AddRange(argParser.PowerPhrases.Select((t, i) => new PowerPhraseInfo(t, i))); PowerPhraseData = new PowerPhraseData(phrases.ToArray(), argParser.PhraseMetricType); }
public void InitCombinations(PowerPhraseData pd, PhraseMetricType metricType) { PhraseCombinations.Clear(); foreach (var p2 in pd.Phrases) { if (p2.Phrase.Length == 0) continue; foreach (CombineType combineType in Enum.GetValues(typeof(CombineType))) { try { PhraseCombinations.Add(new PhraseCombineInfo(pd, this, p2, combineType, metricType)); } catch (Exception e) { } } } //PhraseCombinations.Sort((pc1, pc2) => pc2.Metric.CompareTo(pc1.Metric)); }