Last active
May 5, 2020 00:24
-
-
Save yCatDev/d014249f01ea40c241013582673c0237 to your computer and use it in GitHub Desktop.
Revisions
-
yCatDev revised this gist
May 5, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public bool CanMove(char x, int y) //Просчитываем нашу позицию и ту куда нас хотят всунуть pp = pos + point; //Просчитываем нашу и ту куда мы можем пройти pt = to; //Код отрисовки для проверок игнорируем /*try -
yCatDev renamed this gist
May 4, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
yCatDev created this gist
May 4, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,129 @@ using System; namespace TSS { public class Knight { public char X; public int Y; /// <summary> /// Воспомогательный енам для преобразования /// </summary> private enum Symbols { ZERO, a, b, c, d, e, f, g, h } public Knight(char x = 'a', int y = 1) { X = x; Y = y; //Отрисовка поля игнорим /* for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Console.Write('.'); } Console.WriteLine(); } */ } public bool CanMove(char x, int y) { //Выставляем все нужные переменные их странного буквено-цифреного формата в нормальный var pos = new Point(GetTrueX(X)-1, Y-1); //Console.SetCursorPosition(pos.X,pos.Y); //Console.Write('X'); var to = new Point(GetTrueX(x)-1, y-1); //-1 потому что нахер от 1 считать оло foreach (var point in PossiblePoints()) { Point pp, pt; //Просчитываем нашу позицию и ту куда нас хотят всунуть pp = pos + point; //Просчитываем нашу и ту куда мы можем пройти pt = pos + to; //Код отрисовки для проверок игнорируем /*try { Console.SetCursorPosition(pt.X, pt.Y); Console.Write('0'); Console.SetCursorPosition(pp.X, pp.Y); Console.Write('+'); } catch { ; }*/ //Конец кода отрисовки //Финальное сравнение if (pp==pt) return true; } return false; } /// <summary> /// Уникальный массив для коня, так как он может ходить только по /// определенным участкам мы их сразу выделяем /// (НЕ РАБОТАЕТ ДЛЯ ДРУГИХ ФИГУР, ТАМ МОТЕМОТИКОЙ ПРОЩЕ) /// </summary> /// <returns></returns> private Point[] PossiblePoints() => new[] { new Point(2, 1), new Point(2, -1), new Point(-2, 1), new Point(-2, -1), new Point(1, 2), new Point(1, -2), new Point(-1, 2), new Point(-1, -2), }; /// <summary> /// Трюк для легкого преобразования буквы в нужныю нам цифру /// </summary> private static int GetTrueX(char x) => (int) Enum.Parse<Symbols>(x.ToString()); /// <summary> /// Поспомогательный класс для передачи позиций ибо постоянно юзать х у неудобно /// </summary> public class Point { public int X; public int Y; public Point(int x, int y) { X = x; Y = y; } /// <summary> /// Делоем сложение чтобы не писать двухметровые строки /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public static Point operator +(Point left, Point right) => new Point(left.X + right.X, left.Y + right.Y); /// <summary> /// ПроверОчка /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public static bool operator ==(Point left, Point right) => left.X == right.X && left.Y == right.Y; public static bool operator !=(Point left, Point right) => !(left == right); } } }