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(); internal int getval(ref int[] temp_val_per_Image, ref int last_val, int types) { 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; } internal int[] get_vals_per_image(int total, int type_num) { int[] vals_per_Image = new int[type_num]; int single = total / type_num; for (int k = total; k > 0; k -= 2) { int t = random.Next(0, type_num); if (vals_per_Image[t] >= 1.5 * single && single != 0) { k += 2; continue; } vals_per_Image[t] += 2; } return vals_per_Image; } } }