thinker.cpp

来自「巫魔问题求解」· C++ 代码 · 共 415 行 · 第 1/2 页

CPP
415
字号
}

////////////////////////////////////////////////////////////
//bool Thinker::ThinkCore(int i,
//                        std::vector<unsigned int> &suspect_type)
//{
//    bool refreshed = false;//注意这个变量!!有可能会无限调用,一定要小心!!!
//    const std::vector<Cell*> &suspect_cell = this->TheWorldModel().GetClientMap().GetSuspectCells();
//    bool has_deleted = false;
//    for (unsigned int i = 0;
//        i < suspect_cell.size();
//        has_deleted ? i++ : i)
//    {
//        has_deleted = false;
//        for (int j=0; j<3; j++)
//        {
//            unsigned int type = 0;
//            switch (j)
//            {
//            case 0:
//                type = Cell::CT_Wumpus;
//                break;
//            case 1:
//                type = Cell::CT_Trap;
//                break;
//            case 2:
//                type = Cell::CT_Gold;
//                break;
//
//            default:
//                type = Cell::CT_None;
//                continue;
//            }
//            if (suspect_type[i] & type)
//            {
//                //首先假设是type类型
//                std::vector<Cell*> sus_cell = suspect_cell;
//                std::vector<Cell*>::const_iterator iter_c = sus_cell.begin();
//                std::vector<unsigned int> sus_type = suspect_type;
//                std::vector<unsigned int>::const_iterator iter_t = sus_type.begin();
//                iter_c += i;
//                iter_t += i;
//                sus_cell.erase(iter_c);
//                sus_type.erase(iter_t);
//                //新建一个空的ClientMap,然后初始化
//                ClientMap tmpCM(this->TheWorldModel().GetInfo().mXBorder,this->TheWorldModel().GetInfo().mYBorder, this->TheWorldModel());
//                for (unsigned int k = 0;
//                    k < this->TheWorldModel().GetClientMap().GetKnownCells().size();
//                    k ++)
//                {
//                    Cell *pc = this->TheWorldModel().GetClientMap().GetKnownCells()[k];
//                    tmpCM.TheCell(pc->GetX(), pc->GetY())._su_SetType(pc->GetType());
//                }
//                tmpCM.TheCell(suspect_cell[i]->GetX(), suspect_cell[i]->GetY())._su_SetType(type);
//                
//                //开始搜索了!!!
//                if (!this->InnerThink(tmpCM, sus_cell, sus_type, 0))
//                {
//                    suspect_type[i] ^= type;
//                    refreshed = true;
//                }
//            }
//        }
//        if (suspect_type[i] == Cell::CT_None)
//        {
//            //如果所有类型都不能匹配
//            this->TheWorldModel().TheClientMap().TheSuspectCells()[i]->_su_SetType(Cell::CT_None);
//            ClientMap::Tool_InsertToVector(this->TheWorldModel().TheClientMap().TheKnownCells(), this->TheWorldModel().TheClientMap().TheSuspectCells()[i]);
//            ClientMap::Tool_InsertToVector(this->TheWorldModel().TheClientMap().TheSafeCells(), this->TheWorldModel().TheClientMap().TheSuspectCells()[i]);
//            this->TheWorldModel().TheClientMap().TheSuspectCells().erase(this->TheWorldModel().TheClientMap().TheSuspectCells().begin() + i);
//            suspect_type.erase(suspect_type.begin() + i);
//            has_deleted = true;
//            refreshed = true;
//        }
//        else 
//        {
//            int count = 0;
//            if (suspect_type[i] & Cell::CT_Wumpus) { count++; }
//            if (suspect_type[i] & Cell::CT_Trap)   { count++; }
//            if (suspect_type[i] & Cell::CT_Gold)   { count++; }
//            if (count == 1)
//            {
//                //如果只能匹配一种类型,检查一下是不是不可以没有类型
//                std::vector<Cell*> sus_cell = suspect_cell;
//                std::vector<Cell*>::const_iterator iter_c = sus_cell.begin();
//                std::vector<unsigned int> sus_type = suspect_type;
//                std::vector<unsigned int>::const_iterator iter_t = sus_type.begin();
//                iter_c += i;
//                iter_t += i;
//                sus_cell.erase(iter_c);
//                sus_type.erase(iter_t);
//                //新建一个空的ClientMap,然后初始化
//                ClientMap tmpCM(this->TheWorldModel().GetInfo().mXBorder,this->TheWorldModel().GetInfo().mYBorder,this->TheWorldModel());
//                for (unsigned int k = 0;
//                    k < this->TheWorldModel().GetClientMap().GetKnownCells().size();
//                    k ++)
//                {
//                    Cell *pc = this->TheWorldModel().GetClientMap().GetKnownCells()[k];
//                    tmpCM.TheCell(pc->GetX(), pc->GetY())._su_SetType(pc->GetType());
//                }
//                tmpCM.TheCell(suspect_cell[i]->GetX(), suspect_cell[i]->GetY())._su_SetType(Cell::CT_None);
//                
//                //开始搜索了!!!
//                if (!this->InnerThink(tmpCM, sus_cell, sus_type, 0))
//                {
//                    this->TheWorldModel().TheClientMap().TheSuspectCells()[i]->_su_SetType(suspect_type[i]);
//                    ClientMap::Tool_InsertToVector(this->TheWorldModel().TheClientMap().TheKnownCells(), this->TheWorldModel().TheClientMap().TheSuspectCells()[i]);
//                    if (suspect_type[i] == Cell::CT_Gold)
//                    {
//                        ClientMap::Tool_InsertToVector(this->TheWorldModel().TheClientMap().TheSafeCells(), this->TheWorldModel().TheClientMap().TheSuspectCells()[i]);
//                    }
//                    this->TheWorldModel().TheClientMap().TheSuspectCells().erase(this->TheWorldModel().TheClientMap().TheSuspectCells().begin() + i);
//                    suspect_type.erase(suspect_type.begin() + i);
//                    has_deleted = true;
//                    refreshed = true;
//                }
//            }
//        }
//    }
//    return refreshed;
//}
//
/////////////////////////////////////////////////////
//bool Thinker::InnerThink(ClientMap &cm,
//                    std::vector<_base::Cell*> &suspect_list,
//                    std::vector<unsigned int> &suspect_type,
//                    unsigned int depth)
//{
//    if (depth >= suspect_type.size())
//    {
//        return this->JudgeMap(cm);
//    }
//    for (int i=0; i<3; i++)
//    {
//        unsigned int type = 0;
//        switch (i)
//        {
//        case 0:
//            type = Cell::CT_Wumpus;
//            break;
//        case 1:
//            type = Cell::CT_Trap;
//            break;
//        case 2:
//            type = Cell::CT_Gold;
//            break;
//
//        default:
//            type = Cell::CT_None;
//            continue;
//        }
//        if (suspect_type[depth] & type)
//        {
//            cm.TheCell(suspect_list[depth]->GetX(), suspect_list[depth]->GetY())._su_SetType(type);
//            if (this->InnerThink(cm, suspect_list, suspect_type, depth+1))
//            {
//                return true;
//            }
//        }
//    }
//    return false;
//}
//
///////////////////////////////////////////////////////
//bool Thinker::JudgeMap(ClientMap &cm)
//{
//    //预处理一下,把多余的邻近标志去掉
//    for (unsigned int i=0; i<cm.GetXBorder(); i++)
//    {
//        for (unsigned int j=0; j<cm.GetYBorder(); j++)
//        {
//            cm.TheCell(i,j)._su_DeleteType(~(Cell::CT_Wumpus | Cell::CT_Trap | Cell::CT_Gold));
//        }
//    }
//    //加上新的邻近标志
//    cm.UpdateCells();
//
//    for (unsigned int i=0; i<cm.GetXBorder(); i++)
//    {
//        for (unsigned int j=0; j<cm.GetYBorder(); j++)
//        {
//            if (this->GetWorldModel().GetClientMap().GetCell(i,j).IsWumpusAround())
//            {
//                if (!cm.GetCell(i,j).IsWumpusAround())
//                {
//                    return false;
//                }
//            }
//            if (this->GetWorldModel().GetClientMap().GetCell(i,j).IsTrapAround())
//            {
//                if (!cm.GetCell(i,j).IsTrapAround())
//                {
//                    return false;
//                }
//            }
//            if (this->GetWorldModel().GetClientMap().GetCell(i,j).IsGoldAround())
//            {
//                if (!cm.GetCell(i,j).IsGoldAround())
//                {
//                    return false;
//                }
//            }
//        }
//    }
//    return true;
//}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?