mergenewView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:24k
源码类别:

游戏

开发平台:

Visual C++

  1. // mergenewView.cpp : implementation of the CMergenewView class
  2. //
  3. // Copyright: 胡小民,丁展 2002.5
  4. #include "stdafx.h"
  5. #include "mergenew.h"
  6. #include "fstream.h"
  7. #include "mergenewDoc.h"
  8. #include "mergenewView.h"
  9. #include "maze.h"
  10. #include "mazeMake.h"
  11. #include "HumansWay.h"
  12. #include "microbeWay.h"
  13. #include "mazeAnaly.h"
  14. #include "head.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. Stack _stackarray[CONST_ANT_NUM];
  21. MStack _mStackarray[CONST_ANT_NUM];
  22. bool first=true;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMergenewView
  25. IMPLEMENT_DYNCREATE(CMergenewView, CView)
  26. BEGIN_MESSAGE_MAP(CMergenewView, CView)
  27. //{{AFX_MSG_MAP(CMergenewView)
  28. ON_WM_KEYDOWN()
  29. ON_COMMAND(ID_NEWGAME, OnNewgame)
  30. ON_COMMAND(ID_RESULT, OnResult)
  31. ON_COMMAND(ID_DOUBLERESULT, OnDoubleresult)
  32. ON_COMMAND(ID_PERFECTMAZE, OnPerfectmaze)
  33. ON_COMMAND(ID_HUMAN_SBYS, OnHumanSbys)
  34. ON_COMMAND(ID_HUMAN_GONOW, OnHumanGonow)
  35. ON_COMMAND(ID_COMP_ANT_HUMAN, OnCompAntHuman)
  36. ON_COMMAND(ID_MICROBE_SBS, OnMicrobeSbs)
  37. ON_COMMAND(ID_MICROBE_GONOW, OnMicrobeGonow)
  38. ON_COMMAND(ID_COMP_MICRO_ANT, OnCompMicroAnt)
  39. ON_COMMAND(ID_COMP_MICRO_HUMAN, OnCompMicroHuman)
  40. ON_COMMAND(ID_RCOMP_MICRO_ANT, OnRcompMicroAnt)
  41. ON_COMMAND(ID_COMP_ALL, OnCompAll)
  42. ON_COMMAND(ID_STATISTIC, OnStatistic)
  43. ON_COMMAND(ID_SINGLE, OnSingle)
  44. ON_COMMAND(ID_WITHOUTCOOP, OnWithoutcoop)
  45. ON_COMMAND(ID_WITHSINGLE, OnWithsingle)
  46. //}}AFX_MSG_MAP
  47. // Standard printing commands
  48. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  49. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  50. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMergenewView construction/destruction
  54. CMergenewView::CMergenewView()
  55. {
  56. // TODO: add construction code here
  57. width=300/::row;
  58. point.x=1;
  59. point.y=1;
  60. showtag=false;
  61. resulttag=false;
  62. turn=false;
  63. doubleresult=false;
  64. }
  65. CMergenewView::~CMergenewView()
  66. {
  67. }
  68. BOOL CMergenewView::PreCreateWindow(CREATESTRUCT& cs)
  69. {
  70. // TODO: Modify the Window class or styles here by modifying
  71. //  the CREATESTRUCT cs
  72. return CView::PreCreateWindow(cs);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CMergenewView drawing
  76. void CMergenewView::OnDraw(CDC* pDC)
  77. {
  78. CMergenewDoc* pDoc = GetDocument();
  79. ASSERT_VALID(pDoc);
  80. if(showtag)
  81. {
  82. DrawMerge(pDC);
  83. }
  84. if(resulttag&&turn)
  85. {
  86. DrawMerge(pDC);
  87. DrawResult(pDC);
  88. }
  89. if(doubleresult)
  90. {
  91. DrawMerge(pDC);
  92. // DrawDoubleResult(pDC);
  93. }
  94. // TODO: add draw code for native data here
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CMergenewView printing
  98. BOOL CMergenewView::OnPreparePrinting(CPrintInfo* pInfo)
  99. {
  100. // default preparation
  101. return DoPreparePrinting(pInfo);
  102. }
  103. void CMergenewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  104. {
  105. // TODO: add extra initialization before printing
  106. }
  107. void CMergenewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  108. {
  109. // TODO: add cleanup after printing
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMergenewView diagnostics
  113. #ifdef _DEBUG
  114. void CMergenewView::AssertValid() const
  115. {
  116. CView::AssertValid();
  117. }
  118. void CMergenewView::Dump(CDumpContext& dc) const
  119. {
  120. CView::Dump(dc);
  121. }
  122. CMergenewDoc* CMergenewView::GetDocument() // non-debug version is inline
  123. {
  124. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMergenewDoc)));
  125. return (CMergenewDoc*)m_pDocument;
  126. }
  127. #endif //_DEBUG
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CMergenewView message handlers
  130. void CMergenewView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  131. {
  132. // TODO: Add your message handler code here and/or call default
  133. CClientDC dc(this);
  134. switch(nChar)
  135. {
  136. case VK_DOWN:
  137. {
  138. if(point.x+1<SIZEX_MAZE-1)
  139. if(!maze[point.x+1][point.y])
  140. {
  141. DrawColorBlocks(&dc,point);
  142. point.x++;
  143. DrawColorBlocks(&dc,point,125,125,125);
  144. }
  145. break;
  146. }
  147. case VK_LEFT:
  148. {
  149. if(point.y-1>0)
  150. if(!maze[point.x][point.y-1])
  151. {
  152. DrawColorBlocks(&dc,point);
  153. point.y--;
  154. DrawColorBlocks(&dc,point,125,125,125);
  155. }
  156. break;
  157. }
  158. case VK_RIGHT:
  159. {
  160. if(point.y+1<SIZEY_MAZE-1)
  161. if(!maze[point.x][point.y+1])
  162. {
  163. DrawColorBlocks(&dc,point);
  164. point.y++;
  165. DrawColorBlocks(&dc,point,125,125,125);
  166. }
  167. break;
  168. }
  169. case VK_UP:
  170. {
  171. if(point.x-1>0)
  172. if(!maze[point.x-1][point.y])
  173. {
  174. DrawColorBlocks(&dc,point);
  175. point.x--;
  176. DrawColorBlocks(&dc,point,125,125,125);
  177. }
  178. break;
  179. }
  180. //case VK_DOWNLEFT:
  181. case VK_DELETE:
  182. {
  183. if(point.x+1<SIZEX_MAZE-1&&point.y-1>0)
  184. if(!maze[point.x+1][point.y-1])
  185. {
  186. DrawColorBlocks(&dc,point);
  187. point.x++;
  188. point.y--;
  189. DrawColorBlocks(&dc,point,125,125,125);
  190. }
  191. break;
  192. }
  193. //case VK_DOWNRIGHT:
  194. case VK_END:
  195. {
  196. if(point.x+1<SIZEX_MAZE-1&&point.y+1<SIZEY_MAZE-1)
  197. if(!maze[point.x+1][point.y+1])
  198. {
  199. DrawColorBlocks(&dc,point);
  200. point.x++;
  201. point.y++;
  202. DrawColorBlocks(&dc,point,125,125,125);
  203. }
  204. break;
  205. }
  206. //case VK_UPLEFT:
  207. case VK_INSERT:
  208. {
  209. if(point.x-1>0&&point.y-1>0)
  210. if(!maze[point.x-1][point.y-1])
  211. {
  212. DrawColorBlocks(&dc,point);
  213. point.x--;
  214. point.y--;
  215. DrawColorBlocks(&dc,point,125,125,125);
  216. }
  217. break;
  218. }
  219. //case VK_UPRIGHT:
  220. case VK_HOME:
  221. {
  222. if(point.x-1>0&&point.y+1<SIZEY_MAZE-1)
  223. if(!maze[point.x-1][point.y+1])
  224. {
  225. DrawColorBlocks(&dc,point);
  226. point.x--;
  227. point.y++;
  228. DrawColorBlocks(&dc,point,125,125,125);
  229. }
  230. break;
  231. }
  232. default:
  233. break;
  234. }
  235. if(point.x==EXIT_ROW&&point.y==EXIT_COL)
  236. {
  237. showtag=false;
  238. resulttag=false;
  239. turn=false;
  240. point.x=1;
  241. point.y=1;
  242. MessageBox("you are wonderful");
  243. }
  244. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  245. }
  246. void CMergenewView::DrawColorBlocks(CDC * pDC,CPoint point)
  247. {
  248. CBrush backbrush,*oldbrush;
  249. CRect rect;
  250. rect.top=width*point.x;
  251. rect.bottom=width*(point.x+1);
  252. rect.left=width*point.y;
  253. rect.right=width*(point.y+1);
  254. backbrush.CreateSolidBrush(RGB(255,133,0));
  255. oldbrush=pDC->SelectObject(&backbrush);
  256. pDC->Rectangle(rect);
  257. pDC->SelectObject(oldbrush);
  258. }
  259. void CMergenewView::DrawColorBlocks(CDC * pDC,CPoint point,int r,int g,int b)
  260. {
  261. CBrush backbrush,*oldbrush;
  262. CRect rect;
  263. rect.top=width*point.x;
  264. rect.bottom=width*(point.x+1);
  265. rect.left=width*point.y;
  266. rect.right=width*(point.y+1);
  267. backbrush.CreateSolidBrush(RGB(r,g,b));
  268. oldbrush=pDC->SelectObject(&backbrush);
  269. pDC->Rectangle(rect);
  270. pDC->SelectObject(oldbrush);
  271. }
  272. void CMergenewView::DrawWhiteBlocks(CDC * pDC,CPoint point)
  273. {
  274. CBrush backbrush,*oldbrush;
  275. CRect rect;
  276. rect.top=width*point.x;
  277. rect.bottom=width*(point.x+1);
  278. rect.left=width*point.y;
  279. rect.right=width*(point.y+1);
  280. backbrush.CreateSolidBrush(RGB(0,255,255));
  281. oldbrush=pDC->SelectObject(&backbrush);
  282. pDC->Rectangle(rect);
  283. pDC->SelectObject(oldbrush);
  284. }
  285. void CMergenewView::DrawWhiteBlocks(CDC * pDC,CRect& rect)
  286. {
  287. CBrush backbrush,*oldbrush;
  288. backbrush.CreateSolidBrush(RGB(0,255,255));
  289. oldbrush=pDC->SelectObject(&backbrush);
  290. pDC->Rectangle(rect);
  291. pDC->SelectObject(oldbrush);
  292. }
  293. void CMergenewView::DrawPathBlocks(CDC * pDC,CPoint point)
  294. {
  295. CBrush backbrush,*oldbrush;
  296. CRect rect;
  297. rect.top=width*point.x;
  298. rect.bottom=width*(point.x+1);
  299. rect.left=width*point.y;
  300. rect.right=width*(point.y+1);
  301. backbrush.CreateSolidBrush(RGB(100,100,100));
  302. oldbrush=pDC->SelectObject(&backbrush);
  303. pDC->Rectangle(rect);
  304. pDC->SelectObject(oldbrush);
  305. }
  306. void CMergenewView::DrawPathBlocks(CDC * pDC,CRect& rect)
  307. {
  308. CBrush backbrush,*oldbrush;
  309. backbrush.CreateSolidBrush(RGB(100,100,100));
  310. oldbrush=pDC->SelectObject(&backbrush);
  311. pDC->Rectangle(rect);
  312. pDC->SelectObject(oldbrush);
  313. }
  314. void CMergenewView::DrawColorBlocks(CDC * pDC,CRect &rect)
  315. {
  316. CBrush brush,*oldbrush;
  317. brush.CreateSolidBrush(RGB(255,123,0));
  318. oldbrush=pDC->SelectObject(&brush);
  319. pDC->Rectangle(rect);
  320. pDC->SelectObject(oldbrush);
  321. }
  322. void CMergenewView::DrawColorBlocks(CDC * pDC,CRect &rect,int r,int g,int b)
  323. {
  324. CBrush brush,*oldbrush;
  325. brush.CreateSolidBrush(RGB(r,g,b));
  326. oldbrush=pDC->SelectObject(&brush);
  327. pDC->Rectangle(rect);
  328. pDC->SelectObject(oldbrush);
  329. }
  330. void CMergenewView::DrawMerge(CDC * pDC)
  331. {
  332. CBrush brush;
  333. CRect rect;
  334. int i=0,j=0;
  335. for(i=0;i<SIZEX_MAZE;i++)
  336. {
  337. rect.top=width*i;
  338. rect.bottom=width*(i+1);
  339. for(j=0;j<SIZEY_MAZE;j++)
  340. {
  341. rect.left=width*j;
  342. rect.right=width*(j+1);
  343. if(!maze[i][j])
  344. {
  345. DrawColorBlocks(pDC,rect);
  346. }
  347. else
  348. {
  349. DrawWhiteBlocks(pDC,rect);
  350. }
  351. }
  352. }
  353. }
  354. void CMergenewView::DisplayPath (CDC *pDC)
  355. {
  356. CBrush brush;
  357. CRect rect;
  358. int i=0,j=0;
  359. for(i=0;i<SIZEX_MAZE;i++)
  360. {
  361. rect.top=width*i;
  362. rect.bottom=width*(i+1);
  363. for(j=0;j<SIZEY_MAZE;j++)
  364. {
  365. rect.left=width*j;
  366. rect.right=width*(j+1);
  367. if(::pos[i][j] && !::maze[i][j])
  368. {
  369. DrawPathBlocks(pDC,rect);
  370. }
  371. }
  372. }
  373. }
  374. void CMergenewView::DrawResult(CDC * pDC)
  375. {
  376. }
  377. void CMergenewView::DrawDoubleResult(CDC * pDC)
  378. {
  379. }
  380. void CMergenewView::OnNewgame() 
  381. {
  382. int i;
  383. Restart();
  384. // TODO: Add your command handler code here
  385. CClientDC dc(this);
  386. MInitMark();
  387. for(i=0;i<MAX_ANT_NUM;i++)
  388. _mStackarray[i].MStackEmpty();
  389. InitAll();
  390. for(i=0;i<MAX_ANT_NUM;i++)
  391. _stackarray[i].StackEmpty();
  392. InitView();
  393. DrawMerge(&dc);
  394. showtag=true;
  395. turn=true;
  396. // resulttag=false;
  397. doubleresult=false;
  398. }
  399. void CMergenewView::OnResult() 
  400. {
  401. // TODO: Add your command handler code here
  402. CClientDC dc(this);
  403. CRect rect(550,30,600,80);
  404. char a[10];
  405. a[0]=NULL;
  406. CString text;
  407. int i,j;
  408. if(turn&&!found)
  409. {
  410. DrawMerge(&dc);
  411. StepByStep();
  412. for(i=1;i<SIZEX_MAZE-1;i++)
  413. {
  414. for(j=1;j<SIZEY_MAZE-1;j++)
  415. {
  416. if(pos[i][j]==0)
  417. continue;
  418. text.Format("%d",pos[i][j]);
  419. dc.TextOut(j*width,i*width,text);
  420. }
  421. //dc.TextOut(;
  422. }
  423. // resulttag=true;
  424. }
  425. else if(found==true)
  426. {
  427. text.Format("%d",::step);
  428. dc.TextOut(400,200,text);
  429. }
  430. }
  431. void CMergenewView::InitView()
  432. {
  433. InitMark();
  434. for(int i=0;i<MAX_ANT_NUM;i++)
  435. _stackarray[i].NewAntsCame ();
  436. }
  437. void CMergenewView::StepByStep()
  438. {
  439. found=false;
  440. int tag=0;
  441. element position;
  442. bool x; 
  443. element temp;
  444. int j;
  445. Allocate(_stackarray,MAX_ANT_NUM,ANT);
  446. for(int i=0;i<MAX_ANT_NUM;i++)
  447. {
  448. for(j=0;j<_stackarray[i].GetLength();j++)
  449. {
  450. temp=_stackarray[i].stack[j];
  451. ::markall[temp.row][temp.col]++;
  452. }
  453. }
  454. for(i=0;i<MAX_ANT_NUM;i++)
  455. {
  456. position=_stackarray[i].GetCurrentPosition();
  457. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  458. {
  459. tag=i;
  460. found=true;
  461. }
  462. x=found;
  463. }
  464. }
  465. void CMergenewView::OnDoubleresult() 
  466. {
  467. Restart();
  468. CClientDC dc(this);
  469. CRect rect(550,30,600,80);
  470. char a[10];
  471. a[0]=NULL;
  472. CString text;
  473. int j;
  474. found=false;
  475. int tag=0;
  476. element position;
  477. bool x; 
  478. element temp;
  479. if(turn&&!found)
  480. {
  481. // DrawMerge(&dc);
  482. while(1)
  483. {
  484. // DisplayPath(&dc);
  485. Allocate(_stackarray,MAX_ANT_NUM,ANT);
  486. for(int i=0;i<MAX_ANT_NUM;i++)
  487. {
  488. for(j=0;j<_stackarray[i].GetLength();j++)
  489. {
  490. temp=_stackarray[i].stack[j];
  491. ::markall[temp.row][temp.col]++;
  492. }
  493. }
  494. for(i=0;i<MAX_ANT_NUM;i++)
  495. {
  496. position=_stackarray[i].GetCurrentPosition();
  497. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  498. {
  499. tag=i;
  500. found=true;
  501. }
  502. x=found;
  503. }
  504. if(tag)
  505. break;
  506. if(found==true)
  507. break;
  508. }
  509. }
  510. if(found==true)
  511. {
  512. CString text;
  513. text.Format("%d",::step);
  514. dc.TextOut(400,200,text);
  515. }
  516. }
  517. void CMergenewView::OnPerfectmaze() 
  518. {
  519. Restart();
  520. CClientDC dc(this);
  521. int i;
  522. MInitMark();
  523. for(i=0;i<MAX_ANT_NUM;i++)
  524. _mStackarray[i].MStackEmpty();
  525. InitAll();
  526. for(i=0;i<SIZEX_MAZE;i++)
  527. for(int j=0;j<SIZEY_MAZE;j++)
  528. maze[i][j]=1;
  529. pMazeMaker(::maze);
  530. for(i=0;i<MAX_ANT_NUM;i++)
  531. _stackarray[i].StackEmpty();
  532. InitView();
  533. // DrawMerge(&dc);
  534. showtag=true;
  535. turn=true;
  536. doubleresult=false;
  537. }
  538. void CMergenewView::HumanStepByStep ()
  539. {
  540. found=false;
  541. int tag=0;
  542. element position;
  543. bool x; 
  544. element temp;
  545. int j;
  546. // refreshSig(::markall,1,1,fromLeft);
  547. Allocate(_stackarray,MAX_ANT_NUM,HUMAN);
  548. for(int i=0;i<MAX_ANT_NUM;i++)
  549. {
  550. for(j=0;j<_stackarray[i].GetLength();j++)
  551. {
  552. temp=_stackarray[i].stack[j];
  553. ::markall[temp.row][temp.col]++;
  554. }
  555. }
  556. for(i=0;i<MAX_ANT_NUM;i++)
  557. {
  558. position=_stackarray[i].GetCurrentPosition();
  559. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  560. {
  561. tag=i;
  562. found=true;
  563. }
  564. x=found;
  565. }
  566. }
  567. void CMergenewView::OnHumanSbys() 
  568. {
  569. // TODO: Add your command handler code here
  570. CClientDC dc(this);
  571. CRect rect(550,30,600,80);
  572. char a[10];
  573. a[0]=NULL;
  574. CString text;
  575. int i,j;
  576. if(turn&&!found)
  577. {
  578. DrawMerge(&dc);
  579. HumanStepByStep();
  580. for(i=1;i<SIZEX_MAZE-1;i++)
  581. {
  582. for(j=1;j<SIZEY_MAZE-1;j++)
  583. {
  584. if(pos[i][j]==0)
  585. continue;
  586. text.Format("%d",pos[i][j]);
  587. dc.TextOut(j*width,i*width,text);
  588. }
  589. //dc.TextOut(;
  590. }
  591. // resulttag=true;
  592. }
  593. else if(found==true)
  594. {
  595. text.Format("%d",::step);
  596. dc.TextOut(400,200,text);
  597. }
  598. }
  599. void CMergenewView::OnHumanGonow() 
  600. {
  601. Restart();
  602. CClientDC dc(this);
  603. CRect rect(550,30,600,80);
  604. char a[10];
  605. a[0]=NULL;
  606. CString text;
  607. int j;
  608. found=false;
  609. int tag=0;
  610. element position;
  611. bool x; 
  612. element temp;
  613. if(turn&&!found)
  614. {
  615. DrawMerge(&dc);
  616. while(1)
  617. {
  618. // DisplayPath(&dc);
  619. // refreshSig(::markall,1,1,fromLeft);
  620. Allocate(_stackarray,MAX_ANT_NUM,HUMAN);
  621. for(int i=0;i<MAX_ANT_NUM;i++)
  622. {
  623. for(j=0;j<_stackarray[i].GetLength();j++)
  624. {
  625. temp=_stackarray[i].stack[j];
  626. ::markall[temp.row][temp.col]++;
  627. }
  628. }
  629. for(i=0;i<MAX_ANT_NUM;i++)
  630. {
  631. position=_stackarray[i].GetCurrentPosition();
  632. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  633. {
  634. tag=i;
  635. found=true;
  636. }
  637. x=found;
  638. }
  639. if(tag)
  640. break;
  641. if(found==true)
  642. break;
  643. }
  644. }
  645. if(found==true)
  646. {
  647. CString text;
  648. text.Format("%d",::step);
  649. dc.TextOut(400,200,text);
  650. }
  651. }
  652. void CMergenewView::Restart ()
  653. {
  654. ::step=0;
  655. ::found=false;
  656. ::first =true;
  657. ::totalEdge =0;
  658. ::totalLevel =0;
  659. ::treeHeight =0;
  660. ::imbalance =0;
  661. ::levelNum =0;
  662. }
  663. void CMergenewView::OnCompAntHuman() 
  664. {
  665. // TODO: Add your command handler code here
  666. int firstStep;
  667. OnPerfectmaze();
  668. OnDoubleresult();
  669. firstStep=::step;
  670. Restart();
  671. CClientDC dc(this);
  672. InitMark();
  673. for(int i=0;i<MAX_ANT_NUM;i++)
  674. _stackarray[i].StackEmpty();
  675. InitView();
  676. DrawMerge(&dc);
  677. showtag=true;
  678. turn=true;
  679. doubleresult=false;
  680. OnHumanGonow();
  681. CString text;
  682. text.Format("%d",firstStep);
  683. dc.TextOut(400,200,text);
  684. text.Format("%d",::step);
  685. dc.TextOut(450,200,text);
  686. }
  687. void CMergenewView::OnMicrobeSbs() 
  688. {
  689. // TODO: Add your command handler code here
  690. // TODO: Add your command handler code here
  691. if(::first==true)
  692. {
  693. //initial the enviorment
  694. //]MInitAll();
  695. MInitMark();
  696. for(int i=0;i<MAX_ANT_NUM;i++)
  697. ::_mStackarray[i].NewAntsCame ();
  698. found=false;
  699. first=false;
  700. }
  701. CClientDC dc(this);
  702. CRect rect(550,30,600,80);
  703. char a[10];
  704. a[0]=NULL;
  705. CString text;
  706. int i,j;
  707. if(turn&&!found)
  708. {
  709. DrawMerge(&dc);
  710. MicrobeStepByStep();
  711. for(i=1;i<SIZEX_MAZE-1;i++)
  712. {
  713. for(j=1;j<SIZEY_MAZE-1;j++)
  714. {
  715. if(pos[i][j]==0)
  716. continue;
  717. text.Format("%d",pos[i][j]);
  718. dc.TextOut(j*width,i*width,text);
  719. }
  720. }
  721. }
  722. else if(found==true)
  723. {
  724. text.Format("%d",::step);
  725. dc.TextOut(400,200,text);
  726. }
  727. }
  728. void CMergenewView::MicrobeStepByStep ()
  729. {
  730. int i;
  731. int tag;
  732. bool x;
  733. element position;
  734. MAllocate(_mStackarray,MAX_ANT_NUM);
  735. for(i=0;i<MAX_ANT_NUM;i++)
  736. {
  737. position=_mStackarray[i].GetCurrentPosition();
  738. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  739. {
  740. tag=i;
  741. break;
  742. }
  743. x=found;
  744. }
  745. }
  746. void CMergenewView::OnMicrobeGonow() 
  747. {
  748. // TODO: Add your command handler code here
  749. int i;
  750. MInitMark();
  751. for(i=0;i<MAX_ANT_NUM;i++)
  752. ::_mStackarray[i].NewAntsCame ();
  753. found=false;
  754. first=false;
  755. Restart();
  756. CClientDC dc(this);
  757. CRect rect(550,30,600,80);
  758. char a[10];
  759. a[0]=NULL;
  760. CString text;
  761. int tag=0;
  762. element position;
  763. bool x; 
  764. DrawMerge(&dc);
  765. while(1)
  766. {
  767. // DisplayPath(&dc);
  768. MAllocate(_mStackarray,MAX_ANT_NUM);
  769. for(i=0;i<MAX_ANT_NUM;i++)
  770. {
  771. position=_mStackarray[i].GetCurrentPosition();
  772. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  773. {
  774. tag=i;
  775. break;
  776. }
  777. x=::found;
  778. }
  779. if(tag)
  780. break;
  781. if(::found==true)
  782. break;
  783. }
  784. if(found==true)
  785. {
  786. CString text;
  787. text.Format("%d",::step);
  788. dc.TextOut(400,400,text);
  789. }
  790. }
  791. void CMergenewView::reInitWithoutMaze ()
  792. {
  793. Restart();
  794. InitMark();
  795. for(int i=0;i<MAX_ANT_NUM;i++)
  796. _stackarray[i].StackEmpty();
  797. InitView();
  798. showtag=true;
  799. turn=true;
  800. doubleresult=false;
  801. }
  802. void CMergenewView::OnCompMicroAnt() 
  803. {
  804. // TODO: Add your command handler code here
  805. int firstStep;
  806. CClientDC dc(this);
  807. OnPerfectmaze();
  808. OnMicrobeGonow();
  809. firstStep=::step;
  810. reInitWithoutMaze();
  811. DrawMerge(&dc);
  812. OnDoubleresult();
  813. CString text;
  814. text.Format("%d",firstStep);
  815. dc.TextOut(400,200,text);
  816. text.Format("%d",::step);
  817. dc.TextOut(450,200,text);
  818. }
  819. void CMergenewView::OnCompMicroHuman() 
  820. {
  821. // TODO: Add your command handler code here
  822. // TODO: Add your command handler code here
  823. int firstStep;
  824. OnPerfectmaze();
  825. OnMicrobeGonow();
  826. firstStep=::step;
  827. CClientDC dc(this);
  828. reInitWithoutMaze();
  829. DrawMerge(&dc);
  830. OnHumanGonow();
  831. CString text;
  832. text.Format("%d",firstStep);
  833. dc.TextOut(400,200,text);
  834. text.Format("%d",::step);
  835. dc.TextOut(450,200,text);
  836. }
  837. void CMergenewView::OnRcompMicroAnt() 
  838. {
  839. // TODO: Add your command handler code here
  840. // TODO: Add your command handler code here
  841. int firstStep;
  842. OnNewgame();
  843. OnMicrobeGonow();
  844. firstStep=::step;
  845. CClientDC dc(this);
  846. reInitWithoutMaze();
  847. DrawMerge(&dc);
  848. OnDoubleresult();
  849. CString text;
  850. text.Format("%d",firstStep);
  851. dc.TextOut(400,200,text);
  852. text.Format("%d",::step);
  853. dc.TextOut(450,200,text);
  854. }
  855. void CMergenewView::OnCompAll() 
  856. {
  857. // TODO: Add your command handler code here
  858. int firstStep;
  859. int secondStep;
  860. OnPerfectmaze();
  861. OnMicrobeGonow();
  862. firstStep=::step;
  863. CClientDC dc(this);
  864. DrawMerge(&dc);
  865. reInitWithoutMaze();
  866. OnDoubleresult();
  867. secondStep=::step;
  868. reInitWithoutMaze();
  869. DrawMerge(&dc);
  870. OnHumanGonow();
  871. CString text;
  872. text.Format("%d",firstStep);
  873. dc.TextOut(400,200,text);
  874. text.Format("%d",secondStep);
  875. dc.TextOut(450,200,text);
  876. text.Format("%d",::step);
  877. dc.TextOut(500,200,text);
  878. }
  879. void CMergenewView::OnStatistic() 
  880. {
  881. // TODO: Add your command handler code here
  882. fstream microbe("d:\maze\result\microbe.txt",ios::in|ios::out|ios::trunc);
  883. fstream ant("d:\maze\result\ant.txt",ios::in|ios::out|ios::trunc); 
  884. fstream human("d:\maze\result\human.txt",ios::in|ios::out|ios::trunc);
  885. fstream single("d:\maze\result\single.txt",ios::in|ios::out|ios::trunc);
  886. fstream withoutcoop("d:\maze\result\withoutcoop.txt",ios::in|ios::out|ios::trunc);
  887. fstream mazeShape("d:\maze\result\maze.txt",ios::in|ios::out|ios::trunc);
  888. fstream balance("d:\maze\result\balance.txt",ios::in|ios::out|ios::trunc);
  889. fstream level("d:\maze\result\level.txt",ios::in|ios::out|ios::trunc);
  890. fstream edge("d:\maze\result\edge.txt",ios::in|ios::out|ios::trunc);
  891. fstream height("d:\maze\result\height.txt",ios::in|ios::out|ios::trunc);
  892. fstream leaveNum("d:\maze\result\leaveNum.txt",ios::in|ios::out|ios::trunc);
  893. int generated[20]={-1};
  894. int k;
  895. for(::row=10;::row<=50;::row+=10)
  896. {
  897. ::SIZEX_MAZE =2*::row+1;
  898. ::EXIT_ROW=::SIZEX_MAZE-2;
  899. for(::col=10;::col<=50;::col+=10)
  900. {
  901. ::SIZEY_MAZE =2*::col+1;
  902. ::EXIT_COL=::SIZEY_MAZE-2;
  903. for(::MAX_ANT_NUM =5;::MAX_ANT_NUM <=25;::MAX_ANT_NUM +=10)
  904. {
  905. microbe<<"Row:  "<<::row<<"     ";
  906. ant<<"Row:  "<<::row<<"     ";
  907. human<<"Row:  "<<::row<<"     ";
  908. single<<"Row:  "<<::row<<"     ";
  909. withoutcoop<<"Row:  "<<::row<<"     ";
  910. mazeShape<<"Row:  "<<::row<<"     ";
  911. balance<<"Row:  "<<::row<<"     ";
  912. level<<"Row:  "<<::row<<"     ";
  913. edge<<"Row:  "<<::row<<"     ";
  914. height<<"Row:  "<<::row<<"     ";
  915. leaveNum<<"Row:  "<<::row<<"     ";
  916. microbe<<"Col:  "<<::col<<"      ";
  917. ant<<"Col:  "<<::col<<"      ";
  918. human<<"Col:  "<<::col<<"      ";
  919. single<<"Col:  "<<::col<<"      ";
  920. withoutcoop<<"Col:  "<<::col<<"      ";
  921. mazeShape<<"Col:  "<<::col<<"      ";
  922. balance<<"Col:  "<<::col<<"      ";
  923. level<<"Col:  "<<::col<<"      ";
  924. edge<<"Col:  "<<::col<<"      ";
  925. height<<"Col:  "<<::col<<"      ";
  926. leaveNum<<"Col:  "<<::col<<"      ";
  927. microbe<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  928. ant<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  929. human<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  930. single<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  931. withoutcoop<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  932. mazeShape<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  933. balance<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  934. level<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  935. edge<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  936. height<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  937. leaveNum<<"Ant num:  "<<::MAX_ANT_NUM <<endl;
  938. for(int time=0;time<20;time++)
  939. {
  940. OnPerfectmaze();
  941. OnMicrobeGonow();
  942. for(k=0;k<20;k++)
  943. if(::step!=generated[k])
  944. break;
  945. if(k==20)
  946. continue;
  947. generated[time]=::step;
  948. microbe<<::step<<endl;
  949. int temp=0;
  950. mazeAnaly(::maze,1,1,1,0,1,temp);
  951. balance<<::imbalance <<endl;
  952. height<<::treeHeight <<endl;
  953. level<<::totalLevel  <<endl;
  954. edge<<::totalEdge <<endl;
  955. leaveNum<<::levelNum <<endl;
  956. mazeShape<<endl;
  957. int i=0,j=0;
  958. for(i=0;i<SIZEX_MAZE;i++)
  959. {
  960. for(j=0;j<SIZEY_MAZE;j++)
  961. mazeShape<<::maze[i][j];
  962. mazeShape<<endl;   
  963. }
  964. reInitWithoutMaze();
  965. OnDoubleresult();
  966. ant<<::step<<endl;
  967. reInitWithoutMaze();
  968. OnHumanGonow();
  969. human<<::step <<endl;
  970. reInitWithoutMaze();
  971. ::step=OnSingle();
  972. single<<::step <<endl;
  973. reInitWithoutMaze();
  974. ::step=OnWithoutcoop();
  975. withoutcoop<<::step <<endl;
  976. }
  977. }
  978. }
  979. }
  980. }
  981. int CMergenewView::OnSingle() 
  982. {
  983. int tempAntNum=::MAX_ANT_NUM ;
  984. ::MAX_ANT_NUM =1;
  985. int temp=OnWithoutcoop();
  986. ::MAX_ANT_NUM =tempAntNum;
  987. return temp;
  988. }
  989. int CMergenewView::OnWithoutcoop() 
  990. {
  991. // TODO: Add your command handler code here
  992. int i;
  993. int tag=0;
  994. element position;
  995. bool x; 
  996. int withoutCoop=0;
  997. CClientDC dc(this);
  998. found=false;
  999. while(1)
  1000. {
  1001. withoutCoop++;
  1002. for(i=0;i<MAX_ANT_NUM;i++)
  1003. {
  1004. _stackarray[i].SearchPathStepByStepRandom();
  1005. position=_stackarray[i].GetCurrentPosition();
  1006. if(position.row==EXIT_ROW&&position.col==EXIT_COL)
  1007. {
  1008. tag=i;
  1009. break;
  1010. }
  1011. x=found;
  1012. }
  1013. DisplayPath(&dc);
  1014. if(tag)
  1015. break;
  1016. if(found==true)
  1017. break;
  1018. }
  1019. CString text;
  1020. text.Format("%d",withoutCoop);
  1021. dc.TextOut(400,300,text);
  1022. return withoutCoop;
  1023. }
  1024. void CMergenewView::OnWithsingle() 
  1025. {
  1026. // TODO: Add your command handler code here
  1027. int firstStep;
  1028. int secondStep;
  1029. int thirdStep;
  1030. int fourthStep;
  1031. int fifthStep;
  1032. OnPerfectmaze();
  1033. OnMicrobeGonow();
  1034. firstStep=::step;
  1035. CClientDC dc(this);
  1036. reInitWithoutMaze();
  1037. OnDoubleresult();
  1038. secondStep=::step;
  1039. reInitWithoutMaze();
  1040. OnHumanGonow();
  1041. thirdStep=::step ;
  1042. reInitWithoutMaze();
  1043. fourthStep=OnSingle();
  1044. reInitWithoutMaze();
  1045. fifthStep=OnWithoutcoop();
  1046. CString text;
  1047. text.Format("%d",firstStep);
  1048. dc.TextOut(200,200,text);
  1049. text.Format("%d",secondStep);
  1050. dc.TextOut(250,200,text);
  1051. text.Format("%d",thirdStep);
  1052. dc.TextOut(300,200,text);
  1053. text.Format("%d",fourthStep);
  1054. dc.TextOut(350,200,text);
  1055. text.Format("%d",fifthStep);
  1056. dc.TextOut(400,200,text);
  1057. }