private static void SettingTheBoard(Map _map, Point _point, ChessFigure _figure) { int solNum = 0; GetSolution(_map, _point, _figure, ref solNum); PrintNumberOfSolForQAndK(_figure.GetLook, solNum, _map); // Prints how many solutions were tryed for The Queen and for the King in 3x3 array }
public bool IsFreeSpace(byte posX, byte posY, ChessFigure figure) { if (board[posX, posY] != figure.GetLook && board[posX, posY] != figure.GetFight) { return(true); } else { return(false); } }
private static void GetSolution(Map _map, Point _point, ChessFigure _figure, ref int _solNum) { Random rnd = new Random(); byte size = _map.GetSize; byte countFigures = 0; byte countUnsuccessful = 0; while (countFigures != size) { _point.SetX = (byte)rnd.Next(0, size); _point.SetY = (byte)rnd.Next(0, size); if (_map.IsFreeSpace(_point.GetX, _point.GetY, _figure)) { if (_figure.GetLook == '\u2655' && (size == 2 || size == 3)) // If Queen { Console.WriteLine(" There is no solution for the current map size."); break; } else if (_figure.GetLook == '\u2654' && size == 2) // If King { Console.WriteLine(" There is no solution for the current map size."); break; } else { countFigures++; _map.SetOnMap(_point, _figure, ref countFigures); } } else { countUnsuccessful++; if (countUnsuccessful == size / 2) { _map.ClearMap(); countFigures = 0; _solNum++; } } } }
public void SetOnMap(Point point, ChessFigure figure, ref byte countFigures) { byte posX = point.GetX; byte posY = point.GetY; switch (figure.GetLook) { case '\u2659': // Pawn figure.SetPawnFightPos(ref posX, ref posY, ref countFigures, board, size); board[posX, posY] = figure.GetLook; break; case '\u2658': // Knight board[posX, posY] = figure.GetLook; figure.SetKnightFightPos(posX, posY, board, size); break; case '\u2657': // Bishop board[posX, posY] = figure.GetLook; figure.SetBishopFightPos(posX, posY, board, size); break; case '\u2656': // Rook board[posX, posY] = figure.GetLook; figure.SetRookFightPos(posX, posY, board, size); break; case '\u2655': // Queen board[posX, posY] = figure.GetLook; figure.SetQueenFightPos(posX, posY, board, size); break; case '\u2654': // King board[posX, posY] = figure.GetLook; figure.SetKingFightPos(posX, posY, board, size); break; } }
private static void StartProgram() { Console.OutputEncoding = Encoding.UTF8; Point point = new Point(); byte size = 0; byte spaces = 0; char fig; string command = ""; string moves = ""; ShowPicks(); while (command != "stop") { Console.Write(" Pick Figure: "); fig = char.Parse(Console.ReadLine()); if (IsUserDefindFig(fig)) { CustomFigure customFig = new CustomFigure(fig); Console.Write(" Choose figure fighting positons: "); moves = Console.ReadLine(); Console.Write(" Choose figure fighting spaces: "); spaces = byte.Parse(Console.ReadLine()); try { Console.Write(" Map Size: "); size = byte.Parse(Console.ReadLine()); if (spaces > size) { spaces = size; } Map map = new Map(size); SettingTheBoardForUser(map, point, customFig, moves, spaces); map.ShowMap(customFig.GetLook); } catch (OverflowException) { OverflowMessage(); } } else { ChessFigure figure = new ChessFigure(fig); try { Console.Write(" Map Size: "); size = byte.Parse(Console.ReadLine()); Map map = new Map(size); SettingTheBoard(map, point, figure); map.ShowMap(figure.GetLook); } catch (OverflowException) { OverflowMessage(); } } command = Console.ReadLine(); } }