Advertisement
Pavle_nis

Untitled

Mar 13th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp27
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             textBox1.Text = "3 6";
  23.             textBox2.Text = "5 0";
  24.         }
  25.         private void button1_Click(object sender, EventArgs e)
  26.         {
  27.             int[] bishopPos = new int[2];
  28.             int[] knightPos = new int[2];
  29.             char[,] board = new char[8, 8];
  30.  
  31.             bishopPos = textBox1.Text.Split(' ').Select(Int32.Parse).ToArray();
  32.             knightPos = textBox2.Text.Split(' ').Select(Int32.Parse).ToArray();
  33.  
  34.             int m = 0;
  35.  
  36.             while (true)
  37.             {
  38.                 if (m == 0)
  39.                 {
  40.                     k = 0;
  41.                     if (move(board, bishopPos, knightPos, bishopPos[0], bishopPos[1]))
  42.                     {
  43.                         MessageBox.Show("hello");
  44.                     }
  45.                     m++;
  46.                 }
  47.                 else if (m == 1)
  48.                 {
  49.                     k = 0;
  50.                     if (move(board, bishopPos, knightPos, ++bishopPos[0], --bishopPos[1]))
  51.                     {
  52.                         MessageBox.Show("hello");
  53.                     }
  54.                     m++;
  55.                 }
  56.             }
  57.         }
  58.  
  59.         int k = 0;
  60.         private bool move(char[,] board, int[] bishopPos, int[] knightPos, int x, int y)
  61.         {
  62.             if (k == 0)
  63.             {
  64.                 if (provera(++x, --y))
  65.                 {
  66.                     board[x, y] = 'L';
  67.  
  68.                     move(board, bishopPos, knightPos, x, y);
  69.                 }
  70.  
  71.                 if (x == knightPos[0] && y == knightPos[1])
  72.                 {
  73.                     return true;
  74.                 }
  75.                 else
  76.                 {
  77.                     k++;
  78.                     x = bishopPos[0];
  79.                     y = bishopPos[1];
  80.                 }
  81.             }
  82.  
  83.             if (k == 1)
  84.             {
  85.                 if (provera(--x, --y))
  86.                 {
  87.                     board[x, y] = 'L';
  88.  
  89.                     move(board, bishopPos, knightPos, x, y);
  90.                 }
  91.  
  92.                 if (x == knightPos[0] && y == knightPos[1])
  93.                 {
  94.                     return true;
  95.                 }
  96.                 else
  97.                 {
  98.                     k++;
  99.                     x = bishopPos[0];
  100.                     y = bishopPos[1];
  101.                 }
  102.             }
  103.  
  104.             if (k == 2)
  105.             {
  106.                 if (provera(++x, ++y))
  107.                 {
  108.                     board[x, y] = 'L';
  109.  
  110.                     move(board, bishopPos, knightPos, x, y);
  111.                 }
  112.  
  113.                 if (x == knightPos[0] && y == knightPos[1])
  114.                 {
  115.                     return true;
  116.                 }
  117.                 else
  118.                 {
  119.                     k++;
  120.                     x = bishopPos[0];
  121.                     y = bishopPos[1];
  122.                 }
  123.             }
  124.  
  125.             if (k == 3)
  126.             {
  127.                 if (provera(--x, ++y))
  128.                 {
  129.                     board[x, y] = 'L';
  130.  
  131.                     move(board, bishopPos, knightPos, x, y);
  132.                 }
  133.  
  134.                 if (x == knightPos[0] && y == knightPos[1])
  135.                 {
  136.                     return true;
  137.                 }
  138.                 else
  139.                 {
  140.                     k = 4;
  141.                     return false;
  142.                 }
  143.             }
  144.  
  145.             return false;
  146.         }
  147.         private static bool provera(int x1, int y1)
  148.         {
  149.             if ((x1 >= 0 && x1 <= 7) && (y1 >= 0 && y1 <= 7))
  150.             {
  151.                 return true;
  152.             }
  153.  
  154.             return false;
  155.         }
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement