Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class KnightPath
- {
- static void Main()
- {
- int[] numbers = new int[8];
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = 0;
- }
- string input = Console.ReadLine();
- int currentNumber = 0;
- int position = 0;
- numbers[currentNumber] = 1;
- while (input != "stop")
- {
- string[] inputAsArray = input.Split();
- string firstCommand = inputAsArray[0];
- string secondCommand = inputAsArray[1];
- if (firstCommand == "left" && secondCommand == "up")
- {
- if (position + 2 <= 7 && currentNumber - 1 >= 0)
- {
- position += 2;
- currentNumber--;
- }
- }
- else if (firstCommand == "left" && secondCommand == "down")
- {
- if (position + 2 <= 7 && currentNumber + 1 <= 7)
- {
- position += 2;
- currentNumber++;
- }
- }
- else if (firstCommand == "right" && secondCommand == "up")
- {
- if (position - 2 >= 0 && currentNumber - 1 >= 0)
- {
- position -= 2;
- currentNumber--;;
- }
- }
- else if (firstCommand == "right" && secondCommand == "down")
- {
- if (position - 2 >= 0 && currentNumber + 1 <= 7)
- {
- position -= 2;
- currentNumber++;
- }
- }
- else if (firstCommand == "up" && secondCommand == "left")
- {
- if (position + 1 <= 7 && currentNumber - 2 >= 0)
- {
- position++;
- currentNumber -= 2;
- }
- }
- else if (firstCommand == "up" && secondCommand == "right")
- {
- if (position - 1 >= 0 && currentNumber - 2 >= 0)
- {
- position--;
- currentNumber -= 2;
- }
- }
- else if (firstCommand == "down" && secondCommand == "left")
- {
- if (position + 1 <= 7 && currentNumber + 2 <= 7)
- {
- position++;
- currentNumber += 2;
- }
- }
- if (firstCommand == "down" && secondCommand == "right")
- {
- if (position - 1 >= 0 && currentNumber + 2 <= 7)
- {
- position--;
- currentNumber += 2;
- }
- }
- if (((numbers[currentNumber] >> position) & 1) == 0)
- {
- numbers[currentNumber] ^= (1 << position);
- }
- input = Console.ReadLine();
- }
- bool zeroBoard = true;
- foreach (int number in numbers)
- {
- if (number != 0)
- {
- Console.WriteLine(number);
- zeroBoard = false;
- }
- }
- if (zeroBoard)
- {
- Console.WriteLine("[Board is empty]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement