Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp27
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox1.Text = "3 6";
- textBox2.Text = "5 0";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int[] bishopPos = new int[2];
- int[] knightPos = new int[2];
- char[,] board = new char[8, 8];
- bishopPos = textBox1.Text.Split(' ').Select(Int32.Parse).ToArray();
- knightPos = textBox2.Text.Split(' ').Select(Int32.Parse).ToArray();
- int m = 0;
- while (true)
- {
- if (m == 0)
- {
- k = 0;
- if (move(board, bishopPos, knightPos, bishopPos[0], bishopPos[1]))
- {
- MessageBox.Show("hello");
- }
- m++;
- }
- else if (m == 1)
- {
- k = 0;
- if (move(board, bishopPos, knightPos, ++bishopPos[0], --bishopPos[1]))
- {
- MessageBox.Show("hello");
- }
- m++;
- }
- }
- }
- int k = 0;
- private bool move(char[,] board, int[] bishopPos, int[] knightPos, int x, int y)
- {
- if (k == 0)
- {
- if (provera(++x, --y))
- {
- board[x, y] = 'L';
- move(board, bishopPos, knightPos, x, y);
- }
- if (x == knightPos[0] && y == knightPos[1])
- {
- return true;
- }
- else
- {
- k++;
- x = bishopPos[0];
- y = bishopPos[1];
- }
- }
- if (k == 1)
- {
- if (provera(--x, --y))
- {
- board[x, y] = 'L';
- move(board, bishopPos, knightPos, x, y);
- }
- if (x == knightPos[0] && y == knightPos[1])
- {
- return true;
- }
- else
- {
- k++;
- x = bishopPos[0];
- y = bishopPos[1];
- }
- }
- if (k == 2)
- {
- if (provera(++x, ++y))
- {
- board[x, y] = 'L';
- move(board, bishopPos, knightPos, x, y);
- }
- if (x == knightPos[0] && y == knightPos[1])
- {
- return true;
- }
- else
- {
- k++;
- x = bishopPos[0];
- y = bishopPos[1];
- }
- }
- if (k == 3)
- {
- if (provera(--x, ++y))
- {
- board[x, y] = 'L';
- move(board, bishopPos, knightPos, x, y);
- }
- if (x == knightPos[0] && y == knightPos[1])
- {
- return true;
- }
- else
- {
- k = 4;
- return false;
- }
- }
- return false;
- }
- private static bool provera(int x1, int y1)
- {
- if ((x1 >= 0 && x1 <= 7) && (y1 >= 0 && y1 <= 7))
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement