This repository has been archived on 2024-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
CDSAE3/CDSAE3_Lian_Lian_Kan/Boards/Board_funcs.cs

66 lines
1.9 KiB
C#
Raw Normal View History

2024-04-02 15:14:34 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDSAE3_Lian_Lian_Kan.Boards
{
internal class Board_funcs
{
private Random random = new Random();
2024-04-18 00:38:59 +00:00
internal int getval(ref int[] temp_val_per_Image, ref int last_val, int types)
2024-04-02 15:14:34 +00:00
{
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 = 0;
for (int i = 0; i < temp_val_per_Image.Length; i++)
if (temp_val_per_Image[i] != 0)
{
k = i;
break;
}
temp_val_per_Image[k]--;
return k;
}
int t = random.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;
}
2024-04-18 00:38:59 +00:00
internal int[] get_vals_per_image(int total, int type_num)
2024-04-02 15:14:34 +00:00
{
2024-04-18 00:38:59 +00:00
int[] vals_per_Image = new int[type_num];
2024-04-02 15:14:34 +00:00
int single = total / type_num;
for (int k = total; k > 0; k -= 2)
{
int t = random.Next(0, type_num);
2024-04-18 00:38:59 +00:00
if (vals_per_Image[t] >= 1.5 * single && single != 0)
2024-04-02 15:14:34 +00:00
{
k += 2;
continue;
}
vals_per_Image[t] += 2;
}
return vals_per_Image;
}
}
}