一次写通的代码

ある日、boss给了一个很独特的想法,让我实现,我知道要做什么东西出来,却很没底,因为感觉很容易写错,然后,我还在紧张的条件说想一下就能写出来,然后,写完之后直接跑出正确的结果了,很开心,很开心

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;//交叉点个数

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/";

//统计交叉点和地图

publicvoidsss() {

File.Delete(Application.dataPath +"//"+"FileNamesss"+".txt");

StreamWritersw;

FileInfofi =newFileInfo(Application.dataPath +"//"+"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 +"//"+"FileNamesss"+".txt");

StreamWritersw;

FileInfofi =newFileInfo(Application.dataPath +"//"+"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 + "//" + "FileNamesss" + ".txt");

StreamWritersw;

FileInfofi =newFileInfo(Application.dataPath +"//"+"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();

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,427评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,551评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,747评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,939评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,955评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,737评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,448评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,352评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,834评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,992评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,133评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,815评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,477评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,022评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,147评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,398评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,077评论 2 355

推荐阅读更多精彩内容

  • thiele插值算法 1点插值算法 function [C,c]=thiele(X,Y,Z)%X为插值点横坐标,Y...
    00crazy00阅读 1,990评论 0 4
  • 星期天,老杨一个人背着手在小区里溜达,现在正是一年中最好的时光,春光烂漫。 小区花坛里,各种花正在次第开放。老杨用...
    阿尔他霞阅读 1,267评论 17 18
  • 1.对我们来说,投资等于出去赌马。我们要寻找一匹获胜几率是两分之一、赔率是一赔三的马。你要寻找的是标错赔率的赌局。...
    别样的人生阅读 279评论 0 1
  • 文/驭风者 天上十个太阳喷涌而出的岩浆 融化不了厚厚的城墙 地下十个太阳发出来的光 照不进月亮的边疆 十个太阳在天...
    驭风者hou阅读 2,199评论 11 14