📄 mergenewview.cpp
字号:
// refreshSig(::markall,1,1,fromLeft);
Allocate(_stackarray,MAX_ANT_NUM,HUMAN);
for(int i=0;i<MAX_ANT_NUM;i++)
{
for(j=0;j<_stackarray[i].GetLength();j++)
{
temp=_stackarray[i].stack[j];
::markall[temp.row][temp.col]++;
}
}
for(i=0;i<MAX_ANT_NUM;i++)
{
position=_stackarray[i].GetCurrentPosition();
if(position.row==EXIT_ROW&&position.col==EXIT_COL)
{
tag=i;
found=true;
}
x=found;
}
}
void CMergenewView::OnHumanSbys()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CRect rect(550,30,600,80);
char a[10];
a[0]=NULL;
CString text;
int i,j;
if(turn&&!found)
{
DrawMerge(&dc);
HumanStepByStep();
for(i=1;i<SIZEX_MAZE-1;i++)
{
for(j=1;j<SIZEY_MAZE-1;j++)
{
if(pos[i][j]==0)
continue;
text.Format("%d",pos[i][j]);
dc.TextOut(j*width,i*width,text);
}
//dc.TextOut(;
}
// resulttag=true;
}
else if(found==true)
{
text.Format("%d",::step);
dc.TextOut(400,200,text);
}
}
void CMergenewView::OnHumanGonow()
{
Restart();
CClientDC dc(this);
CRect rect(550,30,600,80);
char a[10];
a[0]=NULL;
CString text;
int j;
found=false;
int tag=0;
element position;
bool x;
element temp;
if(turn&&!found)
{
DrawMerge(&dc);
while(1)
{
// DisplayPath(&dc);
// refreshSig(::markall,1,1,fromLeft);
Allocate(_stackarray,MAX_ANT_NUM,HUMAN);
for(int i=0;i<MAX_ANT_NUM;i++)
{
for(j=0;j<_stackarray[i].GetLength();j++)
{
temp=_stackarray[i].stack[j];
::markall[temp.row][temp.col]++;
}
}
for(i=0;i<MAX_ANT_NUM;i++)
{
position=_stackarray[i].GetCurrentPosition();
if(position.row==EXIT_ROW&&position.col==EXIT_COL)
{
tag=i;
found=true;
}
x=found;
}
if(tag)
break;
if(found==true)
break;
}
}
if(found==true)
{
CString text;
text.Format("%d",::step);
dc.TextOut(400,200,text);
}
}
void CMergenewView::Restart ()
{
::step=0;
::found=false;
::first =true;
::totalEdge =0;
::totalLevel =0;
::treeHeight =0;
::imbalance =0;
::levelNum =0;
}
void CMergenewView::OnCompAntHuman()
{
// TODO: Add your command handler code here
int firstStep;
OnPerfectmaze();
OnDoubleresult();
firstStep=::step;
Restart();
CClientDC dc(this);
InitMark();
for(int i=0;i<MAX_ANT_NUM;i++)
_stackarray[i].StackEmpty();
InitView();
DrawMerge(&dc);
showtag=true;
turn=true;
doubleresult=false;
OnHumanGonow();
CString text;
text.Format("%d",firstStep);
dc.TextOut(400,200,text);
text.Format("%d",::step);
dc.TextOut(450,200,text);
}
void CMergenewView::OnMicrobeSbs()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
if(::first==true)
{
//initial the enviorment
//]MInitAll();
MInitMark();
for(int i=0;i<MAX_ANT_NUM;i++)
::_mStackarray[i].NewAntsCame ();
found=false;
first=false;
}
CClientDC dc(this);
CRect rect(550,30,600,80);
char a[10];
a[0]=NULL;
CString text;
int i,j;
if(turn&&!found)
{
DrawMerge(&dc);
MicrobeStepByStep();
for(i=1;i<SIZEX_MAZE-1;i++)
{
for(j=1;j<SIZEY_MAZE-1;j++)
{
if(pos[i][j]==0)
continue;
text.Format("%d",pos[i][j]);
dc.TextOut(j*width,i*width,text);
}
}
}
else if(found==true)
{
text.Format("%d",::step);
dc.TextOut(400,200,text);
}
}
void CMergenewView::MicrobeStepByStep ()
{
int i;
int tag;
bool x;
element position;
MAllocate(_mStackarray,MAX_ANT_NUM);
for(i=0;i<MAX_ANT_NUM;i++)
{
position=_mStackarray[i].GetCurrentPosition();
if(position.row==EXIT_ROW&&position.col==EXIT_COL)
{
tag=i;
break;
}
x=found;
}
}
void CMergenewView::OnMicrobeGonow()
{
// TODO: Add your command handler code here
int i;
MInitMark();
for(i=0;i<MAX_ANT_NUM;i++)
::_mStackarray[i].NewAntsCame ();
found=false;
first=false;
Restart();
CClientDC dc(this);
CRect rect(550,30,600,80);
char a[10];
a[0]=NULL;
CString text;
int tag=0;
element position;
bool x;
DrawMerge(&dc);
while(1)
{
// DisplayPath(&dc);
MAllocate(_mStackarray,MAX_ANT_NUM);
for(i=0;i<MAX_ANT_NUM;i++)
{
position=_mStackarray[i].GetCurrentPosition();
if(position.row==EXIT_ROW&&position.col==EXIT_COL)
{
tag=i;
break;
}
x=::found;
}
if(tag)
break;
if(::found==true)
break;
}
if(found==true)
{
CString text;
text.Format("%d",::step);
dc.TextOut(400,400,text);
}
}
void CMergenewView::reInitWithoutMaze ()
{
Restart();
InitMark();
for(int i=0;i<MAX_ANT_NUM;i++)
_stackarray[i].StackEmpty();
InitView();
showtag=true;
turn=true;
doubleresult=false;
}
void CMergenewView::OnCompMicroAnt()
{
// TODO: Add your command handler code here
int firstStep;
CClientDC dc(this);
OnPerfectmaze();
OnMicrobeGonow();
firstStep=::step;
reInitWithoutMaze();
DrawMerge(&dc);
OnDoubleresult();
CString text;
text.Format("%d",firstStep);
dc.TextOut(400,200,text);
text.Format("%d",::step);
dc.TextOut(450,200,text);
}
void CMergenewView::OnCompMicroHuman()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
int firstStep;
OnPerfectmaze();
OnMicrobeGonow();
firstStep=::step;
CClientDC dc(this);
reInitWithoutMaze();
DrawMerge(&dc);
OnHumanGonow();
CString text;
text.Format("%d",firstStep);
dc.TextOut(400,200,text);
text.Format("%d",::step);
dc.TextOut(450,200,text);
}
void CMergenewView::OnRcompMicroAnt()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
int firstStep;
OnNewgame();
OnMicrobeGonow();
firstStep=::step;
CClientDC dc(this);
reInitWithoutMaze();
DrawMerge(&dc);
OnDoubleresult();
CString text;
text.Format("%d",firstStep);
dc.TextOut(400,200,text);
text.Format("%d",::step);
dc.TextOut(450,200,text);
}
void CMergenewView::OnCompAll()
{
// TODO: Add your command handler code here
int firstStep;
int secondStep;
OnPerfectmaze();
OnMicrobeGonow();
firstStep=::step;
CClientDC dc(this);
DrawMerge(&dc);
reInitWithoutMaze();
OnDoubleresult();
secondStep=::step;
reInitWithoutMaze();
DrawMerge(&dc);
OnHumanGonow();
CString text;
text.Format("%d",firstStep);
dc.TextOut(400,200,text);
text.Format("%d",secondStep);
dc.TextOut(450,200,text);
text.Format("%d",::step);
dc.TextOut(500,200,text);
}
void CMergenewView::OnStatistic()
{
// TODO: Add your command handler code here
fstream microbe("d:\\maze\\result\\microbe.txt",ios::in|ios::out|ios::trunc);
fstream ant("d:\\maze\\result\\ant.txt",ios::in|ios::out|ios::trunc);
fstream human("d:\\maze\\result\\human.txt",ios::in|ios::out|ios::trunc);
fstream single("d:\\maze\\result\\single.txt",ios::in|ios::out|ios::trunc);
fstream withoutcoop("d:\\maze\\result\\withoutcoop.txt",ios::in|ios::out|ios::trunc);
fstream mazeShape("d:\\maze\\result\\maze.txt",ios::in|ios::out|ios::trunc);
fstream balance("d:\\maze\\result\\balance.txt",ios::in|ios::out|ios::trunc);
fstream level("d:\\maze\\result\\level.txt",ios::in|ios::out|ios::trunc);
fstream edge("d:\\maze\\result\\edge.txt",ios::in|ios::out|ios::trunc);
fstream height("d:\\maze\\result\\height.txt",ios::in|ios::out|ios::trunc);
fstream leaveNum("d:\\maze\\result\\leaveNum.txt",ios::in|ios::out|ios::trunc);
int generated[20]={-1};
int k;
for(::row=10;::row<=50;::row+=10)
{
::SIZEX_MAZE =2*::row+1;
::EXIT_ROW=::SIZEX_MAZE-2;
for(::col=10;::col<=50;::col+=10)
{
::SIZEY_MAZE =2*::col+1;
::EXIT_COL=::SIZEY_MAZE-2;
for(::MAX_ANT_NUM =5;::MAX_ANT_NUM <=25;::MAX_ANT_NUM +=10)
{
microbe<<"Row: "<<::row<<" ";
ant<<"Row: "<<::row<<" ";
human<<"Row: "<<::row<<" ";
single<<"Row: "<<::row<<" ";
withoutcoop<<"Row: "<<::row<<" ";
mazeShape<<"Row: "<<::row<<" ";
balance<<"Row: "<<::row<<" ";
level<<"Row: "<<::row<<" ";
edge<<"Row: "<<::row<<" ";
height<<"Row: "<<::row<<" ";
leaveNum<<"Row: "<<::row<<" ";
microbe<<"Col: "<<::col<<" ";
ant<<"Col: "<<::col<<" ";
human<<"Col: "<<::col<<" ";
single<<"Col: "<<::col<<" ";
withoutcoop<<"Col: "<<::col<<" ";
mazeShape<<"Col: "<<::col<<" ";
balance<<"Col: "<<::col<<" ";
level<<"Col: "<<::col<<" ";
edge<<"Col: "<<::col<<" ";
height<<"Col: "<<::col<<" ";
leaveNum<<"Col: "<<::col<<" ";
microbe<<"Ant num: "<<::MAX_ANT_NUM <<endl;
ant<<"Ant num: "<<::MAX_ANT_NUM <<endl;
human<<"Ant num: "<<::MAX_ANT_NUM <<endl;
single<<"Ant num: "<<::MAX_ANT_NUM <<endl;
withoutcoop<<"Ant num: "<<::MAX_ANT_NUM <<endl;
mazeShape<<"Ant num: "<<::MAX_ANT_NUM <<endl;
balance<<"Ant num: "<<::MAX_ANT_NUM <<endl;
level<<"Ant num: "<<::MAX_ANT_NUM <<endl;
edge<<"Ant num: "<<::MAX_ANT_NUM <<endl;
height<<"Ant num: "<<::MAX_ANT_NUM <<endl;
leaveNum<<"Ant num: "<<::MAX_ANT_NUM <<endl;
for(int time=0;time<20;time++)
{
OnPerfectmaze();
OnMicrobeGonow();
for(k=0;k<20;k++)
if(::step!=generated[k])
break;
if(k==20)
continue;
generated[time]=::step;
microbe<<::step<<endl;
int temp=0;
mazeAnaly(::maze,1,1,1,0,1,temp);
balance<<::imbalance <<endl;
height<<::treeHeight <<endl;
level<<::totalLevel <<endl;
edge<<::totalEdge <<endl;
leaveNum<<::levelNum <<endl;
mazeShape<<endl;
int i=0,j=0;
for(i=0;i<SIZEX_MAZE;i++)
{
for(j=0;j<SIZEY_MAZE;j++)
mazeShape<<::maze[i][j];
mazeShape<<endl;
}
reInitWithoutMaze();
OnDoubleresult();
ant<<::step<<endl;
reInitWithoutMaze();
OnHumanGonow();
human<<::step <<endl;
reInitWithoutMaze();
::step=OnSingle();
single<<::step <<endl;
reInitWithoutMaze();
::step=OnWithoutcoop();
withoutcoop<<::step <<endl;
}
}
}
}
}
int CMergenewView::OnSingle()
{
int tempAntNum=::MAX_ANT_NUM ;
::MAX_ANT_NUM =1;
int temp=OnWithoutcoop();
::MAX_ANT_NUM =tempAntNum;
return temp;
}
int CMergenewView::OnWithoutcoop()
{
// TODO: Add your command handler code here
int i;
int tag=0;
element position;
bool x;
int withoutCoop=0;
CClientDC dc(this);
found=false;
while(1)
{
withoutCoop++;
for(i=0;i<MAX_ANT_NUM;i++)
{
_stackarray[i].SearchPathStepByStepRandom();
position=_stackarray[i].GetCurrentPosition();
if(position.row==EXIT_ROW&&position.col==EXIT_COL)
{
tag=i;
break;
}
x=found;
}
DisplayPath(&dc);
if(tag)
break;
if(found==true)
break;
}
CString text;
text.Format("%d",withoutCoop);
dc.TextOut(400,300,text);
return withoutCoop;
}
void CMergenewView::OnWithsingle()
{
// TODO: Add your command handler code here
int firstStep;
int secondStep;
int thirdStep;
int fourthStep;
int fifthStep;
OnPerfectmaze();
OnMicrobeGonow();
firstStep=::step;
CClientDC dc(this);
reInitWithoutMaze();
OnDoubleresult();
secondStep=::step;
reInitWithoutMaze();
OnHumanGonow();
thirdStep=::step ;
reInitWithoutMaze();
fourthStep=OnSingle();
reInitWithoutMaze();
fifthStep=OnWithoutcoop();
CString text;
text.Format("%d",firstStep);
dc.TextOut(200,200,text);
text.Format("%d",secondStep);
dc.TextOut(250,200,text);
text.Format("%d",thirdStep);
dc.TextOut(300,200,text);
text.Format("%d",fourthStep);
dc.TextOut(350,200,text);
text.Format("%d",fifthStep);
dc.TextOut(400,200,text);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -