資源簡介
采用遺傳算法搜索最優路徑代碼

代碼片段和文件信息
#include?“CBobsMap.h“
//this?defines?our?little?maze?which?Bob?wanders
//around?in
const?int?CBobsMap::map[MAP_HEIGHT][MAP_WIDTH]?=?
{1?1?1?1?1?1?1?1?1?1?1?1?1?1?1
?1?0?1?0?0?0?0?0?1?1?1?0?0?0?1
?8?0?0?0?0?0?0?0?1?1?1?0?0?0?1
?1?0?0?0?1?1?1?0?0?1?0?0?0?0?1
?1?0?0?0?1?1?1?0?0?0?0?0?1?0?1
?1?1?0?0?1?1?1?0?0?0?0?0?1?0?1
?1?0?0?0?0?1?0?0?0?0?1?1?1?0?1
?1?0?1?1?0?0?0?1?0?0?0?0?0?0?5
?1?0?1?1?0?0?0?1?0?0?0?0?0?0?1
?1?1?1?1?1?1?1?1?1?1?1?1?1?1?1};
const?int?CBobsMap::m_iMapHeight?=?MAP_HEIGHT;
const?int?CBobsMap::m_iMapWidth??=?MAP_WIDTH;
const?int?CBobsMap::m_iStartX?=?14;
const?int?CBobsMap::m_iStartY?=?7;
const?int?CBobsMap::m_iEndX?=?0;
const?int?CBobsMap::m_iEndY?=?2;
//-------------------------------Render?-----------------------------
void?CBobsMap::Render(const?int?cxClient
??const?int?cyClient
??HDC?surface)
{
const?int?border?=?20;
int?BlockSizeX?=?(cxClient?-?2*border)/m_iMapWidth;
int?BlockSizeY?=?(cyClient?-?2*border)/m_iMapHeight;
HBRUSH BlackBrush?RedBrush?OldBrush;
HPEN NullPen?OldPen;
//grab?a?null?pen?so?we?can?see?the?outlines?of?the?cells
NullPen?=?(HPEN)GetStockobject(NULL_PEN);
//grab?a?brush?to?fill?our?cells?with
BlackBrush?=?(HBRUSH)GetStockobject(BLACK_BRUSH);
//create?a?brush?for?the?exit/entrance?points
RedBrush?=?CreateSolidBrush(RGB(25500));
//select?them?into?the?device?conext
OldBrush?=?(HBRUSH)Selectobject(surface?BlackBrush);
OldPen ?= ?(HPEN)Selectobject(surface?NullPen);
for?(int?y=0;?y {
for?(int?x=0;?x {
//calculate?the?corners?of?each?cell
int?left??=?border?+?(BlockSizeX?*?x);
int?right?=?left?+?BlockSizeX;
int?top????=?border?+?(BlockSizeY?*?y);
int?bottom?=?top?+?BlockSizeY;
//draw?black?rectangle?if?this?is?a?wall
if?(map[y][x]?==?1)
{
Selectobject(surface?BlackBrush);
//draw?the?cell
Rectangle(surface?left?top?right?bottom);
}
//draw?red?for?exit?and?entrance
if?(?(map[y][x]?==?5)?||?(map[y][x]?==?8))
{
Selectobject(surface?RedBrush);
//draw?the?cell
Rectangle(surface?left?top?right?bottom);
}
}
}
//restore?the?original?brush
Selectobject(surface?OldBrush);
//and?pen
Selectobject(surface?OldPen);
}
//-------------------------------MemoryRender?------------------------
//
// //draws?whatever?path?may?be?stored?in?the?memory
//--------------------------------------------------------------------
void?CBobsMap::MemoryRender(const?int?cxClient
const?int?cyClient
HDC?surface)
{
const?int?border?=?20;
int?BlockSizeX?=?(cxClient?-?2*border)/m_iMapWidth;
int?BlockSizeY?=?(cyClient?-?2*border)/m_iMapHeight;
HBRUSH GreyBrush?OldBrush;
HPEN NullP
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6093??2003-11-18?18:44??Pathfinder\CBobsMap.cpp
?????文件???????1507??2003-11-18?18:44??Pathfinder\CBobsMap.h
?????文件???????7979??2003-11-18?18:44??Pathfinder\CgaBob.cpp
?????文件???????3624??2003-11-18?18:44??Pathfinder\CgaBob.h
?????文件????????557??2003-11-18?18:44??Pathfinder\defines.h
?????文件???????5894??2003-11-18?18:44??Pathfinder\main.cpp
?????文件???????4432??2003-11-18?18:44??Pathfinder\pathfinder.dsp
?????文件????????545??2003-11-18?18:44??Pathfinder\pathfinder.dsw
?????文件?????107520??2010-07-02?19:22??Pathfinder\pathfinder.ncb
?????文件??????57856??2010-07-02?19:22??Pathfinder\pathfinder.opt
?????文件???????1662??2010-07-02?19:22??Pathfinder\pathfinder.plg
?????文件????????371??2003-11-18?18:44??Pathfinder\utils.cpp
?????文件???????1152??2003-11-18?18:44??Pathfinder\utils.h
?????目錄??????????0??2010-12-09?14:11??Pathfinder
-----------?---------??----------?-----??----
???????????????199192????????????????????14
- 上一篇:2021年考研英語5500個詞匯
- 下一篇:Apache官方中文幫助手冊
評論
共有 條評論