Advertisement
Lusien_Lashans

Coding game Thor

Jan 22nd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 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. {
  16.     static void Main(string[] args)
  17.     {
  18.         string[] inputs = Console.ReadLine().Split(' ');
  19.         int lightX = int.Parse(inputs[0]); // the X position of the light of power
  20.         int lightY = int.Parse(inputs[1]); // the Y position of the light of power
  21.         int initialTX = int.Parse(inputs[2]); // Thor's starting X position
  22.         int initialTY = int.Parse(inputs[3]); // Thor's starting Y position
  23.  
  24.         // game loop
  25.         while (true)
  26.         {
  27.             Action<string> move = (string dir) => Console.WriteLine(dir);
  28.             Action<int, string> moveN = (int n, string dir) =>
  29.                 {
  30.                     for (int i = 0; i < n; i++)
  31.                         move(dir);
  32.                 };
  33.             Action<int, string, int, string> moveKek = (int hypoten, string tt, int stright, string td) =>
  34.                 {
  35.                     moveN(stright, td);
  36.                     moveN(hypoten, tt);
  37.                 };
  38.             int remainingTurns = int.Parse(Console.ReadLine()); // The remaining amount of turns Thor can move. Do not remove this line.
  39.             Console.Error.WriteLine(remainingTurns.ToString());
  40.             // Write an action using Console.WriteLine()
  41.             // To debug: Console.Error.WriteLine("Debug messages...");
  42.  
  43.  
  44.             // A single line providing the move to be made: N NE E SE S SW W or NW
  45.             var deltaX = lightX - initialTX;
  46.             var deltaY = lightY - initialTY;
  47.             var absX = (int) Math.Abs(deltaX);
  48.             var absY = (int) Math.Abs(deltaY);
  49.             if (deltaX == 0 && deltaY > 0)
  50.                 move("S");
  51.             if (deltaX == 0 && deltaY < 0)
  52.                 move("N");
  53.             if (deltaY == 0 && deltaX > 0)
  54.                 move("E");
  55.             if (deltaY == 0 && deltaX < 0)
  56.                 move("W");
  57.            
  58.             var switcher = CheckSwitcher(deltaX, deltaY);
  59.             var straight = (int) Math.Abs(absX - absY);
  60.             var hypotenX = (int) Math.Round(absX * Math.Sqrt(2));
  61.             var hypotenY = (int) Math.Round(absY * Math.Sqrt(2));
  62.             Console.Error.WriteLine("Debug messages  " + hypotenX);
  63.             switch(switcher)
  64.             {
  65.                 case 1:
  66.                     moveKek(hypotenX, "SE", straight, "S");
  67.                 break;
  68.                 case 2:
  69.                     moveKek(hypotenX, "SW", straight, "S");
  70.                 break;
  71.                 case 3:
  72.                     moveKek(hypotenY, "SE", straight, "E");
  73.                 break;
  74.                 case 4:
  75.                     moveKek(hypotenY, "NW", straight, "W");
  76.                 break;
  77.                 case 5:
  78.                     moveKek(hypotenX, "NW", straight, "N");
  79.                 break;
  80.                 case 6:
  81.                     moveKek(hypotenX, "NE", straight, "N");
  82.                 break;
  83.                 case 7:
  84.                     moveKek(hypotenY, "NE", straight, "E");
  85.                 break;
  86.                 case 8:
  87.                     moveKek(hypotenX, "SW", straight, "W");
  88.                 break;
  89.             }
  90.             //Console.WriteLine("SE");
  91.         }
  92.     }
  93.    
  94.     static int CheckSwitcher(int deltaX, int deltaY)
  95.     {
  96.         var absX = Math.Abs(deltaX);
  97.         var absY = Math.Abs(deltaY);
  98.         if (deltaX < 0 && deltaY > 0)
  99.             return (absY > absX) ? 1 : 8;
  100.         if (deltaX > 0 && deltaY > 0)
  101.             return (absY > absX) ? 2 : 3;
  102.         if (deltaX > 0 && deltaY < 0)
  103.             return (absY > absX) ? 5 : 4;
  104.         if (deltaX < 0 && deltaY < 0)
  105.             return (absY > absX) ? 6 : 4;
  106.        
  107.         return -1;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement