画线 加声音
This commit is contained in:
@@ -5,25 +5,28 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using CDSAE3_Lian_Lian_Kan;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
|
||||
namespace CDSAE3_Lian_Lian_Kan.Board_funcs
|
||||
{
|
||||
public partial class Board
|
||||
{
|
||||
public Board() {
|
||||
}
|
||||
public int[,]? Bd { get; set; } = null;//y,x
|
||||
public int[]? vals_per_Image = null;
|
||||
public int[,] Bd { get; set; } = { { } };//y,x
|
||||
public Dictionary<int, List<(int, int)>> board_Index { get; } = new Dictionary<int, List<(int, int)>>();
|
||||
public int[] Vals_per_Image { get; set; } = { };
|
||||
public int total;
|
||||
public int Total { get
|
||||
public int Total
|
||||
{
|
||||
get
|
||||
{
|
||||
return total;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
total = value;
|
||||
if(total == 0)
|
||||
if (total == 0)
|
||||
Settings.game_mode_form?.Finished_Handler(this, new Forms.FinishArgs { finish_Type = Forms.FinishArgs.Finish_Type.All_done });
|
||||
} }
|
||||
}
|
||||
}
|
||||
public void make_board()
|
||||
{
|
||||
var rand = new Random();
|
||||
@@ -38,68 +41,139 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
|
||||
sum--;
|
||||
total = sum;
|
||||
int types = Settings.Images_size();
|
||||
vals_per_Image = new int[types];
|
||||
int single = sum/types;
|
||||
for(int k = sum; k>0; k-=2)
|
||||
Vals_per_Image = new int[types];
|
||||
int single = sum / types;
|
||||
for (int k = sum; k > 0; k -= 2)
|
||||
{
|
||||
int t = rand.Next(0, types);
|
||||
if (vals_per_Image[t] >= 1.5*single)
|
||||
if (Vals_per_Image[t] >= 1.5 * single)
|
||||
{
|
||||
k += 2;
|
||||
continue;
|
||||
}
|
||||
vals_per_Image[t]+=2;
|
||||
Vals_per_Image[t] += 2;
|
||||
}
|
||||
int cur_width = 1, cur_height = 1;
|
||||
var temp_val_per_Image = (int[])vals_per_Image.Clone();
|
||||
var temp_val_per_Image = (int[])Vals_per_Image.Clone();
|
||||
int last_val = -1;
|
||||
Func<int> getval = () =>
|
||||
{
|
||||
int t = rand.Next(0, types);
|
||||
if (temp_val_per_Image[t] == 0)
|
||||
int not_zero = 0;
|
||||
foreach (int x in temp_val_per_Image)
|
||||
if (x != 0)
|
||||
{
|
||||
not_zero++;
|
||||
if (not_zero > 1)
|
||||
break;
|
||||
}
|
||||
if (not_zero <= 1)
|
||||
{
|
||||
int i = (t + 1)%types;
|
||||
for (; temp_val_per_Image[i] == 0; i %= types)
|
||||
int k = temp_val_per_Image.Single(x => x != 0);
|
||||
temp_val_per_Image[k]--;
|
||||
return k;
|
||||
}
|
||||
int t = rand.Next(0, types);
|
||||
if (temp_val_per_Image[t] == 0 || t == last_val)
|
||||
{
|
||||
int i = (t + 1) % types;
|
||||
for (; temp_val_per_Image[i] == 0 || i == last_val; i %= types)
|
||||
i++;
|
||||
temp_val_per_Image[i]--;
|
||||
last_val = i;
|
||||
return i;
|
||||
}
|
||||
temp_val_per_Image[t]--;
|
||||
last_val = t;
|
||||
return t;
|
||||
};
|
||||
for (int i=0;i<sum;i++)
|
||||
for (int i = 0; i < sum; i++)
|
||||
{
|
||||
Bd[cur_height,cur_width] = getval();
|
||||
Bd[cur_height, cur_width] = getval();
|
||||
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) });
|
||||
cur_width++;
|
||||
if (cur_width > width)
|
||||
{
|
||||
{
|
||||
cur_height++;
|
||||
cur_width = 1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
public (bool,List<(int,int)>?) test((int,int) a,(int,int) b)//x,y
|
||||
public void remake_board()
|
||||
{
|
||||
board_Index.Clear();
|
||||
var rand = new Random();
|
||||
int[] temp_val_per_Image = (int[])Vals_per_Image.Clone();
|
||||
int types = Vals_per_Image.Length;
|
||||
int height = Bd.GetLength(0);
|
||||
int width = Bd.GetLength(1);
|
||||
int last_val = -1;
|
||||
Func<int> getval = () =>
|
||||
{
|
||||
int not_zero = 0;
|
||||
foreach (int x in temp_val_per_Image)
|
||||
if (x != 0)
|
||||
{
|
||||
not_zero++;
|
||||
if (not_zero > 1)
|
||||
break;
|
||||
}
|
||||
if (not_zero <= 1)
|
||||
{
|
||||
int k = temp_val_per_Image.Single(x => x != 0);
|
||||
temp_val_per_Image[k]--;
|
||||
return k;
|
||||
}
|
||||
int t = rand.Next(0, types);
|
||||
if (temp_val_per_Image[t] == 0 || t == last_val)
|
||||
{
|
||||
int i = (t + 1) % types;
|
||||
for (; temp_val_per_Image[i] == 0 || i == last_val; i %= types)
|
||||
i++;
|
||||
temp_val_per_Image[i]--;
|
||||
last_val = i;
|
||||
return i;
|
||||
}
|
||||
temp_val_per_Image[t]--;
|
||||
last_val = t;
|
||||
return t;
|
||||
};
|
||||
for (int i = 0; i < height; i++)
|
||||
for (int j = 0; j < width; j++)
|
||||
if (Bd[i, j] != -1)
|
||||
{
|
||||
Bd[i, j] = getval();
|
||||
if (board_Index.TryGetValue(Bd[i, j], out var index))
|
||||
index.Add((j, i));
|
||||
else
|
||||
board_Index.Add(Bd[i, j], new List<(int, int)> { (j, i) });
|
||||
}
|
||||
}
|
||||
public (bool, List<(int, int)>?) test((int, int) a, (int, int) b)//x,y
|
||||
{
|
||||
bool reverse = false;
|
||||
if (a == b)
|
||||
return (false,null);
|
||||
if (Bd?[a.Item2, a.Item1] != Bd?[b.Item2, b.Item1])
|
||||
return (false,null);
|
||||
return (false, null);
|
||||
if (Bd[a.Item2, a.Item1] != Bd[b.Item2, b.Item1])
|
||||
return (false, null);
|
||||
var (xa, ya) = a;
|
||||
var (xb, yb) = b;
|
||||
Func<bool, int, int, int,bool> line_test = (bool x,int ct,int from,int to) =>
|
||||
Func<bool, int, int, int, bool> line_test = (bool x, int ct, int from, int to) =>
|
||||
{//ct is x (x==true)left to right ///up to down
|
||||
if (from > to)
|
||||
(from, to) = (to, from);
|
||||
if (x)
|
||||
{
|
||||
for (int i = from + 1; i < to; i++)
|
||||
if (Bd?[ct, i] != -1)
|
||||
if (Bd[ct, i] != -1)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
for (int i = from + 1; i < to; i++)
|
||||
if (Bd?[i, ct] != -1)
|
||||
if (Bd[i, ct] != -1)
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
@@ -115,9 +189,9 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
|
||||
HashSet<(int, int)> reachableA = new HashSet<(int, int)>(), reachableB = new HashSet<(int, int)>();
|
||||
Func<(int, int), HashSet<(int, int)>, bool> check_insert = ((int, int) pos, HashSet<(int, int)> insert) =>//x,y
|
||||
{
|
||||
if (pos.Item1 < 0 || pos.Item2 < 0 || pos.Item1 >= Bd?.GetLength(1) || pos.Item2 >= Bd?.GetLength(0))
|
||||
if (pos.Item1 < 0 || pos.Item2 < 0 || pos.Item1 >= Bd.GetLength(1) || pos.Item2 >= Bd.GetLength(0))
|
||||
return false;
|
||||
if (Bd?[pos.Item2, pos.Item1] == -1)
|
||||
if (Bd[pos.Item2, pos.Item1] == -1)
|
||||
{
|
||||
insert.Add(pos);
|
||||
return true;
|
||||
@@ -182,33 +256,57 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
|
||||
if (find_ans)
|
||||
return (true, new List<(int, int)> { a, (pax, pay), b });
|
||||
if (reachableA.Count > reachableB.Count)
|
||||
{
|
||||
{
|
||||
(a, b) = (b, a);
|
||||
reverse = true;
|
||||
}
|
||||
}
|
||||
{//three line test
|
||||
Func<(int, int), (int, int), (bool, (int, int))> intersection = ((int, int) a, (int, int) b) =>
|
||||
Func<(int, int), (int, int), (bool, (int, int))> intersection = ((int, int) a, (int, int) b) =>//first small last big
|
||||
{
|
||||
if (a.Item1 > b.Item1)
|
||||
(a, b) = (b, a);
|
||||
if (a.Item2 < b.Item1)
|
||||
return (false, (-1, -1));
|
||||
if (a.Item2 > b.Item2)
|
||||
return (true,( b.Item1, b.Item2));
|
||||
return (true, (b.Item1, b.Item2));
|
||||
return (true, (b.Item1, a.Item2));
|
||||
};
|
||||
var (throughx, xrange) = intersection((squareA[3].Item1, squareA[1].Item1), (squareB[3].Item1, squareB[1].Item1));
|
||||
var (throughy, yrange) = intersection((squareA[0].Item2, squareA[2].Item2), (squareB[0].Item2, squareB[2].Item2));
|
||||
Func<(int, int), List<int>> swing_check = ((int, int) range) =>
|
||||
{
|
||||
int mid = (range.Item2 - range.Item1) / 2 + range.Item1;
|
||||
bool swing = true;//up true
|
||||
List<int> ans = new List<int> { mid };
|
||||
for (int i = 1; ;)
|
||||
{
|
||||
int t;
|
||||
if (swing)
|
||||
t = mid + i;
|
||||
else
|
||||
{
|
||||
t = mid - i;
|
||||
i++;
|
||||
}
|
||||
swing = !swing;
|
||||
if (t >= range.Item1 && t <= range.Item2)
|
||||
ans.Add(t);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return ans;
|
||||
};
|
||||
if (throughx)
|
||||
for (int i = xrange.Item1; i <= xrange.Item2; i++)
|
||||
foreach (int i in swing_check(xrange))
|
||||
if (line_test(false, i, a.Item2, b.Item2))
|
||||
if (reverse)
|
||||
return (true, new List<(int, int)> { b, (i, b.Item2), (i, a.Item2), a });
|
||||
else
|
||||
return (true, new List<(int, int)> { a, (i, a.Item2), (i, b.Item2), b });
|
||||
|
||||
if (throughy)
|
||||
for (int i = yrange.Item1; i <= yrange.Item2; i++)
|
||||
foreach (int i in swing_check(yrange))
|
||||
if (line_test(true, i, a.Item1, b.Item1))
|
||||
if (reverse)
|
||||
return (true, new List<(int, int)> { b, (b.Item1, i), (a.Item1, i), a });
|
||||
@@ -217,6 +315,33 @@ namespace CDSAE3_Lian_Lian_Kan.Board_funcs
|
||||
}
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
|
||||
internal void decrease(params (int, int)[] poss)
|
||||
{
|
||||
foreach (var (x, y) in poss)
|
||||
{
|
||||
int type = Bd[y, x];
|
||||
Bd[y, x] = -1;
|
||||
if (!board_Index[type].Remove((x, y)))
|
||||
throw new Exception("Val not Found in board_Index");
|
||||
Vals_per_Image[type]--;
|
||||
}
|
||||
}
|
||||
|
||||
internal 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))
|
||||
foreach (var pos in tip)
|
||||
{
|
||||
var (result, path) = test(start, pos);
|
||||
if(result&&path!=null)
|
||||
ans.Add(path);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public (int, int) size { get; set; }//width,height
|
||||
public Settings.Mode mode { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user