Skip to content

Instantly share code, notes, and snippets.

@tomliversidge
Last active May 12, 2017 13:51
Show Gist options
  • Save tomliversidge/60cb5c87f63f69e3bb13fcf87a793020 to your computer and use it in GitHub Desktop.
Save tomliversidge/60cb5c87f63f69e3bb13fcf87a793020 to your computer and use it in GitHub Desktop.
Thor
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
* ---
* Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
**/
class Player
{
static void Main(string[] args)
{
string[] inputs = Console.ReadLine().Split(' ');
int lightX = int.Parse(inputs[0]); // the X position of the light of power
int lightY = int.Parse(inputs[1]); // the Y position of the light of power
int currentPositionX = int.Parse(inputs[2]); // Thor's starting X position
int currentPositionY = int.Parse(inputs[3]); // Thor's starting Y position
// game loop
while (true)
{
int remainingTurns = int.Parse(Console.ReadLine()); // The remaining amount of turns Thor can move. Do not remove this line.
int xDiff = lightX - currentPositionX;
int yDiff = lightY - currentPositionY;
string direction = "";
if (yDiff > 0) {
direction += "S";
currentPositionY++;
}
if (yDiff < 0) {
direction += "N";
currentPositionY--;
}
if (xDiff > 0) {
direction += "E";
currentPositionX++;
}
if (xDiff < 0) {
direction += "W";
currentPositionX--;
}
Console.WriteLine(direction);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment