Files
EightQueens/Program.cs

45 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using EightQueens;
var board = new Board();
string[] cmd = [];
bool quit = false;
while (!quit)
{
board.Draw();
Console.WriteLine(
$"\nДействия:\n"
+ $"add X Y - добавить ферзя\n"
+ $"del X Y - удалить ферзя\n"
+ $"clear - очистить доску\n"
+ $"issolved - проверить решение задачи\n"
+ $"exit - выход\n");
var cmdString = Console.ReadLine();
if (cmdString == null) continue;
cmd = cmdString.Trim().Split();
switch (cmd[0])
{
case "add":
board.Add(int.Parse(cmd[1]), int.Parse(cmd[2]));
break;
case "del":
board.Remove(int.Parse(cmd[1]), int.Parse(cmd[2]));
break;
case "clear":
board.Clear();
break;
case "issolved":
Console.WriteLine(board.IsBoardSafe() ? "Ферзи в безопасности!" : "Задача не выполняется");
break;
case "exit":
quit = true;
break;
default:
Console.WriteLine($"Неизвестная команда '{cmd[0]}'");
break;
}
Console.WriteLine($"\n=======================\n");
}