又写了一堆屎山
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
|
||||
namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
{
|
||||
public partial class Board:IBoard
|
||||
public partial class Board : IBoard
|
||||
{
|
||||
private int[,] Bd = { { } };//y,x
|
||||
private Dictionary<int, List<(int, int)>> board_Index = new Dictionary<int, List<(int, int)>>();
|
||||
private Dictionary<int, List<(int, int)>> boardIndex = new Dictionary<int, List<(int, int)>>();
|
||||
private int[] Vals_per_Image { get; set; } = Array.Empty<int>();
|
||||
private int total;
|
||||
private int Total
|
||||
@@ -17,7 +17,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
{
|
||||
total = value;
|
||||
if (Total == 0)
|
||||
Etcs.gameModeForm?.Finished_Handler(this, new FinishArgs { finish_Type = FinishArgs.Finish_Type.All_done });
|
||||
Etcs.gameModeForm?.Finished_Handler(this, new FinishArgs { finishType = FinishArgs.FinishType.All_done });
|
||||
}
|
||||
}
|
||||
private Board_funcs board_Funcs = new Board_funcs();
|
||||
@@ -41,10 +41,10 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
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))
|
||||
if (boardIndex.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) });
|
||||
boardIndex.Add(Bd[cur_height, cur_width], new List<(int, int)> { (cur_width, cur_height) });
|
||||
cur_width++;
|
||||
if (cur_width > width)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
}
|
||||
public int[,] remake_board()
|
||||
{
|
||||
board_Index.Clear();
|
||||
boardIndex.Clear();
|
||||
var rand = new Random();
|
||||
int[] temp_val_per_Image = (int[])Vals_per_Image.Clone();
|
||||
int types = Vals_per_Image.Length;
|
||||
@@ -68,10 +68,10 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
if (Bd[i, j] != -1)
|
||||
{
|
||||
Bd[i, j] = board_Funcs.getval(ref temp_val_per_Image, ref last_val, types);
|
||||
if (board_Index.TryGetValue(Bd[i, j], out var index))
|
||||
if (boardIndex.TryGetValue(Bd[i, j], out var index))
|
||||
index.Add((j, i));
|
||||
else
|
||||
board_Index.Add(Bd[i, j], new List<(int, int)> { (j, i) });
|
||||
boardIndex.Add(Bd[i, j], new List<(int, int)> { (j, i) });
|
||||
}
|
||||
return Bd;
|
||||
}
|
||||
@@ -249,7 +249,9 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
{
|
||||
int type = Bd[y, x];
|
||||
Bd[y, x] = -1;
|
||||
if (!board_Index[type].Remove((x, y)))
|
||||
if (type == -1)
|
||||
return;
|
||||
if (!boardIndex[type].Remove((x, y)))
|
||||
throw new Exception("Val not Found in board_Index");
|
||||
Vals_per_Image[type]--;
|
||||
Total--;
|
||||
@@ -258,7 +260,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
public List<List<(int, int)>> get_tip((int, int) start)
|
||||
{
|
||||
List<List<(int, int)>> ans = new List<List<(int, int)>>();
|
||||
if (board_Index.TryGetValue(Bd[start.Item2, start.Item1], out var tip))
|
||||
if (boardIndex.TryGetValue(Bd[start.Item2, start.Item1], out var tip))
|
||||
foreach (var pos in tip)
|
||||
{
|
||||
var (result, path) = test(start, pos);
|
||||
@@ -267,6 +269,19 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public (int, int) GetRandomBlock()
|
||||
{
|
||||
Random random = new();
|
||||
int k = random.Next(0, boardIndex.Count);
|
||||
for (int i = 0; i < boardIndex.Count(); i++)
|
||||
{
|
||||
if (boardIndex[k + i].Count != 0)
|
||||
return boardIndex[k + i][random.Next(0, boardIndex[k + i].Count)];
|
||||
}
|
||||
return (-1, -1);
|
||||
}
|
||||
|
||||
public (int, int) size { get; set; }//width,height
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
}
|
||||
public (int, int) size { get; set; }//width,height
|
||||
Dictionary<(int,int),Node>Index = new Dictionary<(int,int), Node>();//width,height
|
||||
private Dictionary<int, List<(int, int)>> board_Index = new Dictionary<int, List<(int, int)>>();
|
||||
private Dictionary<int, List<(int, int)>> boardIndex = new Dictionary<int, List<(int, int)>>();
|
||||
Board_funcs board_Funcs = new Board_funcs();
|
||||
private int total;
|
||||
private int Total
|
||||
@@ -48,7 +48,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
{
|
||||
total = value;
|
||||
if (Total == 0)
|
||||
Etcs.gameModeForm?.Finished_Handler(this, new FinishArgs { finish_Type = FinishArgs.Finish_Type.All_done });
|
||||
Etcs.gameModeForm?.Finished_Handler(this, new FinishArgs { finishType = FinishArgs.FinishType.All_done });
|
||||
}
|
||||
}
|
||||
private int[] Vals_per_Image { get; set; } = Array.Empty<int>();
|
||||
@@ -72,7 +72,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
}
|
||||
else
|
||||
throw new Exception("Val not Found in Index");
|
||||
if (!board_Index[type].Remove((x, y)))
|
||||
if (!boardIndex[type].Remove((x, y)))
|
||||
throw new Exception("Val not Found in board_Index");
|
||||
Vals_per_Image[type]--;
|
||||
Total--;
|
||||
@@ -82,7 +82,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
public List<List<(int, int)>> get_tip((int, int) start)
|
||||
{
|
||||
List<List<(int, int)>> ans = new List<List<(int, int)>>();
|
||||
if (board_Index.TryGetValue(Index[start].value, out var tip))
|
||||
if (boardIndex.TryGetValue(Index[start].value, out var tip))
|
||||
foreach (var pos in tip)
|
||||
{
|
||||
var (result, path) = test(start, pos);
|
||||
@@ -120,10 +120,10 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
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))
|
||||
if (boardIndex.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) });
|
||||
boardIndex.Add(Bd[cur_height, cur_width], new List<(int, int)> { (cur_width, cur_height) });
|
||||
Index[(cur_width, cur_height)].value = Bd[cur_height, cur_width];
|
||||
cur_width++;
|
||||
if (cur_width > width)
|
||||
@@ -151,7 +151,7 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
|
||||
public int[,] remake_board()
|
||||
{
|
||||
board_Index.Clear();
|
||||
boardIndex.Clear();
|
||||
int[] temp_val_per_Image = (int[])Vals_per_Image.Clone();
|
||||
var (width, height) = size;
|
||||
int[,] Bd = new int[height + 2, width + 2];
|
||||
@@ -165,10 +165,10 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
continue;
|
||||
node.value = board_Funcs.getval(ref temp_val_per_Image, ref last_val, Etcs.Images_size());
|
||||
Bd[node.y,node.x] = node.value;
|
||||
if(board_Index.TryGetValue(node.value,out var list))
|
||||
if(boardIndex.TryGetValue(node.value,out var list))
|
||||
list.Add((node.x, node.y));
|
||||
else
|
||||
board_Index.Add(node.value, new List<(int, int)> { (node.x, node.y) });
|
||||
boardIndex.Add(node.value, new List<(int, int)> { (node.x, node.y) });
|
||||
}
|
||||
return Bd;
|
||||
}
|
||||
@@ -308,5 +308,17 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
|
||||
|
||||
}
|
||||
|
||||
public (int, int) GetRandomBlock()
|
||||
{
|
||||
Random random = new();
|
||||
int k = random.Next(0, boardIndex.Count);
|
||||
for(int i = 0;i<boardIndex.Count(); i++)
|
||||
{
|
||||
if (boardIndex[k + i].Count != 0)
|
||||
return boardIndex[k + i][random.Next(0, boardIndex[k + i].Count)];
|
||||
}
|
||||
return (-1, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@ namespace CDSAE3_Lian_Lian_Kan.Boards
|
||||
public void decrease(params (int, int)[] poss);
|
||||
public List<List<(int, int)>> get_tip((int, int) start);
|
||||
public (int, int) size { get; set; }//width,height
|
||||
public (int, int) GetRandomBlock();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user