thinker.cpp
来自「巫魔问题求解」· C++ 代码 · 共 415 行 · 第 1/2 页
CPP
415 行
#include "Thinker.h"
#include "WorldModel.h"
#include "ClientMap.h"
#ifdef SHOW_THINKING_STEP
#include <iostream>
#endif
#include <Wum_Tool/src/Math.h>
using namespace _algorithm;
using namespace _base;
////////////////////////////////////////////////////
Thinker::Thinker(WorldModel &wm)
{
this->mpWorldModel = &wm;
}
////////////////////////////////////////////////////
Thinker::Thinker(const Thinker &from)
{
}
////////////////////////////////////////////////////
Thinker::~Thinker(void)
{
}
////////////////////////////////////////////////////
WorldModel &Thinker::TheWorldModel(void)
{
return *mpWorldModel;
}
////////////////////////////////////////////////////
const WorldModel &Thinker::GetWorldModel(void) const
{
return *mpWorldModel;
}
////////////////////////////////////////////////////
void Thinker::Think(void)
{
ClientMap &cm = this->TheWorldModel().TheClientMap();
unsigned int cur_x = this->TheWorldModel().GetInfo().mPositionX;
unsigned int cur_y = this->TheWorldModel().GetInfo().mPositionY;
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), &cm.TheCell(cur_x, cur_y));
ClientMap::Tool_InsertToVector(cm.TheHasCameCells(), &cm.TheCell(cur_x, cur_y));
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), &cm.TheCell(cur_x, cur_y));
if (!(cm.TheCell(cur_x, cur_y).GetType() & (Cell::CT_Stench | Cell::CT_Breeze)))
{
if (cm.TheCell(cur_x, cur_y).CellUp())
{
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), cm.TheCell(cur_x, cur_y).CellUp());
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), cm.TheCell(cur_x, cur_y).CellUp());
}
if (cm.TheCell(cur_x, cur_y).CellDown())
{
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), cm.TheCell(cur_x, cur_y).CellDown());
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), cm.TheCell(cur_x, cur_y).CellDown());
}
if (cm.TheCell(cur_x, cur_y).CellLeft())
{
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), cm.TheCell(cur_x, cur_y).CellLeft());
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), cm.TheCell(cur_x, cur_y).CellLeft());
}
if (cm.TheCell(cur_x, cur_y).CellRight())
{
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), cm.TheCell(cur_x, cur_y).CellRight());
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), cm.TheCell(cur_x, cur_y).CellRight());
}
}
Cell *p1 = NULL;
Cell *p2 = NULL;
for (unsigned int i=0; i<cm.TheHasCameCells().size(); i++)
{
if (cm.TheHasCameCells()[i]->GetType() & Cell::CT_Gleam)
{
p2 = p1;
p1 = cm.TheHasCameCells()[i];
}
}
if (p1 && p2)
{
unsigned int x1 = p1->GetX(),
y1 = p1->GetY(),
x2 = p2->GetX(),
y2 = p2->GetY();
unsigned int xx = cm.GetXBorder();
unsigned int yy = cm.GetYBorder();
if ((x1 == x2) && (_tool::Abs((int)y1-(int)y2)==2) ||
(y1 == y2) && (_tool::Abs((int)x1-(int)x2)==2))
{
xx = (x1+x2)/2;
yy = (y1+y2)/2;
}
if (_tool::Abs((int)x1-(int)x2)==1 && _tool::Abs((int)y1-(int)y2)==1)
{
if (cm.TheCell(x1,y2).IsHasCame())
{
xx = x2;
yy = y1;
}
if (cm.TheCell(x2,y1).IsHasCame())
{
xx = x1;
yy = y2;
}
}
if (xx < cm.GetXBorder() && yy < cm.GetYBorder())
{
cm.TheCell(xx,yy)._su_AddType(Cell::CT_Gold);
ClientMap::Tool_InsertToVector(cm.TheSafeCells(), &cm.TheCell(xx,yy));
ClientMap::Tool_InsertToVector(cm.TheKnownCells(), &cm.TheCell(xx,yy));
}
}
// ClientMap &cm = this->TheWorldModel().TheClientMap();
//#ifdef SHOW_THINKING_STEP
// std::cout << std::endl << "======think begin========" << std::endl;
// std::cout << "KnownCells:";
// for (unsigned int i=0; i<cm.TheKnownCells().size(); i++)
// {
// std::cout << '(' << cm.TheKnownCells()[i]->GetX() << ','
// << cm.TheKnownCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "SafeCells:";
// for (unsigned int i=0; i<cm.TheSafeCells().size(); i++)
// {
// std::cout << '(' << cm.TheSafeCells()[i]->GetX() << ','
// << cm.TheSafeCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "HasCameCells:";
// for (unsigned int i=0; i<cm.TheHasCameCells().size(); i++)
// {
// std::cout << '(' << cm.TheHasCameCells()[i]->GetX() << ','
// << cm.TheHasCameCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "SuspectCells:";
// for (unsigned int i=0; i<cm.TheSuspectCells().size(); i++)
// {
// std::cout << '(' << cm.TheSuspectCells()[i]->GetX() << ','
// << cm.TheSuspectCells()[i]->GetY() << ')';
// }
// std::cout << std::endl;
//
//#endif
// bool refreshed = true;
// while (refreshed)
// {
// refreshed = false;
// this->TheWorldModel().TheClientMap().Update();
// for (unsigned int i=0; i<this->TheWorldModel().GetClientMap().GetSuspectCells().size(); i++)//对怀疑的节点进行遍历
// {
// //设置怀疑类型
// std::vector<unsigned int> suspect_type;
// for (std::vector<Cell*>::iterator iter2 = cm.TheSuspectCells().begin();
// iter2 != cm.TheSuspectCells().end();
// iter2++)
// {
// unsigned int type = 0;
// if (cm.GetCell((*iter2)->GetX(), (*iter2)->GetY()).IsNear(Cell::CT_Stench))
// {
// type |= Cell::CT_Wumpus;
// }
// if (cm.GetCell((*iter2)->GetX(), (*iter2)->GetY()).IsNear(Cell::CT_Breeze))
// {
// type |= Cell::CT_Trap;
// }
// if (cm.GetCell((*iter2)->GetX(), (*iter2)->GetY()).IsNear(Cell::CT_Gleam))
// {
// type |= Cell::CT_Gold;
// }
// suspect_type.push_back(type);
// }
//
// refreshed = refreshed || this->ThinkCore(i, suspect_type);
// }
// }
//#ifdef SHOW_THINKING_STEP
// std::cout << std::endl << "======think end========" << std::endl;
// std::cout << "KnownCells:";
// for (unsigned int i=0; i<cm.TheKnownCells().size(); i++)
// {
// std::cout << '(' << cm.TheKnownCells()[i]->GetX() << ','
// << cm.TheKnownCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "SafeCells:";
// for (unsigned int i=0; i<cm.TheSafeCells().size(); i++)
// {
// std::cout << '(' << cm.TheSafeCells()[i]->GetX() << ','
// << cm.TheSafeCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "HasCameCells:";
// for (unsigned int i=0; i<cm.TheHasCameCells().size(); i++)
// {
// std::cout << '(' << cm.TheHasCameCells()[i]->GetX() << ','
// << cm.TheHasCameCells()[i]->GetY() << ')';
// }
// std::cout << std::endl << "SuspectCells:";
// for (unsigned int i=0; i<cm.TheSuspectCells().size(); i++)
// {
// std::cout << '(' << cm.TheSuspectCells()[i]->GetX() << ','
// << cm.TheSuspectCells()[i]->GetY() << ')';
// }
// std::cout << std::endl;
//
//#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?