//Метод проверяющий лежит ли фигура на форме рисунка,если да возвращает все 5 точек в которых фигура лежит иначе null private NodeCoord[] CheckFigures(int[,] cur_figure, int i, int j) { bool flag = true; NodeCoord[] coord = new NodeCoord[5]; for (int dot = 0; dot < cur_figure.GetLength(0); dot++) { int row = i + cur_figure[dot, 0]; int col = j + cur_figure[dot, 1]; try { if (board_array[row, col] != 1) { flag = false; coord = null; break; } } catch (IndexOutOfRangeException e) { flag = false; coord = null; break; } coord[dot] = node_coord[row, col]; } return(flag ? coord : null); }
private void SetChildrenPositions(NodeCoord node, int position) { if (node == null) { return; } node.Position = position; //SetChildrenPositions(node.left, position - 2); //SetChildrenPositions(node.right, position + 2); }
private void ShiftRight(NodeCoord node, int shift) { if (node == null) { return; } node.Position += shift; ShiftRight(node.Left, shift); ShiftRight(node.Right, shift); }
private NodeCoord GetCommonRoot(NodeCoord left, NodeCoord right) { if (left == right) { return(right); } var currLeft = left; var currRight = right; while (currLeft != null && currRight != null && currLeft != currRight) { currLeft = currLeft.Parent; currRight = currRight.Parent; } return(currRight); }
private NodeCoord BuildLevels(NodeCoord parent, TreeNode node, int level, int position) { if (node == null) { return(null); } if (!Matrix.ContainsKey(level)) { Matrix[level] = new List <NodeCoord>(); } var nd = new NodeCoord(node, parent); nd.Position = position; nd.Level = level; Matrix[level].Add(nd); nd.Left = BuildLevels(nd, node.left, level + 1, position - 1); nd.Right = BuildLevels(nd, node.right, level + 1, position + 1); return(nd); }
public void PentaminoSolve() { bool isSolve = dlx.Solve(); if (!isSolve || rows_count == 0) { Console.WriteLine("Решений нет"); return; } solution_res = new char[board_array.GetLength(0), board_array.GetLength(1)]; for (int i = 0; i < solution_res.GetLength(0); i++) { for (int j = 0; j < solution_res.GetLength(1); j++) { solution_res[i, j] = ' '; } } char key = 'A'; foreach (Nodes.Node sol in dlx.SolutionArr) { Nodes.Node node = sol; do { if (node.data.GetType() == typeof(NodeCoord)) { NodeCoord coord = ((NodeCoord)node.data); if (coord != null) { solution_res[coord.x, coord.y] = key; } } node = node.right; } while (node != sol); key++; } print(); }
public override bool Equals(object obj) { NodeCoord o = (NodeCoord)obj; return((o.x == x) && (o.y == y)); }
//Метод создания структуры матрицы для Алгоритма-Х public void CreateMatrixStructur() { int headerCount = 0; for (int i = 0; i < board_array.GetLength(0); i++) { for (int j = 0; j < board_array.GetLength(1); j++) { if (board_array[i, j] == 1) { node_coord[i, j] = new NodeCoord() { x = i, y = j }; headerCount++; } } } dlx.CreateHeadersNodes(headerCount + 12); Nodes.Node header_node = dlx.header_root.right; int count = 0; for (int i = 0; i < board_array.GetLength(0); i++) { for (int j = 0; j < board_array.GetLength(1); j++) { if (node_coord[i, j] != null) { header_node.data = node_coord[i, j]; header_node = header_node.right; count++; } } } figure_id = new FigureId[12]; for (int i = 0; i < 12; i++) { FigureId figure_node_id = new FigureId() { id = i }; header_node.data = figure_node_id; ((Nodes.HeaderNode)header_node).isNodeID = true; header_node = header_node.right; figure_id[i] = figure_node_id; } List <Figures.FigureItem> list = Figures.GetFigures(); for (int f = 0; f < list.Count; f++) { int[,] cur_figures = (int[, ])list[f].figure.Clone(); int figure_id = list[f].figure_id; for (int i = 0; i < board_array.GetLength(0); i++) { for (int j = 0; j < board_array.GetLength(1); j++) { if (board_array[i, j] == 1) { NodeCoord[] c = CheckFigures(cur_figures, i, j); if (c != null) { AddToStructureMatrix(cur_figures, figure_id, i, j, c); rows_count++; } } } } } }
public NodeCoord(TreeNode node, NodeCoord parent) { Node = node; Parent = parent; }