ある日、boss給了一個很獨特的想法拂共,讓我實現(xiàn)牺弄,我知道要做什么東西出來,卻很沒底宜狐,因為感覺很容易寫錯势告,然后,我還在緊張的條件說想一下就能寫出來抚恒,然后咱台,寫完之后直接跑出正確的結(jié)果了,很開心俭驮,很開心
usingSystem;
usingUnityEngine;
usingSystem.IO;
usingSystem.Text;
usingSystem.Collections.Generic;
usingSystem.Text.RegularExpressions;
usingSystem.Collections;
usingSystem.Linq;
usingSystem.Reflection;
publicclassword_Map{
publicstringword;
publicList?wh;//坐標
//public?int?jianglicichangdu;//獎勵詞長度
}
publicclassMapee{
publicList?WMList;
publicintjianglicichangdu;//獎勵詞長度
publicintjiaochadiangeshu;//交叉點個數(shù)
publicintw;
publicinth;
publicintallwordlength;
}
publicclassmap{
privatestaticmap_instance;
publicstaticmapInstance
{
get
{
if(_instance?==null)
{
_instance?=newmap();
}
return_instance;
}
}
publicmap()
{
}
stringanswerPath?="Json/answer/";
publicList?getJsonArray(stringjson)
{
stringnewJson?="{\"array\":"+?json?+"}";
Wrapper?wrapper?=JsonUtility.FromJson>(newJson);
returnwrapper.array;
}
[Serializable]
privateclassWrapper
{
publicList?array?=null;
}
stringJsonPath?="Json/";
//統(tǒng)計交叉點和地圖
publicvoidsss()?{
File.Delete(Application.dataPath?+"http://"+"FileNamesss"+".txt");
StreamWritersw;
FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");
if(!fi.Exists)
{
sw?=?fi.CreateText();
}
else{
sw?=?fi.AppendText();
}
stringdata?=?(Resources.Load(JsonPath?+"UpToServer")asTextAsset).text;
List?er?=?getJsonArray(data);
for(inti?=0;?i?<?er.Count;?i++)?{
GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);
Mapeemp?=newMapee();
mp.w?=?gl.w;
mp.h?=?gl.h;
mp.allwordlength?=0;
List?WMLists=newList();
mp.jianglicichangdu?=0;
for(intj?=0;?j?<?gl.wordsList.Count;?j++)?{
mp.allwordlength?+=?gl.wordsList[j].word.Length;
word_MapWM?=newword_Map();
WM.word?=?gl.wordsList[j].word;
List?rto0?=newList();
intwordlength?=?gl.wordsList[j].word.Length;
if(gl.wordsList[j].d?==0)?{
for(intm?=0;?m?<?wordlength;?m++)?{
Vector2temp?=newVector2();
temp.x?=?gl.wordsList[j].x?+?m;
temp.y?=?gl.wordsList[j].y;
rto0.Add(temp);
}
}elseif(gl.wordsList[j].d?==1){
for(intm?=0;?m?<?wordlength;?m++)
{
Vector2temp?=newVector2();
temp.x?=?gl.wordsList[j].x?;
temp.y?=?gl.wordsList[j].y+m;
rto0.Add(temp);
}
}elseif(gl.wordsList[j].d?==2||gl.wordsList[j].d?==3)?{
//Debug.Log(i+"???"+er[i]);
mp.jianglicichangdu?+=?wordlength;
}
WM.wh?=?rto0;
WMLists.Add(WM);
}
mp.WMList?=?WMLists;
Dictionary?dic?=newDictionary();
for(intm?=0;?m?<?mp.WMList.Count;?m++){
List?removelist?=newList();
for(intn?=0;?n?<?mp.WMList[m].wh.Count;?n++)
{
if(dic.ContainsKey(mp.WMList[m].wh[n])?==false)?{
dic.Add(mp.WMList[m].wh[n],m);
}else{
removelist.Add(mp.WMList[m].wh[n]);
mp.WMList[dic[mp.WMList[m].wh[n]]].wh.Remove(mp.WMList[m].wh[n]);
}
}
mp.jiaochadiangeshu?+=?removelist.Count;
for(intn?=0;?n?<?removelist.Count;?n++)?{
mp.WMList[m].wh.Remove(removelist[n]);
}
}
//int?w_1?=?0;
//int?w_2?=?0;
//int?w_3?=?0;
//int?w_4?=?0;
//int?w_5?=?0;
//int?w_6?=?0;
//for?(int?m?=?0;?m?<?mp.WMList.Count;?m++)?{
//if?(mp.WMList[m].wh.Count?==?0)
//{
////獎勵詞
//}
//else?if?(mp.WMList[m].wh.Count?==?1)?{?w_1++;?}
//else?if?(mp.WMList[m].wh.Count?==?2)?{?w_2++;?}
//else?if?(mp.WMList[m].wh.Count?==?3)?{?w_3++;?}
//else?if?(mp.WMList[m].wh.Count?==?4)?{?w_4++;?}
//else?if?(mp.WMList[m].wh.Count?==?5)?{?w_5++;?}
//else?if?(mp.WMList[m].wh.Count?==?6)?{?w_6++;?}
//else?if?(mp.WMList[m].wh.Count?==?7)?{?w_7++;?}
//else?{
//Debug.Log("不可能"?+?mp.WMList[m].wh.Count?+?"_"?+?er[i]);
//}
//sw.WriteLine(w_6?+?"\t"?+?w_5?+?"\t"?+?w_4?+?"\t"?+?w_3?+?"\t"+?w_2?+?"\t"?+?w_1?+?"\t"?+?mp.jianglicichangdu);
sw.WriteLine(mp.w?+"\t"+?mp.h?+"\t"+?mp.WMList.Count?+"\t"+?mp.allwordlength?+"\t"+?mp.jiaochadiangeshu);
}
sw.Flush();
sw.Close();
}
//除去交叉點
publicvoidsss2()
{
File.Delete(Application.dataPath?+"http://"+"FileNamesss"+".txt");
StreamWritersw;
FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");
if(!fi.Exists)
{
sw?=?fi.CreateText();
}
else{
sw?=?fi.AppendText();
}
stringdata?=?(Resources.Load(JsonPath?+"UpToServer")asTextAsset).text;
List?er?=?getJsonArray(data);
for(inti?=0;?i?<?er.Count;?i++)
{
GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);
Mapeemp?=newMapee();
List?WMLists?=newList();
mp.jianglicichangdu?=0;
for(intj?=0;?j?<?gl.wordsList.Count;?j++)
{
word_MapWM?=newword_Map();
WM.word?=?gl.wordsList[j].word;
List?rto0?=newList();
intwordlength?=?gl.wordsList[j].word.Length;
if(gl.wordsList[j].d?==0)
{
for(intm?=0;?m?<?wordlength;?m++)
{
Vector2temp?=newVector2();
temp.x?=?gl.wordsList[j].x?+?m;
temp.y?=?gl.wordsList[j].y;
rto0.Add(temp);
}
}
elseif(gl.wordsList[j].d?==1)
{
for(intm?=0;?m?<?wordlength;?m++)
{
Vector2temp?=newVector2();
temp.x?=?gl.wordsList[j].x;
temp.y?=?gl.wordsList[j].y?+?m;
rto0.Add(temp);
}
}
elseif(gl.wordsList[j].d?==2||?gl.wordsList[j].d?==3)
{
mp.jianglicichangdu?+=?wordlength;
}
WM.wh?=?rto0;
WMLists.Add(WM);
}
mp.WMList?=?WMLists;
//Debug.Log(WMLists.Count);
//int?jiaochadian?=?0;
Dictionary?dic?=newDictionary();
dic.Clear();
for(intm?=0;?m?<?mp.WMList.Count;?m++)
{
List?removelist?=newList();
removelist.Clear();
for(intn?=0;?n?<?mp.WMList[m].wh.Count;?n++)
{
if(dic.ContainsKey(mp.WMList[m].wh[n])?==false)
{
dic.Add(mp.WMList[m].wh[n],?m);
}
else{
removelist.Add(mp.WMList[m].wh[n]);
mp.WMList[dic[mp.WMList[m].wh[n]]].wh.Remove(mp.WMList[m].wh[n]);
}
}
for(intn?=0;?n?<?removelist.Count;?n++)
{
mp.WMList[m].wh.Remove(removelist[n]);
}
}
intw_1?=0;
intw_2?=0;
intw_3?=0;
intw_4?=0;
intw_5?=0;
intw_6?=0;
intw_7?=0;
for(intm?=0;?m?<?mp.WMList.Count;?m++)
{
if(mp.WMList[m].wh.Count?==0)?{
//獎勵詞
}
elseif(mp.WMList[m].wh.Count?==1){w_1++;}
elseif(mp.WMList[m].wh.Count?==2){w_2++;}
elseif(mp.WMList[m].wh.Count?==3){w_3++;}
elseif(mp.WMList[m].wh.Count?==4)?{?w_4++;?}
elseif(mp.WMList[m].wh.Count?==5)?{?w_5++;?}
elseif(mp.WMList[m].wh.Count?==6)?{?w_6++;?}
elseif(mp.WMList[m].wh.Count?==7)?{?w_7++;?}
else{
Debug.Log("不可能"+mp.WMList[m].wh.Count+"_"+er[i]);
}
}
sw.WriteLine(w_7?+"\t"+w_6?+"\t"+?w_5?+"\t"+?w_4?+"\t"+?w_3?+"\t"+?w_2?+"\t"+?w_1?+"\t"+?mp.jianglicichangdu);
}
sw.Flush();
sw.Close();
}
//地圖
stringProblemPath?="Json/problems/";
publicvoidsss3(stringcountry,stringfileName)
{
stringdata?=?(Resources.Load(answerPath?+?country?+"/"+?fileName)asTextAsset).text;
List?er?=?getJsonArray(data);
for(inti?=0;?i?<?er.Count;?i++)
{
//int?x_Start?=?10,x_end=0,int?y_start=10,y_end=0;
Dictionary?dicry?=newDictionary();
dicry.Clear();
GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);
for(intj?=0;?j?<?gl.wordsList.Count;?j++)
{
intwordlength?=?gl.wordsList[j].word.Length;
for(intm?=0;?m?<?wordlength;?m++)
{
Vector2temp?=newVector2();
if(gl.wordsList[j].d?==0||?gl.wordsList[j].d?==2)
{
temp.x?=?gl.wordsList[j].x?+?m;
temp.y?=?gl.wordsList[j].y;
}else{
temp.x?=?gl.wordsList[j].x?;
temp.y?=?gl.wordsList[j].y+m;
}
if(dicry.ContainsKey(temp)?==false)
{
dicry.Add(temp,0);
}
}
}
dealVec2dic(dicry,er[i],gl);
}
Debug.Log("over");
}
publicvoiddealVec2dic(Dictionary?dicry,stringtimu,GameLevelgls){
GameLevelgl?=?gls;
//File.Delete(Application.dataPath?+?"http://"?+?"FileNamesss"?+?".txt");
StreamWritersw;
FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");
if(!fi.Exists)
{
sw?=?fi.CreateText();
}
else
{
sw?=?fi.AppendText();
}
//邊界
intx_Start?=20,?x_end?=0;
inty_start?=20,?y_end?=0;
foreach(KeyValuePair?kvindicry){
if(kv.Key.x>x_end){
x_end?=(int)(kv.Key.x);
}
if(kv.Key.x?<?x_Start)
{
x_Start?=?(int)(kv.Key.x);
}
if(kv.Key.y?>?y_end)
{
y_end?=?(int)(kv.Key.y);
}
if(kv.Key.y?<?y_start)
{
y_start?=?(int)(kv.Key.y);
}
}
if(x_Start!=0||x_end+1!=gl.w||y_start!=0||y_end+1!=gl.h){
Debug.Log(timu+"_"+x_Start+"_"+x_end+"_"+y_start?+"_"+y_end);
gl.w?=?x_end?+1-x_Start;
gl.h?=?y_end?+1-y_start;
if(x_Start?!=0||?y_start?!=0)
{
for(intre?=0;?re?<?gl.wordsList.Count;?re++)
{
WordStructws?=newWordStruct();
ws.word?=?gl.wordsList[re].word;
ws.x=gl.wordsList[re].x-x_Start;
ws.y?=?gl.wordsList[re].y?-?y_start;
ws.d?=?gl.wordsList[re].d;
gl.wordsList[re]?=?ws;
}
}
//Debug.Log(timu);
sw.WriteLine("\""+DictionaryManager.Instance.GameLeveLToString(gl)+"\",");
}
//Debug.Log(timu);
List?w_list?=newList();
w_list.Clear();
for(inti?=1;?i?<?gl.w-1;?i++)
{
boolma?=false;
for(intj?=0;?j?<?gl.h;?j++)
{
Vector2v2?=newVector2();
v2.x?=?i;
v2.y?=?j;
if(dicry.ContainsKey(v2)?==true){
ma?=true;
break;
}
}
if(ma?==false&&?w_list.Count?>0&&?w_list[w_list.Count?-1]?==false){
Debug.Log(timu?+"_"+"w:"+?i);
}
w_list.Add(ma);
}
w_list.Clear();
for(inti?=1;?i?<?gl.h-1;?i++)
{
boolma?=false;
for(intj?=0;?j?<?gl.w;?j++)
{
Vector2v2?=newVector2();
v2.x?=?j;
v2.y?=?i;
if(dicry.ContainsKey(v2)?==true)
{
ma?=true;
break;
}
}
if(ma?==false&&?w_list.Count?>0&&?w_list[w_list.Count?-1]?==false)
{
Debug.Log(timu?+"_"+"w:"+?i);
}
w_list.Add(ma);
}
sw.Flush();
sw.Close();
}
}