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;
- namespace Core_Tasks_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = 4; //Int32.Parse(Console.ReadLine());
- //optimal search 2, 1, -1, -2, -2, -1, 1, 2
- // 1, 2, 2, 1, -1, -2, -2, -1
- // --------- clesest
- //-2, -1, 1, 2, -2, -1, 1, 2
- //-1, -2, -2, -1, 1, 2, 2, 1
- int[] rowPostions = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 }; // -2, -1, 1, 2, 2, 1, -1, -2 | -2, -1, 1, 2, 2, 1, -1, -2 | 2, 1, -1, -2, -2, -1, 1, 2 \ 1, -2, 1, -2, -1, 2, 1, -1
- int[] colPostions = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 }; // -1, -2, -2, -1, 1, 2, 2, 1 | 1, 2, 2, 1, -1, -2, -2, -1 | 1, 2, 2, 1, -1, -2, -2, -1 \ 2, 1, -2, -1, -2, -1, 2, 2
- int counterPosition = 1;
- int[,] matrix = new int[size,size];
- // array initiatig -1 to all boxes
- for(int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- matrix[row, col] = -1;
- }
- }
- bool alive = true;
- int rowCurrPosition = 0;
- int colCurrPosition = 0;
- matrix[rowCurrPosition, colCurrPosition] = counterPosition;
- bool isPossibleMove = false;
- int tm = 0;
- while (alive)
- {
- isPossibleMove = false;
- bool cnt = false;
- for(int i = 0; i < rowPostions.Length; i++)
- {
- //Console.WriteLine((rowCurrPosition + (rowPostions[i])) + " : " + (colCurrPosition + (colPostions[i])) + " : " + counterPosition);
- int tmpRowPos = rowCurrPosition + (rowPostions[i]);
- int tmpColPos = colCurrPosition + (colPostions[i]);
- if (tmpRowPos >= 0 && tmpRowPos < size &&
- tmpColPos >= 0 && tmpColPos < size &&
- matrix[tmpRowPos, tmpColPos] == -1)
- {
- //
- rowCurrPosition = tmpRowPos;
- colCurrPosition = tmpColPos;
- counterPosition++;
- matrix[rowCurrPosition, colCurrPosition] = counterPosition;
- break;
- }
- else
- {
- cnt = true;
- }
- tm++;
- }
- if (tm >= 100)
- alive = false;
- }
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement