На
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Console.WriteLine("♟️ Введите координаты целевого поля (a, b):");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine("? Введите координаты коня (c, d):");
int c = int.Parse(Console.ReadLine());
int d = int.Parse(Console.ReadLine());
Console.WriteLine(IsThreatened(a, b, c, d)
? $"⚠️ Конь угрожает полю ({a}, {b}) через два хода."
: $"✅ Конь не угрожает полю ({a}, {b}) через два хода.");
Console.WriteLine("Спасибо за использование программы! ?");
}
static bool IsThreatened(int a, int b, int c, int d)
{
int[,] moves = { { 2, 1 }, { 2, -1 }, { -2, 1 }, { -2, -1 }, { 1, 2 }, { 1, -2 }, { -1, 2 }, { -1, -2 } };
var firstMoves = new HashSet<(int, int)>();
foreach (var move in moves)
{
int newC = c + move[0], newD = d + move[1];
if (IsValidPosition(newC, newD)) firstMoves.Add((newC, newD));
}
foreach (var move in firstMoves)
{
foreach (var secondMove in moves)
{
int newC2 = move.Item1 + secondMove[0], newD2 = move.Item2 + secondMove[1];
if (IsValidPosition(newC2, newD2) && newC2 == a && newD2 == b) return true;
}
}
return false;
}
static bool IsValidPosition(int x, int y) => x >= 1 && x <= 8 && y >= 1 && y <= 8;
}