public void DrawUnit(Unit unit) { var minY = unit.members.Concat(new[]{unit.pivot}).Min(cell => cell.y); while (minY > 0) { unit = unit.Move(MoveType.NE); minY--; } while (minY < 0) { unit = unit.Move(MoveType.SE); minY++; } var minX = unit.members.Min(cell => cell.x); while (minX > 0) { unit = unit.Move(MoveType.W); minX--; } while (minX < 0) { unit = unit.Move(MoveType.E); minX++; } var map = new Map(unit.members.Concat(new[] { unit.pivot }).Max(cell => cell.x) + 1, unit.members.Concat(new[] { unit.pivot }).Max(cell => cell.y) + 1); console.WriteLine(); DrawMap(map, unit); }
public void Step() { ++step; switch (state) { case State.WaitUnit: if (currentUnitIndex++ >= problem.sourceLength) { state = State.End; return; } spawnedUnitIndex = UnitIndeces[currentUnitIndex - 1]; var spawnedUnit = units[spawnedUnitIndex]; if (!spawnedUnit.IsCorrect(map)) { state = State.End; return; } currentUnit = spawnedUnit; forbiddenSequenceChecker = new ForbiddenSequenceChecker(currentUnit); moves = new List<MoveType>(); state = State.UnitInGame; return; case State.UnitInGame: char move; if (!TryGetNextMove(out move)) { state = State.End; return; } var moveType = MoveTypeExt.Convert(move); if (moveType == null) { state = State.EndInvalidCommand; return; } enteredString.Append(move); ParseNewMagicSpells(); var movedUnit = currentUnit.Move(moveType.Value); if (!movedUnit.IsCorrect(map)) { LockUnit(currentUnit); currentUnit = null; state = State.WaitUnit; return; } if (!forbiddenSequenceChecker.CheckLastMove(moves, moveType.Value)) { state = State.EndPositionRepeated; return; } moves.Add(moveType.Value); currentUnit = movedUnit; return; case State.EndInvalidCommand: return; case State.End: return; default: throw new ArgumentOutOfRangeException(); } }
private List<MoveType> FinalMoves(Unit unit) { return allowedMoves.Where(m => !unit.Move(m).IsCorrect(map)).ToList(); }