using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CDSAE3_Lian_Lian_Kan.Boards { internal class Graph_Board : IBoard { class Node { public Node? LNode, RNode, UNode, DNode; public int x, y; public int value; public Node(int x, int y, int value) { this.x = x; this.y = y; this.value = value; LNode = RNode = UNode = DNode = null; } public Node(Node? lNode, Node? rNode, Node? uNode, Node? dNode, int x, int y, int value) { LNode = lNode; RNode = rNode; UNode = uNode; DNode = dNode; this.x = x; this.y = y; this.value = value; } } public (int, int) size { get; set; }//width,height Dictionary<(int,int),Node>Index = new Dictionary<(int,int), Node>();//width,height private Dictionary> board_Index = new Dictionary>(); Board_funcs board_Funcs = new Board_funcs(); private int total; private int Total { get { return total; } set { total = value; if (Total == 0) Etcs.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done }); } } private int[] Vals_per_Image { get; set; } = Array.Empty(); public void decrease(params (int, int)[] poss) { foreach (var (x, y) in poss) { int type = Index[(x, y)].value; if (!Index.Remove((x, y))) throw new Exception("Val not Found in Index"); if (!board_Index[type].Remove((x, y))) throw new Exception("Val not Found in board_Index"); Vals_per_Image[type]--; Total--; } } public List> get_tip((int, int) start) { throw new NotImplementedException(); } public int[,] make_board() { size = Etcs.get_length_width(); var (width, height) = size; int[,]Bd = new int[height + 2, width + 2]; for (int i = 0; i < height + 2; i++) for (int j = 0; j < width + 2; j++) Bd[i, j] = -1; int sum = width * height; if (sum % 2 != 0) sum--; total = sum; int types = Etcs.Images_size(); Vals_per_Image = board_Funcs.get_vals_per_image(Total, types); int last_val = -1; int cur_width = 1, cur_height = 1; var temp_val_per_Image = (int[])Vals_per_Image.Clone(); for (int i = 0; i < sum; i++) { Bd[cur_height, cur_width] = board_Funcs.getval(ref temp_val_per_Image, ref last_val, types); if (board_Index.TryGetValue(Bd[cur_height, cur_width], out var index)) index.Add((cur_width, cur_height)); else board_Index.Add(Bd[cur_height, cur_width], new List<(int, int)> { (cur_width, cur_height) }); Index.Add((cur_width, cur_height), new Node(cur_width, cur_height, Bd[cur_height, cur_width])); cur_width++; if (cur_width > width) { cur_height++; cur_width = 1; } } foreach(var (index,node)in Index) { if (Index.TryGetValue((node.x - 1, node.y), out var lnode)) node.LNode = lnode; if (Index.TryGetValue((node.x + 1, node.y), out var rnode)) node.RNode = rnode; if (Index.TryGetValue((node.x, node.y - 1), out var unode)) node.UNode = unode; if (Index.TryGetValue((node.x, node.y + 1), out var dnode)) node.DNode = dnode; Index[index] = node; } return Bd; } public int[,] remake_board() { throw new NotImplementedException(); } public (bool, List<(int, int)>?) test((int, int) a, (int, int) b) { throw new NotImplementedException(); } } }