Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace KnightPath
- {
- class KnightPath
- {
- static void Main(string[] args)
- {
- int[] numbers = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
- int indexOfNumbers = 0;
- int curentPosition = 0;
- numbers[indexOfNumbers] |= 1;
- bool stop = false;
- while (!stop)
- {
- string commandString = Console.ReadLine();
- if (commandString == "stop")
- {
- stop = true;
- continue;
- }
- string[] comands = commandString.Split(' ');
- string firstCommand = comands[0];
- string secondCommand = comands[1];
- if (firstCommand == "left" && secondCommand == "up")
- {
- if ((curentPosition + 2) > 7 | (indexOfNumbers - 1) < 0) continue;
- curentPosition += 2;
- indexOfNumbers -= 1;
- }
- else if (firstCommand == "left" && secondCommand == "down")
- {
- if ((curentPosition + 2) > 7 | (indexOfNumbers + 1) > 7) continue;
- curentPosition += 2;
- indexOfNumbers += 1;
- }
- else if (firstCommand == "right" && secondCommand == "up")
- {
- if ((curentPosition - 2) < 0 | (indexOfNumbers - 1) < 0) continue;
- curentPosition -= 2;
- indexOfNumbers -= 1;
- }
- else if (firstCommand == "right" && secondCommand == "down")
- {
- if ((curentPosition - 2) < 0 | (indexOfNumbers + 1) > 7) continue;
- curentPosition -= 2;
- indexOfNumbers += 1;
- }
- else if (firstCommand == "up" && secondCommand == "left")
- {
- if ((curentPosition + 1) > 7 | (indexOfNumbers - 2) < 0) continue;
- curentPosition += 1;
- indexOfNumbers -= 2;
- }
- else if (firstCommand == "up" && secondCommand == "right")
- {
- if ((curentPosition - 1) < 0 | (indexOfNumbers - 2) < 0) continue;
- curentPosition -= 1;
- indexOfNumbers -= 2;
- }
- else if (firstCommand == "down" && secondCommand == "left")
- {
- if ((curentPosition + 1) > 7 | (indexOfNumbers + 2) > 7) continue;
- curentPosition += 1;
- indexOfNumbers += 2;
- }
- else if (firstCommand == "down" && secondCommand == "right")
- {
- if ((curentPosition - 1) < 0 | (indexOfNumbers + 2) > 7) continue;
- curentPosition -= 1;
- indexOfNumbers += 2;
- }
- if (((numbers[indexOfNumbers] >> curentPosition) & 1) == 0)
- {
- numbers[indexOfNumbers] |= (1 << curentPosition);
- }
- else if (((numbers[indexOfNumbers] >> curentPosition) & 1) == 1)
- {
- numbers[indexOfNumbers] &= (~(1 << curentPosition));
- }
- }
- int counter1 = 0;
- for (int i = 0; i < 8; i++)
- {
- counter1 += numbers[i];
- }
- if (counter1 == 0)
- {
- Console.WriteLine("[Board is empty]");
- }
- else
- {
- for (int i = 0; i < 8; i++)
- {
- if (numbers[i] > 0)
- {
- Console.WriteLine(numbers[i]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement