Advertisement
Chronos_Ouroboros

Untitled

Mar 3rd, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  * ---
  12.  * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
  13.  **/
  14. class Player {
  15.     static readonly Dictionary<int, string> dirs = new Dictionary<int,string> {
  16.         [( 0+1) | (( 1+1) << 16)] = "N",
  17.         [(-1+1) | (( 1+1) << 16)] = "NE",
  18.         [(-1+1) | (( 0+1) << 16)] = "E",
  19.         [(-1+1) | ((-1+1) << 16)] = "SE",
  20.         [( 0+1) | ((-1+1) << 16)] = "S",
  21.         [( 1+1) | ((-1+1) << 16)] = "SW",
  22.         [( 1+1) | (( 0+1) << 16)] = "W",
  23.         [( 1+1) | (( 1+1) << 16)] = "NW",
  24.     };
  25.  
  26.     public static int Clamp (int value, int min, int max) {  
  27.         return (value < min) ? min : (value > max) ? max : value;
  28.     }
  29.    
  30.     static void Main (string [] args) {
  31.         string [] inputs = Console.ReadLine ().Split (' ');
  32.         int lightX = int.Parse (inputs [0]); // the X position of the light of power
  33.         int lightY = int.Parse (inputs [1]); // the Y position of the light of power
  34.         int initialTX = int.Parse (inputs [2]); // Thor's starting X position
  35.         int initialTY = int.Parse (inputs [3]); // Thor's starting Y position
  36.        
  37.         int thorX = initialTX;
  38.         int thorY = initialTY;
  39.  
  40.         // game loop
  41.         while (true) {
  42.             int remainingTurns = int.Parse (Console.ReadLine ()); // The remaining amount of turns Thor can move. Do not remove this line.
  43.  
  44.             // Write an action using Console.WriteLine()
  45.             // To debug: Console.Error.WriteLine("Debug messages...");
  46.            
  47.             int diffX = Clamp (thorX - lightX, -1, 1);
  48.             int diffY = Clamp (thorY - lightY, -1, 1);
  49.             thorX += diffX;
  50.             thorY += diffY;
  51.            
  52.             Console.Error.WriteLine ("({0}, {1})", diffX, diffY);
  53.            
  54.             Console.WriteLine (dirs [(diffX+1) | ((diffY+1) << 16)]);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement