Пример #1
0
void PokePersonal::setMove(int moveNum, int moveSlot, bool check) throw(QString)
{
    if (moveNum == move(moveSlot))
        return;

    if (check && moveNum != 0) {
        m_moves[moveSlot] = Move::NoMove;

        if (hasMove(moveNum))
            throw QObject::tr("%1 already has move %2.").arg(nickname(), MoveInfo::Name(moveNum));
        else if (gen() > 1 && !PokemonInfo::Moves(num(), gen()).contains(moveNum))
            throw QObject::tr("%1 can't learn %2.").arg(nickname(), MoveInfo::Name(moveNum));
    }

    m_moves[moveSlot] = moveNum;

    if (check) {
        QSet<int> invalid_moves;
        QString error;
        if (!MoveSetChecker::isValid(num(), gen(), m_moves[0],m_moves[1],m_moves[2],m_moves[3],ability(),gender(),level(),false,&invalid_moves, &error)) {
            m_moves[moveSlot] = Move::NoMove;
            throw error;
        }
    }
}
Пример #2
0
//finds the move which results in best avg score for a given grid
double bestPossibleMove(const Board& board, int depth)
{
  if (depth == 0)
  {   
    return hasMove(board) ? findHeuristic(board) : 0;
  }

  double maxScore = 0;

  for(int direction = 0; direction < 4; direction++)
  {
    Board aiBoard = board;
    move(aiBoard, direction);

    // if before and after moves are same
    if (aiBoard == board)  
    {
      continue;
    }
    
    double aiScore = 0;

    aiScore = aiSolverMove(aiBoard, depth - 1);

    if (aiScore > maxScore)
    {
      maxScore = aiScore;
    }
  }
    
  return maxScore;
}