Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- /**
- * Solve this puzzle by writing the shortest code.
- * Whitespaces (spaces, new lines, tabs...) are counted in the total amount of chars.
- * These comments should be burnt after reading!
- **/
- class Player
- {
- static void Main(string[] args)
- {
- string[] inputs = Console.ReadLine().Split(' ');
- int LX = int.Parse(inputs[0]); // the X position of the light of power
- int LY = int.Parse(inputs[1]); // the Y position of the light of power
- int TX = int.Parse(inputs[2]); // Thor's starting X position
- int TY = int.Parse(inputs[3]); // Thor's starting Y position
- int currentX = TX;
- int currentY = TY;
- // game loop
- while (true)
- {
- int remainingTurns = int.Parse(Console.ReadLine()); // The level of Thor's remaining energy, representing the number of moves he can still make.
- // Write an action using Console.WriteLine()
- // To debug: Console.Error.WriteLine("Debug messages...");
- if (LY == TY && TX > LX) Console.WriteLine("W");
- else if (LY == TY && TX < LX) Console.WriteLine("E");
- else if (TX == LX && TY > LY) Console.WriteLine("N");
- else if (TX == LX && TY < LY) Console.WriteLine("S");
- else if (LX > TX && LY > TX)
- {
- // find slope == 1
- int value = (LY - currentY) / (LX - currentX);
- // if ((LX - TX ) / 2 == currentX)
- if (value == 1)
- {
- Console.WriteLine("SE"); ;
- }
- else
- {
- Console.WriteLine("E");
- currentX++;
- }
- }
- else if (LX < TX)
- {
- int slope = Math.Abs((LY - currentY) / (LX - currentX));
- // note: thor Y and light Y won't be == here, so it's safe to use >
- if (LY > TY)
- {
- // int slope = Math.Abs((LY - currentY) / (LX - currentX));
- if (slope == 1)
- {
- Console.WriteLine("SW");
- }
- else
- {
- Console.WriteLine("W");
- currentX--;
- }
- }
- else
- {
- // todo: handle when slope is < 1
- // in that case thor must move E 1st
- if (slope == 1)
- {
- Console.WriteLine("NW");
- }
- else
- {
- Console.WriteLine("W");
- currentX--;
- }
- }
- }
- // A single line providing the move to be made: N NE E SE S SW W or NW
- // Console.WriteLine("SE");
- Console.Error.WriteLine($"{currentX}, {currentY}");
- }
- }
- }
- // NOTE: THIS WILL PASS THE THE TEST IN GAME. BUT THERE ARE SOME CASE THAT NEED TO BE HANDLED. CHECK THE TODO
Add Comment
Please, Sign In to add comment