mergenewView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:24k
- // mergenewView.cpp : implementation of the CMergenewView class
- //
- // Copyright: 胡小民,丁展 2002.5
- #include "stdafx.h"
- #include "mergenew.h"
- #include "fstream.h"
- #include "mergenewDoc.h"
- #include "mergenewView.h"
- #include "maze.h"
- #include "mazeMake.h"
- #include "HumansWay.h"
- #include "microbeWay.h"
- #include "mazeAnaly.h"
- #include "head.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- Stack _stackarray[CONST_ANT_NUM];
- MStack _mStackarray[CONST_ANT_NUM];
- bool first=true;
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView
- IMPLEMENT_DYNCREATE(CMergenewView, CView)
- BEGIN_MESSAGE_MAP(CMergenewView, CView)
- //{{AFX_MSG_MAP(CMergenewView)
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_NEWGAME, OnNewgame)
- ON_COMMAND(ID_RESULT, OnResult)
- ON_COMMAND(ID_DOUBLERESULT, OnDoubleresult)
- ON_COMMAND(ID_PERFECTMAZE, OnPerfectmaze)
- ON_COMMAND(ID_HUMAN_SBYS, OnHumanSbys)
- ON_COMMAND(ID_HUMAN_GONOW, OnHumanGonow)
- ON_COMMAND(ID_COMP_ANT_HUMAN, OnCompAntHuman)
- ON_COMMAND(ID_MICROBE_SBS, OnMicrobeSbs)
- ON_COMMAND(ID_MICROBE_GONOW, OnMicrobeGonow)
- ON_COMMAND(ID_COMP_MICRO_ANT, OnCompMicroAnt)
- ON_COMMAND(ID_COMP_MICRO_HUMAN, OnCompMicroHuman)
- ON_COMMAND(ID_RCOMP_MICRO_ANT, OnRcompMicroAnt)
- ON_COMMAND(ID_COMP_ALL, OnCompAll)
- ON_COMMAND(ID_STATISTIC, OnStatistic)
- ON_COMMAND(ID_SINGLE, OnSingle)
- ON_COMMAND(ID_WITHOUTCOOP, OnWithoutcoop)
- ON_COMMAND(ID_WITHSINGLE, OnWithsingle)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView construction/destruction
- CMergenewView::CMergenewView()
- {
- // TODO: add construction code here
- width=300/::row;
- point.x=1;
- point.y=1;
- showtag=false;
- resulttag=false;
- turn=false;
- doubleresult=false;
- }
- CMergenewView::~CMergenewView()
- {
- }
- BOOL CMergenewView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView drawing
- void CMergenewView::OnDraw(CDC* pDC)
- {
- CMergenewDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(showtag)
- {
- DrawMerge(pDC);
- }
- if(resulttag&&turn)
- {
- DrawMerge(pDC);
- DrawResult(pDC);
- }
- if(doubleresult)
- {
- DrawMerge(pDC);
- // DrawDoubleResult(pDC);
- }
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView printing
- BOOL CMergenewView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMergenewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMergenewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView diagnostics
- #ifdef _DEBUG
- void CMergenewView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMergenewView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMergenewDoc* CMergenewView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMergenewDoc)));
- return (CMergenewDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMergenewView message handlers
- void CMergenewView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- switch(nChar)
- {
- case VK_DOWN:
- {
- if(point.x+1<SIZEX_MAZE-1)
- if(!maze[point.x+1][point.y])
- {
- DrawColorBlocks(&dc,point);
- point.x++;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- case VK_LEFT:
- {
- if(point.y-1>0)
- if(!maze[point.x][point.y-1])
- {
- DrawColorBlocks(&dc,point);
- point.y--;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- case VK_RIGHT:
- {
- if(point.y+1<SIZEY_MAZE-1)
- if(!maze[point.x][point.y+1])
- {
- DrawColorBlocks(&dc,point);
- point.y++;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- case VK_UP:
- {
- if(point.x-1>0)
- if(!maze[point.x-1][point.y])
- {
- DrawColorBlocks(&dc,point);
- point.x--;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- //case VK_DOWNLEFT:
- case VK_DELETE:
- {
- if(point.x+1<SIZEX_MAZE-1&&point.y-1>0)
- if(!maze[point.x+1][point.y-1])
- {
- DrawColorBlocks(&dc,point);
- point.x++;
- point.y--;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- //case VK_DOWNRIGHT:
- case VK_END:
- {
- if(point.x+1<SIZEX_MAZE-1&&point.y+1<SIZEY_MAZE-1)
- if(!maze[point.x+1][point.y+1])
- {
- DrawColorBlocks(&dc,point);
- point.x++;
- point.y++;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- //case VK_UPLEFT:
- case VK_INSERT:
- {
- if(point.x-1>0&&point.y-1>0)
- if(!maze[point.x-1][point.y-1])
- {
- DrawColorBlocks(&dc,point);
- point.x--;
- point.y--;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- //case VK_UPRIGHT:
- case VK_HOME:
- {
- if(point.x-1>0&&point.y+1<SIZEY_MAZE-1)
- if(!maze[point.x-1][point.y+1])
- {
- DrawColorBlocks(&dc,point);
- point.x--;
- point.y++;
- DrawColorBlocks(&dc,point,125,125,125);
- }
- break;
- }
- default:
- break;
- }
-
- if(point.x==EXIT_ROW&&point.y==EXIT_COL)
- {
- showtag=false;
- resulttag=false;
- turn=false;
- point.x=1;
- point.y=1;
- MessageBox("you are wonderful");
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CMergenewView::DrawColorBlocks(CDC * pDC,CPoint point)
- {
- CBrush backbrush,*oldbrush;
- CRect rect;
- rect.top=width*point.x;
- rect.bottom=width*(point.x+1);
- rect.left=width*point.y;
- rect.right=width*(point.y+1);
- backbrush.CreateSolidBrush(RGB(255,133,0));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawColorBlocks(CDC * pDC,CPoint point,int r,int g,int b)
- {
- CBrush backbrush,*oldbrush;
- CRect rect;
- rect.top=width*point.x;
- rect.bottom=width*(point.x+1);
- rect.left=width*point.y;
- rect.right=width*(point.y+1);
- backbrush.CreateSolidBrush(RGB(r,g,b));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawWhiteBlocks(CDC * pDC,CPoint point)
- {
- CBrush backbrush,*oldbrush;
- CRect rect;
- rect.top=width*point.x;
- rect.bottom=width*(point.x+1);
- rect.left=width*point.y;
- rect.right=width*(point.y+1);
- backbrush.CreateSolidBrush(RGB(0,255,255));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawWhiteBlocks(CDC * pDC,CRect& rect)
- {
- CBrush backbrush,*oldbrush;
- backbrush.CreateSolidBrush(RGB(0,255,255));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawPathBlocks(CDC * pDC,CPoint point)
- {
- CBrush backbrush,*oldbrush;
- CRect rect;
- rect.top=width*point.x;
- rect.bottom=width*(point.x+1);
- rect.left=width*point.y;
- rect.right=width*(point.y+1);
- backbrush.CreateSolidBrush(RGB(100,100,100));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawPathBlocks(CDC * pDC,CRect& rect)
- {
- CBrush backbrush,*oldbrush;
- backbrush.CreateSolidBrush(RGB(100,100,100));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawColorBlocks(CDC * pDC,CRect &rect)
- {
- CBrush brush,*oldbrush;
- brush.CreateSolidBrush(RGB(255,123,0));
- oldbrush=pDC->SelectObject(&brush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawColorBlocks(CDC * pDC,CRect &rect,int r,int g,int b)
- {
- CBrush brush,*oldbrush;
- brush.CreateSolidBrush(RGB(r,g,b));
- oldbrush=pDC->SelectObject(&brush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CMergenewView::DrawMerge(CDC * pDC)
- {
- CBrush brush;
- CRect rect;
- int i=0,j=0;
- for(i=0;i<SIZEX_MAZE;i++)
- {
- rect.top=width*i;
- rect.bottom=width*(i+1);
- for(j=0;j<SIZEY_MAZE;j++)
- {
- rect.left=width*j;
- rect.right=width*(j+1);
- if(!maze[i][j])
- {
- DrawColorBlocks(pDC,rect);
- }
- else
- {
- DrawWhiteBlocks(pDC,rect);
- }
- }
- }
- }
- void CMergenewView::DisplayPath (CDC *pDC)
- {
- CBrush brush;
- CRect rect;
- int i=0,j=0;
- for(i=0;i<SIZEX_MAZE;i++)
- {
- rect.top=width*i;
- rect.bottom=width*(i+1);
- for(j=0;j<SIZEY_MAZE;j++)
- {
- rect.left=width*j;
- rect.right=width*(j+1);
- if(::pos[i][j] && !::maze[i][j])
- {
- DrawPathBlocks(pDC,rect);
- }
- }
- }
- }
- void CMergenewView::DrawResult(CDC * pDC)
- {
- }
- void CMergenewView::DrawDoubleResult(CDC * pDC)
- {
- }
- void CMergenewView::OnNewgame()
- {
- int i;
- Restart();
- // TODO: Add your command handler code here
- CClientDC dc(this);
- MInitMark();
- for(i=0;i<MAX_ANT_NUM;i++)
- _mStackarray[i].MStackEmpty();
- InitAll();
- for(i=0;i<MAX_ANT_NUM;i++)
- _stackarray[i].StackEmpty();
- InitView();
- DrawMerge(&dc);
- showtag=true;
- turn=true;
- // resulttag=false;
- doubleresult=false;
- }
- void CMergenewView::OnResult()
- {
- // 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);
- StepByStep();
- 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::InitView()
- {
- InitMark();
- for(int i=0;i<MAX_ANT_NUM;i++)
- _stackarray[i].NewAntsCame ();
- }
- void CMergenewView::StepByStep()
- {
-
- found=false;
- int tag=0;
- element position;
- bool x;
- element temp;
- int j;
- Allocate(_stackarray,MAX_ANT_NUM,ANT);
- 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::OnDoubleresult()
- {
- 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);
-
- Allocate(_stackarray,MAX_ANT_NUM,ANT);
- 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::OnPerfectmaze()
- {
- Restart();
- CClientDC dc(this);
- int i;
- MInitMark();
- for(i=0;i<MAX_ANT_NUM;i++)
- _mStackarray[i].MStackEmpty();
- InitAll();
- for(i=0;i<SIZEX_MAZE;i++)
- for(int j=0;j<SIZEY_MAZE;j++)
- maze[i][j]=1;
-
- pMazeMaker(::maze);
- for(i=0;i<MAX_ANT_NUM;i++)
- _stackarray[i].StackEmpty();
- InitView();
- // DrawMerge(&dc);
- showtag=true;
- turn=true;
- doubleresult=false;
-
- }
- void CMergenewView::HumanStepByStep ()
- {
- found=false;
- int tag=0;
- element position;
- bool x;
- element temp;
- int j;
-
- // 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);
- }