先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
213 lines
7.3 KiB
C#
213 lines
7.3 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
public class FishSequenceData
|
||
{
|
||
public int id;
|
||
public int difference_value_1;
|
||
public int difference_value_2;
|
||
public List<int> sequence = new List<int>();
|
||
}
|
||
|
||
public class PVPToolWindow : EditorWindow
|
||
{
|
||
[MenuItem("Window/PVP 序列生成")]
|
||
|
||
public static void OpenPVPToolWindow()
|
||
{
|
||
GetWindow<PVPToolWindow>("PVP 序列生成");
|
||
}
|
||
|
||
public int contrast_index_1 = 6;
|
||
public int contrast_index_2 = 8;
|
||
public int difference_1 = 500;
|
||
public int difference_2 = 700;
|
||
public int min_1 = 1200;
|
||
public int max_1 = 4500;
|
||
public int min_2 = 1600;
|
||
public int max_2 = 6000;
|
||
public int continuity = 4;
|
||
|
||
public string fileName = "序列数据";
|
||
public string fileName2 = "PVPData_1";
|
||
List<FishSequenceData> FishSequence = new List<FishSequenceData>();
|
||
|
||
private void OnGUI()
|
||
{
|
||
GUILayout.Label("PVP 序列生成", EditorStyles.boldLabel);
|
||
fileName = EditorGUILayout.TextField("保存数据的文件名", fileName);
|
||
|
||
EditorGUILayout.BeginHorizontal();
|
||
contrast_index_1 = EditorGUILayout.IntField("前6条鱼", contrast_index_1);
|
||
contrast_index_2 = EditorGUILayout.IntField("前8条鱼", contrast_index_2);
|
||
EditorGUILayout.EndHorizontal();
|
||
EditorGUILayout.BeginHorizontal();
|
||
difference_1 = EditorGUILayout.IntField("前6条鱼差值", difference_1);
|
||
difference_2 = EditorGUILayout.IntField("前8条鱼差值", difference_2);
|
||
EditorGUILayout.EndHorizontal();
|
||
EditorGUILayout.BeginHorizontal();
|
||
min_1 = EditorGUILayout.IntField("前6条鱼最小值", min_1);
|
||
min_2 = EditorGUILayout.IntField("前8条鱼最小值", min_2);
|
||
EditorGUILayout.EndHorizontal();
|
||
EditorGUILayout.BeginHorizontal();
|
||
max_1 = EditorGUILayout.IntField("前6条鱼最大值", max_1);
|
||
max_2 = EditorGUILayout.IntField("前8条鱼最大值", max_2);
|
||
EditorGUILayout.EndHorizontal();
|
||
continuity = EditorGUILayout.IntField("连续性", continuity);
|
||
if (GUILayout.Button("生成"))
|
||
{
|
||
GeneratePVPData();
|
||
}
|
||
|
||
}
|
||
private void GeneratePVPData()
|
||
{
|
||
// 生成PVP数据的逻辑
|
||
// 这里可以使用上面定义的参数来生成数据
|
||
//然后存成一个csv文件
|
||
string path = EditorUtility.SaveFilePanel("保存序列数据", "", $"{fileName}.csv", "csv");
|
||
if (string.IsNullOrEmpty(path))
|
||
return;
|
||
System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
|
||
sw.WriteLine("id,difference_value_1,difference_value_2,sequence");
|
||
GenerateFishSequence("", 0, 0);
|
||
FishSequence.Sort((x, y) =>
|
||
{
|
||
if (x.difference_value_1 != y.difference_value_1)
|
||
{
|
||
return x.difference_value_1.CompareTo(y.difference_value_1);
|
||
}
|
||
else
|
||
{
|
||
return x.difference_value_2.CompareTo(y.difference_value_2);
|
||
}
|
||
});
|
||
for (int i = 0; i < FishSequence.Count; i++)
|
||
{
|
||
FishSequence[i].id = i + 1;
|
||
sw.WriteLine($"{FishSequence[i].id},{FishSequence[i].difference_value_1},{FishSequence[i].difference_value_2},{string.Join(";", FishSequence[i].sequence)}");
|
||
}
|
||
sw.Close();
|
||
AssetDatabase.Refresh();
|
||
|
||
EditorUtility.DisplayDialog("提示", "生成序列数据成功", "确定");
|
||
string path2 = EditorUtility.SaveFilePanel("保存匹配数据", "", $"{fileName2}.csv", "csv");
|
||
|
||
if (string.IsNullOrEmpty(path2))
|
||
return;
|
||
System.IO.StreamWriter sw2 = new System.IO.StreamWriter(path2);
|
||
sw2.WriteLine("id,player1,player2");
|
||
int id = 0;
|
||
int count = FishSequence.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
FishSequenceData fishSequence = FishSequence[0];
|
||
List<int> ints = new List<int>();
|
||
Debug.Log(fishSequence.id);
|
||
for (int j = 1; j < FishSequence.Count; j++)
|
||
{
|
||
if (Mathf.Abs(fishSequence.difference_value_1 - FishSequence[j].difference_value_1) > difference_1)
|
||
{
|
||
break;
|
||
}
|
||
if (Mathf.Abs(fishSequence.difference_value_2 - FishSequence[j].difference_value_2) > difference_2)
|
||
{
|
||
continue;
|
||
}
|
||
ints.Add(FishSequence[j].id);
|
||
}
|
||
if (ints.Count > 0)
|
||
{
|
||
id++;
|
||
sw2.WriteLine($"{id},{fishSequence.id},{string.Join(";", ints)}");
|
||
}
|
||
FishSequence.RemoveAt(0);
|
||
}
|
||
sw2.Close();
|
||
AssetDatabase.Refresh();
|
||
EditorUtility.DisplayDialog("提示", "生成匹配数据成功", "确定");
|
||
}
|
||
|
||
void GenerateFishSequence(string fishList, int score, int j)
|
||
{
|
||
if (j >= continuity)
|
||
{
|
||
//后4未一样,返回
|
||
if (fishList.Substring(j - continuity, continuity).Distinct().Count() == 1)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
j++;
|
||
for (int i = 1; i <= 5; i++)
|
||
{
|
||
int allScore = score;
|
||
int quality = i;
|
||
allScore += ScoreMap[quality - 1];
|
||
if (!AdjustAndValidateSequence(allScore, j))
|
||
{
|
||
return;
|
||
}
|
||
if (j == contrast_index_2)
|
||
{
|
||
List<int> list = fishList.Select(p => int.Parse(p.ToString())).ToList();
|
||
list.Add(quality);
|
||
var difference_value_1 = Mathf.Abs(list.Take(contrast_index_1).Sum(t => ScoreMap[t - 1]));
|
||
var difference_value_2 = Mathf.Abs(list.Take(contrast_index_2).Sum(t => ScoreMap[t - 1]));
|
||
if (FishSequence.FindLast(p => p.difference_value_1 == difference_value_1
|
||
&& p.difference_value_2 == difference_value_2
|
||
&& list.Sum() == p.sequence.Sum()) != null)
|
||
{
|
||
return;
|
||
}
|
||
FishSequenceData fishSequenceData = new FishSequenceData();
|
||
fishSequenceData.sequence = list;
|
||
fishSequenceData.difference_value_1 = difference_value_1;
|
||
fishSequenceData.difference_value_2 = difference_value_2;
|
||
|
||
FishSequence.Add(fishSequenceData);
|
||
return;
|
||
}
|
||
GenerateFishSequence(fishList + quality.ToString(), allScore, j);
|
||
}
|
||
}
|
||
|
||
private bool AdjustAndValidateSequence(int scoreFirst, int length)
|
||
{
|
||
//c.1200<前6条鱼的积分<4500;1600<前8条鱼的积分<6000
|
||
if (length < contrast_index_1)
|
||
{
|
||
return scoreFirst < max_1;
|
||
}
|
||
else if (length == contrast_index_1)
|
||
{
|
||
if (scoreFirst < min_1 || scoreFirst > max_1)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
else if (length < contrast_index_2)
|
||
{
|
||
return scoreFirst < max_2;
|
||
}
|
||
else
|
||
{
|
||
// 计算前8条鱼的积分
|
||
if (scoreFirst < min_2 || scoreFirst > max_2)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private static readonly int[] ScoreMap =
|
||
{
|
||
70, 120, 200, 500, 1500
|
||
};
|
||
|
||
}
|
||
|