void followPlayer() { //TODO - ainda esta muito lento if (target == null) target = FindObjectOfType<InputReader> (); int dir = anim.GetInteger ("Direction"); if(isUnicorn&&(dir == 0||dir == 2)) Debug.LogError("Direcao Invalida para unicorn"); if (!target) { anim.SetInteger ("Direction", 4); return; } if (isUnicorn) { float x = transform.localPosition.x; float tx = target.transform.localPosition.x; dir = x > tx ? 3 : 1; if (tx == x) dir = 4; anim.SetInteger ("Direction", dir); if (dir != 4) anim.SetInteger ("lastStep", dir); return; } List<int> path = getPath (transform, target.transform); if (path == null) { return; } dir = path[path.Count-1]; anim.SetInteger("Direction", dir); if(dir!=4) anim.SetInteger("lastStep", dir); }
public static void Main(string[] args) { Stream inputStream = Console.OpenStandardInput(); InputReader inp = new InputReader(inputStream); Stream outputStream = Console.OpenStandardOutput(); OutputWriter outp = new OutputWriter(outputStream); Solver algorithm = new Solver(); algorithm.solve(inp, outp); outp.close(); }
static void Main(string[] args) { var reader = new InputReader(); var writer = new OutputWriter(); var playerId = reader.ReadPlayerId(); var player = new Player(playerId, reader, writer); while (true) { player.TakeALook(); player.Attack(); } }
private static void Main(string[] args) { Console.Title = "SNAKE"; Console.CursorVisible = false; var gameBoard = new GameBoard(); //Is responsible for placing and updating the game objects. var inputReader = new InputReader(); //Reads the player's keyboard input. var timer = new Stopwatch (); //Is used to keep the frame rate consistent. const int updateDelay = 100; //Snake moves faster with lower numbers. //Reset static global variables. ResetGlobals (); //Start counting for the first frame. timer.Start (); //Start game loop while (!Global.IsGameOver) { var moveKey = inputReader.GetInput(); //Skips over this section if game is paused with spacebar. if (!Global.IsPaused) { if (timer.ElapsedMilliseconds < updateDelay) { continue; } //Recalculate and redraw snake and apple positions gameBoard.ChangeBoard(moveKey); //reset timer for next frame. timer.Restart (); } } }
/// <summary> /// Creates an InputReader implemented using Microsoft DirectInput (tm). /// </summary> /// <returns></returns> public Axiom.Input.InputReader CreateInputReader() { inputReader = new Win32InputReader(); return(inputReader); }
public void InputReader_can_be_created([Frozen] IConsoleReader reader, InputReader sut) { Assert.That(sut, Is.Not.Null); }
public void TryReadInputs_returns_false_if_tile_position_is_out_of_north_boundary([Frozen] IConsoleReader reader, InputReader sut) { Mock.Get(reader).SetupSequence(p => p.ReadLine()) .Returns("0") .Returns($"{0} {InputReader.MaxY + 1}"); var result = sut.TryReadInputs(out var output); Assert.That(result, Is.False); }
public override void Awake() { base.Awake(); _inputReader = GameManager.Instance.playerInputReader; _movementControl = GetComponent <MovementController>(); }
public void TryReadInputs_ignores_instructions_with_distance_greater_than_max_allowed([Frozen] IConsoleReader reader, InputReader sut, [Range(-100, 100)] int initialX, [Range(-100, 100)] int initialY, Direction direction, int distance) { Mock.Get(reader).SetupSequence(p => p.ReadLine()) .Returns("1") .Returns($"{initialX} {initialY}") .Returns($"{direction.ToString()[0]} {distance + InputReader.MaxDistance}"); var result = sut.TryReadInputs(out var output); Assert.That(result, Is.True); Assert.That(output !.Instructions, Has.None.InstanceOf <Instruction>()); }
/// <summary> /// The main entry point for the application. /// </summary> public static int Main(string[] args) { string OutputFormat = " {0,-14} 0x{1,-14:x}"; //IO variables. string InFilename = null; FileStream InFileStream = null; BinaryReader InputReader = null; string OutFilename = null; BinaryWriter OutputWriter = null; //Used to pass line termination chars to FixOrConvert. byte [] crlfArr = new byte[] { 0x0d, 0x0a }; byte [] lfArr = new byte[] { 0x0a }; //Get file expression from argument. try { DirectoryInfo curdir = new DirectoryInfo(System.Environment.CurrentDirectory); string FileExpression = null; //Usage if (args.Length < 1) { Console.WriteLine(nl + "Usage: crlf <filename | expression>" + nl); Console.WriteLine("Requires filename or wildcard expression." + nl); }//end if else { FileExpression = args[0]; FileInfo[] files = curdir.GetFiles(FileExpression); if (files.Length < 1) { Console.WriteLine("File does not exist or invalid file expression."); return(1); }//end if //Loop to cover all files in expression list foreach (FileInfo fi in files) { int c1 = 0; int c2 = 0; TermListType TermList = new TermListType(); string Reply = null; bool NeedsFix = false; bool AllLF = false; bool AllCRLF = false; bool CRLF = false; bool LFOnly = false; bool CROnlyFix = false; CRFixType CRFix = CRFixType.Delete; FileStream OutputFileStream = null; string Prompt = null; Console.WriteLine("Processing file: {0}", fi.Name); //Check again that file exists. Probably redundant but doesn't hurt. if (!File.Exists(fi.FullName)) { Console.WriteLine("{0} does not exist, skipping file."); continue; }//end if try { InFilename = fi.FullName; InFileStream = new FileStream(InFilename, FileMode.Open); InputReader = new BinaryReader(InFileStream, System.Text.Encoding.ASCII); }//end try catch (Exception e) { bool Exit = OutputException("Problem opening file: " + InFilename, e); if (Exit) { return(1); } else //Go to next file in list. { continue; } }//end catch InputReader.BaseStream.Seek(0, SeekOrigin.Begin); InputReader.BaseStream.Position = 0; if (InputReader.BaseStream.Length > 2) { c1 = InputReader.Read(); c2 = InputReader.Read(); } //end if else { Console.WriteLine("File too small"); //Go to next file in list. continue; } //end else if (c1 == 0x0a) { TermListItem tli = new TermListItem((long)1, TermTypeEnum.LFOnly); TermList.Add(tli); } //end if long Count = 2; //Loop through file while (c2 > -1) { if (c1 == 0x0d && c2 != 0x0a) { TermListItem CRtli = new TermListItem((long)Count - 1, TermTypeEnum.CROnly); TermList.Add(CRtli); }//end if if (c1 != 0x0d && c2 == 0x0a) { TermListItem LFtli = new TermListItem((long)Count, TermTypeEnum.LFOnly); TermList.Add(LFtli); }//end if if (c1 == 0x0d && c2 == 0x0a) { TermListItem CRLFtli = new TermListItem((long)Count, TermTypeEnum.CRLF); TermList.Add(CRLFtli); }//end if c1 = c2; c2 = InputReader.Read(); Count++; }//end while Console.WriteLine(nl + "Number of unmatched CRs: {0, 12}", TermList.CROnlyCount); Console.WriteLine("Number of LF-only chars {0, 12}", TermList.LFOnlyCount); Console.WriteLine("Number of CRLF sets: {0, 12}" + nl, TermList.CRLFCount); Console.WriteLine("Size of input file: {0}", InputReader.BaseStream.Length); if (TermList.LFOnlyCount > 0 && TermList.CRLFCount == 0) { Console.WriteLine("File is LF-only terminated" + nl); Console.WriteLine("Total number of LF terminated lines: {0}", TermList.LFOnlyCount); AllLF = true; }//end if else { if (TermList.CRLFCount > 0 && TermList.LFOnlyCount == 0) { Console.WriteLine("File is CRLF terminated"); Console.WriteLine("Total number of CRLF terminated lines: {0}", TermList.CRLFCount); AllCRLF = true; } else { if (TermList.LFOnlyCount > TermList.CRLFCount && TermList.LFOnlyCount > 0) { Console.WriteLine("File is mostly LF-only terminated"); NeedsFix = true; }//end if else { if (TermList.CRLFCount > TermList.LFOnlyCount && TermList.CRLFCount > 0) { Console.WriteLine("File is mostly CRLF terminated" + nl); NeedsFix = true; } //end if } //end else Console.WriteLine("Number of unexpected CR chars if file is LF-only: {0}" + nl, TermList.CRLFCount); if (TermList.CRLFCount > 0) { OutputLocations(TermList, TermList.FirstCRLF, OutputFormat, false, TermList.CRLFCount); }//end if Console.WriteLine("Number of unexpected LF-only chars if file is CRLF: {0}" + nl, TermList.LFOnlyCount); if (TermList.LFOnlyCount > 0) { OutputLocations(TermList, TermList.FirstLFOnly, OutputFormat, false, TermList.LFOnlyCount); }//end if else { Console.WriteLine("Insufficient line termination chars to " + "determine termination type." + nl); //Jump to next file in list. continue; } //end else } //end else } //end else if (TermList.CROnlyCount > 0) { CROnlyFix = true; Console.WriteLine("Number of unmatched CR-only chars: {0}" + nl, TermList.CROnlyCount); OutputLocations(TermList, TermList.FirstCROnly, OutputFormat, true, TermList.CROnlyCount); }//end if if (NeedsFix || CROnlyFix) { Prompt = nl + "Do you wish to fix this file? "; }//end if else { if (AllLF) { Prompt = "Do you wish to convert this file to all CRLF? "; }//end if else { if (AllCRLF) { Prompt = "Do you wish to convert this file to all LF-only? "; } //end if } //end else } //end else Console.Write(Prompt); Reply = Console.ReadLine(); if (Reply.ToLower() == "y" || Reply.ToLower() == "yes") { try { OutFilename = Path.GetFileNameWithoutExtension(InFilename) + ".fixed" + Path.GetExtension(InFilename); OutputFileStream = new FileStream(OutFilename, FileMode.Create); OutputWriter = new BinaryWriter(OutputFileStream, System.Text.Encoding.ASCII); }//end try catch (Exception e) { bool Exit = OutputException("Problem opening file: " + OutFilename, e); if (Exit) { return(1); } else { continue; } }//end catch //Reposition input file seek for second read from start. InputReader.BaseStream.Seek(0, SeekOrigin.Begin); InputReader.BaseStream.Position = 0; //If we got here with 'yes' then we will convert to opposite if no fixes required. if (AllLF) { CRLF = true; }//end if else { if (AllCRLF) { LFOnly = true; } //end if } //end else //Since we need fixes, ask which way to convert. //Ask to convert towards most common one first. if (NeedsFix) { if (TermList.CRLFCount >= TermList.LFOnlyCount) //Mostly CRLF { Console.Write("Do you wish to make file CRLF? "); Reply = Console.ReadLine(); if (Reply.ToLower() == "y" || Reply.ToLower() == "yes") { CRLF = true; }//end if else { Console.WriteLine("Modified file will be LF-only..."); LFOnly = true; } //end else } //end if else //Mostly LF-only { Console.Write("Do you wish to make file LF-only? "); Reply = Console.ReadLine(); if (Reply.ToLower() == "y" || Reply.ToLower() == "yes") { LFOnly = true; }//end if else { Console.WriteLine("Modified file will be CRLF..."); CRLF = true; } //end else } } //end if if (TermList.CROnlyCount > 0) { Console.Write("Do you wish to delete unmatched CR chars? "); Reply = Console.ReadLine(); if (Reply.ToLower() == "y" || Reply.ToLower() == "yes") { CRFix = CRFixType.Delete; } else { Console.WriteLine("Unmatched CR chars will be replaced with normal line termination."); CRFix = CRFixType.Replace; } }//end if if (NeedsFix || CROnlyFix) { if (CROnlyFix && !NeedsFix) //CROnlyFix case { if (CRLF) { FixOrConvert(TermList, InputReader, OutputWriter, crlfArr, TermList.FirstCROnly, CRFix); }//end if else { if (LFOnly) { FixOrConvert(TermList, InputReader, OutputWriter, lfArr, TermList.FirstCROnly, CRFix); } //end if } //end else } //end if else { if (CRLF) //Change LF-onlys to CRLF during fix { FixOrConvert(TermList, InputReader, OutputWriter, crlfArr, TermList.FirstLFOnly, CRFix); }//end if else { if (LFOnly) //Change CRLFs to LF-only during fix { FixOrConvert(TermList, InputReader, OutputWriter, lfArr, TermList.FirstCRLF, CRFix); } //end if } //end else } //end if } //end else else //File conversion only { if (CRLF) //Convert to CRLF { FixOrConvert(TermList, InputReader, OutputWriter, crlfArr, -1, CRFix); }//end if else { if (LFOnly) //Convert to LF-only { FixOrConvert(TermList, InputReader, OutputWriter, lfArr, -1, CRFix); } //end if } //end else } //end else OutputWriter.BaseStream.Flush(); OutputWriter.Close(); OutputWriter = null; Console.WriteLine(nl + "Modified file saved to: {0}", OutFilename); } //end if else //Reply was 'no' { Console.WriteLine("Exiting without creating fixed or modified file."); }//end else InputReader.Close(); InputReader = null; Console.WriteLine(); } //end foreach } //end else return(0); } //end try catch (Exception e) { OutputException("Unexpected exception", e); return(1); }//end catch finally { if (InputReader != null) { InputReader.Close(); }//end if if (OutputWriter != null) { OutputWriter.Close(); } //end if } //end finally } //end Main
public IEnumerable <string> Run() { return(InputReader.GetNextWord().Select(GetNextLargestWord)); }
void Awake() { inputReader = GetComponent <InputReader>(); commandProcessor = GetComponent <CommandProcessor>(); }
private static Task <IEnumerable <string> > ReadInputAsync() => InputReader.ReadLinesAsync("Day13/input.txt");
public void Solution1() { var map = InputReader.ReadLines("Day03/input.txt"); Console.WriteLine(Day03.Solve(map, 3, 1)); }
public InputReaderTest() { inputReader = new InputReader(); }
public void solve(InputReader inp, OutputWriter outp) { //hello-world outp.println("hello-world"); }
public void Setup() { _sut = new InputReader(); }
void Start() { playButton = GameObject.Find ("PlayButton").GetComponent<Button> (); controller = GetComponent<CharacterController>(); inputs = GetComponent<InputReader> (); temp = level; AudioSource[] sounds = GetComponents<AudioSource>(); LevelCompleteSound = sounds [0]; PlayerDeath = sounds [1]; playButton.onClick.AddListener (() => { if(InputReader.isPlayed == false && InGameGui.paused == false){ InputReader.isPlayed = true; StartCoroutine("RelayedInput"); } }); }
public void UpdateInputReader() { _inputReader = MyPrefs.GetInputReader(); }
public Player(int id, InputReader reader, OutputWriter writer) { this.id = id; this.entityFactory = EntityFactory.CreateChain(id); this.reader = reader; this.writer = writer; this.updateMethods = new Dictionary<Type, Action<Entity>> { { typeof(Droplet), e => UpdateDroplet(e as Droplet) }, { typeof(Chip), e => UpdateChip(e as Chip) } }; this.ownChips = new List<Chip>(); this.enemies = new List<Chip>(); this.powers = new List<Droplet>(); }
public static long GetTotalFuel() { var masses = InputReader.ReadLinesLong("Day01/Input.txt"); return(masses.Sum(GetNeededFuel)); }
public static T Add <T>(this IInjectorStream <T> stream, string text, InputReader inputReader) { return(stream.Add(new LocatedString(text), inputReader)); }
protected virtual void doUpdate() { attackUpdate -= Time.deltaTime; if (attackUpdate < 0) { attackUpdate = 0; } blockCooldown -= Time.deltaTime; if (blockCooldown < 0) { blockCooldown = 0; } if (GetComponent <HealthManager>().shieldActivated) { return; } if (InputReader.getInput(controller, InputReader.ControlType.B_BTN) == 1 && isNearGround() && secondary()) { manageAnimation(); rigidbody.velocity = new Vector2(); return; } if (InputReader.getInput(controller, InputReader.ControlType.X_BTN) == 1) { if (isNearGround()) { a_ground(); } else { a_air(); } } grounded = isNearGround(); Vector2 vel = rigidbody.velocity; float value = vel.y > 0 ? gravUp : gravDown; fly = vel.y > 0; if (isNearGround()) { jumpCounter = 0; blocked = false; } vel.Set(vel.x, isGrounded() ? 0 : vel.y - value * Time.deltaTime); if (vel.y < maxFallSpeed) { vel.Set(vel.x, maxFallSpeed); } rigidbody.velocity = vel; if (InputReader.getInput(controller, InputReader.ControlType.HORIZONTAL) == 1) { moveRight(); } else if (InputReader.getInput(controller, InputReader.ControlType.HORIZONTAL) == -1) { moveLeft(); } else { slow(); } handleButtons(); if (move_right) { animator.gameObject.transform.rotation = new Quaternion(0, 0, 0, 0); } else { animator.gameObject.transform.rotation = new Quaternion(0, 180, 0, 0); } manageAnimation(); }
public static T Add <T>(this IInjectorStream <T> stream, LocatedString locatedString, InputReader inputReader) { inputReader.AddToInjectorStream(stream, locatedString); return((T)stream); }
private static Task <IEnumerable <long> > ReadInputAsync() => InputReader.ReadLinesAsLongsAsync("Day09/input.txt");
public void Solution1() { var input = InputReader.ReadLines("Day08/input.txt"); Console.WriteLine(new Day08Part1(input).Solve()); }
public string[] GetInput(string resourceName) { return(InputReader.GetInput(resourceName)); }
public void Solution2() { var input = InputReader.ReadLines("Day08/input.txt"); Console.WriteLine(Day08Part2.Solve(input)); }
// Use this for initialization void Start() { inputReader = GameObject.Find("TextDisplay").GetComponent <InputReader>(); animator = GetComponent <Animator>(); animator.SetInteger("Selection", Random.Range(0, 9)); }
public void ExamplePart1() { var input = InputReader.ReadLines("Day08/input-example.txt"); new Day08Part1(input).Solve().Should().Be(5); }
public void TryReadInputs_ignores_invalid_instructions([Frozen] IConsoleReader reader, InputReader sut, [Range(-100, 100)] int initialX, [Range(-100, 100)] int initialY, string invalidInstruction) { Mock.Get(reader).SetupSequence(p => p.ReadLine()) .Returns("1") .Returns($"{initialX} {initialY}") .Returns(invalidInstruction); var result = sut.TryReadInputs(out var output); Assert.That(result, Is.True); Assert.That(output !.Instructions, Has.None.InstanceOf <Instruction>()); }
private static async Task <long[]> ReadInputAsync() => (await InputReader.ReadLinesAsLongsAsync("Day01/input.txt")).ToArray();
public void TryReadInputs_returns_false_if_GTE_max_number_of_allowed_instructions_is_entered([Frozen] IConsoleReader reader, InputReader sut, [Range(-100, 100)] int initialX, [Range(-100, 100)] int initialY) { Mock.Get(reader).SetupSequence(p => p.ReadLine()) .Returns($"{InputReader.MaxInstructions}") .Returns($"{initialX} {initialY}"); var result = sut.TryReadInputs(out var output); Assert.That(result, Is.False); }
public Round() { A = CoordinateUtils.SetCoordinate("A"); R = InputReader.GetIntValue("Введите радиус: "); }
public void TryReadInputs_returns_false_if_tile_position_is_invalid([Frozen] IConsoleReader reader, InputReader sut, string invalidTilePosition) { Mock.Get(reader).SetupSequence(p => p.ReadLine()) .Returns("0") .Returns(invalidTilePosition); var result = sut.TryReadInputs(out var output); Assert.That(result, Is.False); }
/// <summary> /// Handles the setup of the Input system for the ExampleApplication /// </summary> protected virtual void SetupInput() { // retreive and initialize the input system Input = PlatformManager.Instance.CreateInputReader(); Input.Initialize(Window, true, true, false, false); }
protected override void Initialize() { _input = InputReader.ReadFile("input.txt") .Select(l => l.Select(i => i).ToArray()) .ToArray(); }
private static int Run(CmdOptions opts) { var prescriptionPath = ExperimentPrescriptionPath(opts); if (!File.Exists(prescriptionPath)) { Console.WriteLine($"Experiment prescription file {prescriptionPath} does not exist."); return(1); } var prescription = JsonConvert.DeserializeObject <Prescription>( File.ReadAllText(prescriptionPath), new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Populate }); if (!Directory.Exists(Program.DatasetsPath(opts))) { Console.WriteLine($"Datasets directory {Program.DatasetsPath(opts)} does not exist."); return(1); } foreach (var datasetName in prescription.DatasetNames) { var datasetPath = DatasetPath(opts, datasetName); if (!Directory.Exists(datasetPath)) { Console.WriteLine($"Dataset directory {datasetPath} does not exist."); return(1); } } if (opts.FromScratch) { foreach (var datasetName in prescription.DatasetNames) { foreach (var solverPrescription in prescription.Solvers) { var solverResultsPath = ResultsExperimentDatasetSolverPath( opts, datasetName, solverPrescription.Id); if (Directory.Exists(solverResultsPath)) { Directory.Delete(solverResultsPath, true); } } } } // TODO: if (opts.NumThreads != 1) { Console.WriteLine($"Parallel instance solving is not currently supported due to:"); Console.WriteLine($"- optimal switching cost is computed in parallel and there is no option to disable this"); return(1); } var objectLock = new object(); foreach (var datasetName in prescription.DatasetNames) { var instancePaths = Directory.EnumerateFiles(DatasetPath(opts, datasetName)).ToList(); foreach (var solverPrescription in prescription.Solvers) { var prescriptionSolverConfig = PrescriptionSolverConfig.Merge( prescription.GlobalConfig, solverPrescription.Config); Parallel.ForEach( instancePaths, new ParallelOptions { MaxDegreeOfParallelism = opts.NumThreads }, (instancePath) => { try { Console.WriteLine($"Solving {instancePath} using {solverPrescription.Id}"); var resultPath = ResultPath( opts, datasetName, solverPrescription.Id, Path.GetFileName(instancePath)); if (opts.FromScratch == false && File.Exists(resultPath)) { Console.WriteLine($"{instancePath} using {solverPrescription.Id} already solved"); return; } var instance = new InputReader().ReadFromPath(instancePath); SolverConfig solverConfig; lock (objectLock) { solverConfig = prescriptionSolverConfig.ToSolverConfig(solverPrescription.SpecializedSolverConfig); } if (solverPrescription.InitStartTimesFrom != null) { var initStartTimesResultPath = ResultPath( opts, datasetName, solverPrescription.InitStartTimesFrom, Path.GetFileName(instancePath)); var initStartTimesResult = JsonConvert.DeserializeObject <Result>( File.ReadAllText(initStartTimesResultPath)); if (initStartTimesResult.Status == Status.Optimal || initStartTimesResult.Status == Status.Heuristic) { solverConfig.InitStartTimes = initStartTimesResult.StartTimes; } } if (solverPrescription.SubstractExtendedInstanceGenerationFromTimeLimit && solverConfig.TimeLimit.HasValue && instance.TimeForExtendedInstance.HasValue) { solverConfig.TimeLimit = new TimeSpan(Math.Max( 0, solverConfig.TimeLimit.Value.Ticks - instance.TimeForExtendedInstance.Value.Ticks)); } var solver = new SolverFactory().Create(solverPrescription.SolverName); var solverResult = solver.Solve(solverConfig, instance); if (solverResult.Status == Status.Optimal || solverResult.Status == Status.Heuristic) { var feasibilityChecker = new FeasibilityChecker(); var feasibilityStatus = feasibilityChecker.Check(instance, solverResult.StartTimes, solverConfig, solverResult.Objective); if (feasibilityStatus != FeasibilityChecker.FeasibilityStatus.Feasible) { throw new Exception($"Feasibility check failed: {feasibilityStatus}, {instancePath}, {solverPrescription.Id}"); } } lock (objectLock) { if (!Directory.Exists(Path.GetDirectoryName(resultPath))) { Directory.CreateDirectory(Path.GetDirectoryName(resultPath)); } } File.WriteAllText( resultPath, JsonConvert.SerializeObject(Result.FromSolverResult(solverResult))); } catch (Exception) { Console.WriteLine($"Error while solving {instancePath} using {solverPrescription.Id}"); throw; } }); } } return(0); }