Power of Thor

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
* 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.
**/

int main()
{
int lightX; // the X position of the light of power
int lightY; // the Y position of the light of power
int initialTX; // Thor's starting X position
int initialTY; // Thor's starting Y position
cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();

int tX;
int tY;
tX = initialTX;
tY = initialTY;
string dir;

// game loop
while (1) {
int remainingTurns; // The remaining amount of turns Thor can move. Do not
remove this line.
cin >> remainingTurns; cin.ignore();
if ((tX > lightX && tY > lightY)) { tX -= 1; tY -= 1; dir = "NW"; }
else if ((tX > lightX && tY < lightY)) { tX -= 1; tY += 1; dir = "SW"; }
else if ((tX < lightX && tY < lightY)) { tX += 1; tY += 1; dir = "SE"; }
else if ((tX < lightX && tY > lightY)) { tX += 1; tY -= 1; dir = "NE"; }
else if (tX > lightX) { tX -= 1; dir = "W"; }
else if (tX < lightX) { tX += 1; dir = "E"; }
else if (tY > lightY) { tY -= 1; dir = "N"; }
else if (tY < lightY) { tY += 1; dir = "S"; }
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;

// A single line providing the move to be made: N NE E SE S SW W or NW


cout << dir << endl;
}
}

You might also like