亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ccontroller.cpp

?? 開發游戲人工智能的王道書
?? CPP
字號:
#include "CController.h"
#include "resource.h"



string CController::m_sPatternName = "";


//--------------------------------- ctor -------------------------------
//
//----------------------------------------------------------------------
CController::CController(HWND hwnd):m_bDrawing(false),
                          m_iNumSmoothPoints(NUM_VECTORS+1),
                          m_hwnd(hwnd),
                          m_dHighestOutput(0),
                          m_iBestMatch(-1),
                          m_iMatch(-1),
                          m_iNumValidPatterns(NUM_PATTERNS),
                          m_Mode(UNREADY)
                         
{
  //create the database
  m_pData = new CData(m_iNumValidPatterns, NUM_VECTORS);

  //setup the network
  m_pNet = new CNeuralNet(NUM_VECTORS*2,        //inputs
                          m_iNumValidPatterns,  //outputs
                          NUM_HIDDEN_NEURONS,   //hidden
                          LEARNING_RATE);
                          
}

//--------------------------------- dtor --------------------------------
//
//-----------------------------------------------------------------------
CController::~CController()
{
  delete m_pData;
  delete m_pNet;
}
//-----------------------------------------------------------------
//
//  message handler for the dialog box
//-----------------------------------------------------------------
BOOL CALLBACK CController::DialogProc(HWND   hwnd,
                                 UINT   msg,
                                 WPARAM wParam,
                                 LPARAM lParam)
{
  switch(msg)
  {
  case WM_INITDIALOG:
    {
      return true;
    }

    break;

  case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
      case IDOK:
        {
          //get a handle to the edit control
          HWND hwndEdit = GetDlgItem(hwnd, IDC_GRAB_NAME); 

          //set the focus
          SetFocus(hwndEdit);

          //get the text
          char buffer[30]; 

          GetWindowText(hwndEdit, buffer, 30);

          m_sPatternName = buffer;

          //if the user hasn't entered a name set name
          if (m_sPatternName.size == 0)
          {
            m_sPatternName = "User defined pattern";
          }
          
          EndDialog(hwnd, 0);

          return true;
        }

        break;
      }
    }

    break;

  }//end switch

  return false;
}

//--------------------------- Clear --------------------------------------
//
//  clears the current data
//------------------------------------------------------------------------
void CController::Clear()
{
  m_vecPath.clear();
  m_vecSmoothPath.clear();
  m_vecVectors.clear();
}

//------------------------------ Drawing ---------------------------------
//
//  this is called whenever the user depresses or releases the right
//  mouse button.
//  If val is true then the right mouse button has been depressed so all
//  mouse data is cleared ready for the next gesture. If val is false a
//  gesture has just been completed. The gesture is then either added to
//  the current data set or it is tested to see if it matches an existing
//  pattern.
//  The hInstance is required so a dialog box can be created as a child
//  window of the main app instance. The dialog box is used to grab the
//  name of any user defined gesture
//------------------------------------------------------------------------
bool CController::Drawing(bool val, HINSTANCE hInstance)
{
  if (val == true)
  {
    Clear();
  }

  else
  {
    //smooth and vectorize the data if we have enough points
    if (Smooth())
    {
      //create the vectors
      CreateVectors();

      if (m_Mode == ACTIVE)
      {

        if (!TestForMatch())
        {
          return false;
        }
      }

      else
      {
        //add the data set if user is happy with it
        if(MessageBox(m_hwnd, "Happy with this gesture?", "OK?", MB_YESNO) == IDYES)
        {
           //grab a name for this pattern
          DialogBox(hInstance,
                    MAKEINTRESOURCE(IDD_DIALOG1),
                    m_hwnd,
                    DialogProc);

          
           //add the data
           m_pData->AddData(m_vecVectors, m_sPatternName);

           //delete the old network
           delete m_pNet;

           ++m_iNumValidPatterns;

           //create a new network
           m_pNet = new CNeuralNet(NUM_VECTORS*2,
                                   m_iNumValidPatterns,
                                   NUM_VECTORS*2,
                                   LEARNING_RATE);

           //train the network
           TrainNetwork();

           m_Mode = ACTIVE;
         }

         else
         {
           //clear dismissed gesture
           m_vecPath.clear();
         }
      }
    }
  }
    
  m_bDrawing = val;

  return true;
}

//------------------------------ TrainNetwork -----------------------------
//
//  Trains the neural net work with the predefined training set
//-------------------------------------------------------------------------
bool CController::TrainNetwork()
{  
  m_Mode = TRAINING;

  if(!m_pNet->Train(m_pData, m_hwnd))
  {
    return false;
  }

  m_Mode = ACTIVE;

  return true;
}
  

//------------------------- TestForMatch ----------------------------------
//
//  checks the mouse pattern to see if it matches one of the learned
//  patterns
//-------------------------------------------------------------------------
bool CController::TestForMatch()
{
  //input the smoothed mouse vectors into the net and see if we get a match
  vector<double> outputs = m_pNet->Update(m_vecVectors);

  if (outputs.size() == 0)
  {
    MessageBox(NULL, "Error in with ANN output", "Error!", MB_OK);

    return false;
  }

  //run through the outputs and see which is highest
  m_dHighestOutput = 0;
  m_iBestMatch = 0;
  m_iMatch = -1;
  
  for (int i=0; i<outputs.size(); ++i)
  {
    if (outputs[i] > m_dHighestOutput)
    {
      //make a note of the most likely candidate
      m_dHighestOutput = outputs[i];

      m_iBestMatch = i;
 

      //if the candidates output exceeds the threshold we 
      //have a match! ...so make a note of it.
      if (m_dHighestOutput > MATCH_TOLERANCE)
      {
        m_iMatch = m_iBestMatch;
                  
      }
    }
  }

  return true;
}

//----------------------------------- CreateVectors ----------------------
//
//  this function creates normalized vectors out of the series of POINTS
//  in m_vecSmoothPoints
//------------------------------------------------------------------------
void CController::CreateVectors()
{ 
  for (int p=1; p<m_vecSmoothPath.size(); ++p)
  {    

    double x = m_vecSmoothPath[p].x - m_vecSmoothPath[p-1].x;
    double y = m_vecSmoothPath[p].y - m_vecSmoothPath[p-1].y;

    SVector2D v1(1, 0);
    SVector2D v2(x, y);

    Vec2DNormalize(v2);

    m_vecVectors.push_back(v2.x);
    m_vecVectors.push_back(v2.y);
  }

}

//------------------------------------- Smooth ---------------------------
//
//------------------------------------------------------------------------
bool CController::Smooth()
{
  //make sure it contains enough points for us to work with
  if (m_vecPath.size() < m_iNumSmoothPoints)
  {
    //return
    return false;
  }

  //copy the raw mouse data
  m_vecSmoothPath = m_vecPath;

  //while there are excess points iterate through the points
  //finding the shortest spans, creating a new point in its place
  //and deleting the adjacent points.
  while (m_vecSmoothPath.size() > m_iNumSmoothPoints)
  {
    double ShortestSoFar = 99999999;

    int PointMarker = 0;

    //calculate the shortest span
    for (int SpanFront=2; SpanFront<m_vecSmoothPath.size()-1; ++SpanFront)
    {
      //calculate the distance between these points
      double length = 
      sqrt( (m_vecSmoothPath[SpanFront-1].x - m_vecSmoothPath[SpanFront].x) *
            (m_vecSmoothPath[SpanFront-1].x - m_vecSmoothPath[SpanFront].x) +

            (m_vecSmoothPath[SpanFront-1].y - m_vecSmoothPath[SpanFront].y)*
            (m_vecSmoothPath[SpanFront-1].y - m_vecSmoothPath[SpanFront].y));

      if (length < ShortestSoFar)
      {
        ShortestSoFar = length;

        PointMarker = SpanFront;
      }      
    }

    //now the shortest span has been found calculate a new point in the 
    //middle of the span and delete the two end points of the span
    POINTS newPoint;

    newPoint.x = (m_vecSmoothPath[PointMarker-1].x + 
                  m_vecSmoothPath[PointMarker].x)/2;

    newPoint.y = (m_vecSmoothPath[PointMarker-1].y +
                  m_vecSmoothPath[PointMarker].y)/2;

    m_vecSmoothPath[PointMarker-1] = newPoint;

    m_vecSmoothPath.erase(m_vecSmoothPath.begin() + PointMarker);
  }

  return true;
}


//--------------------------------- LearningMode -------------------------
//
//  clears the screen and puts the app into learning mode, ready to accept
//  a user defined gesture
//------------------------------------------------------------------------
void CController::LearningMode()
{
  m_Mode = LEARNING;

  Clear();

  //update window
  InvalidateRect(m_hwnd, NULL, TRUE);
  UpdateWindow(m_hwnd);
}
			
//-------------------------------- Render --------------------------------
//
//------------------------------------------------------------------------
void CController::Render(HDC &surface, int cxClient, int cyClient)
{
    
  //render error from any training taking place
  if(m_Mode == TRAINING)
  {   
    string s = "Error: " + ftos(m_pNet->Error());
    TextOut(surface, cxClient/2, 5, s.c_str(), s.size());

     s = "Epochs: " + ftos(m_pNet->Epoch());
    TextOut(surface, 5, 5, s.c_str(), s.size());
  }

  if (m_pNet->Trained())
  {
    if ((m_Mode == ACTIVE))
    {
       string s = "Recognition circuits active";
       TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
    }

    if (m_Mode == LEARNING)
    {
      string s = "Recognition circuits offline - Enter a new gesture";
      TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
    }
  }

  else
  {
     string s = "Training in progress...";
     TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
  }


  if (!m_bDrawing)
  {  
    //render best match
    if (m_dHighestOutput > 0)
    {
   
      if ( (m_vecSmoothPath.size() > 1) && (m_Mode != LEARNING) )
      {
        if (m_dHighestOutput < MATCH_TOLERANCE)
        {
          string s = "I'm guessing this is the pattern " + 
                     m_pData->PatternName(m_iBestMatch); 

          TextOut(surface, 5, 10, s.c_str(), s.size());
        }

        else
        {
          SetTextColor(surface, RGB(0, 0, 255));

          string s = m_pData->PatternName(m_iMatch);
          TextOut(surface, 5, 10, s.c_str(), s.size());

          SetTextColor(surface, RGB(0, 0, 0));

        }
      }

      else if (m_Mode != LEARNING)
      {
        SetTextColor(surface, RGB(255, 0, 0));

        string s = "Not enough points drawn - plz try again";
        TextOut(surface, 5, 10, s.c_str(), s.size());

        SetTextColor(surface, RGB(0, 0, 0));
      }
    }
  }
  
  if (m_vecPath.size() < 1)
  {
    return;
  }
  
  MoveToEx(surface, m_vecPath[0].x, m_vecPath[0].y, NULL);

  for (int vtx=1; vtx<m_vecPath.size(); ++vtx)
  {
    LineTo(surface, m_vecPath[vtx].x, m_vecPath[vtx].y);
  }
  
  //draw the points which make up the smoothed path
  if ((!m_bDrawing) && (m_vecSmoothPath.size() > 0))
  {
    for (int vtx=0; vtx<m_vecPath.size(); ++vtx)
    {
      POINTS pt = m_vecSmoothPath[vtx];

      Ellipse(surface, pt.x-2, pt.y-2, pt.x+2, pt.y+2);
    }
  }	 
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产亲近乱来精品视频| 欧美男人的天堂一二区| 日本欧美韩国一区三区| 亚洲美女视频在线| 亚洲品质自拍视频| 亚洲精品乱码久久久久| 亚洲精品伦理在线| 亚洲国产精品久久人人爱| 一区二区三区视频在线看| 亚洲一区二区欧美日韩| 午夜婷婷国产麻豆精品| 老司机免费视频一区二区| 久久er精品视频| 国产精品一区二区果冻传媒| 亚洲国产精品一区二区久久恐怖片| 亚洲欧洲www| 亚洲精品久久久久久国产精华液| 亚洲国产wwwccc36天堂| 午夜欧美视频在线观看 | 一区二区三区日韩精品视频| 午夜精品久久久久久久久久| 婷婷丁香激情综合| 国产一区二区美女诱惑| av亚洲精华国产精华精| 欧美性色黄大片| 精品乱人伦一区二区三区| 国产精品欧美一级免费| 亚洲国产精品视频| 乱一区二区av| 色婷婷激情久久| 日韩欧美激情在线| 日韩一区欧美一区| 日韩1区2区日韩1区2区| 国产精品一区久久久久| 91麻豆国产福利在线观看| 欧美成人三级电影在线| 国产精品第四页| 日韩国产欧美一区二区三区| 国产91精品免费| 欧美片在线播放| 国产精品久久久久久久久搜平片| 一区二区国产视频| 成人综合在线网站| 欧美一区二区私人影院日本| 国产精品精品国产色婷婷| 奇米四色…亚洲| 色国产综合视频| 国产三级精品在线| 另类小说欧美激情| 欧美日韩国产另类不卡| 国产精品国模大尺度视频| 久草这里只有精品视频| 在线观看精品一区| 亚洲精品一区二区三区影院| 亚洲动漫第一页| 97久久精品人人澡人人爽| 国产日韩亚洲欧美综合| 久久国产精品免费| 欧美久久久一区| 亚洲与欧洲av电影| 日本丰满少妇一区二区三区| 国产清纯在线一区二区www| 久久精品国产亚洲aⅴ| 欧美情侣在线播放| 亚洲国产综合人成综合网站| 国产精品一二二区| 久久综合久久综合九色| 青青国产91久久久久久| 欧美日韩国产大片| 天堂午夜影视日韩欧美一区二区| 色天使色偷偷av一区二区| 国产精品久久久久桃色tv| 国产激情91久久精品导航| 久久久蜜臀国产一区二区| 另类中文字幕网| 精品国产乱码久久久久久久久| 日韩电影在线免费观看| 欧美一区二区在线不卡| 免费看精品久久片| 欧美一区二区三区视频免费 | 日本一区二区三区视频视频| 国产成人精品综合在线观看 | 欧美精品 国产精品| 亚洲福利一区二区| 91精品国产综合久久小美女| 日韩专区欧美专区| 7777精品伊人久久久大香线蕉的 | 成人综合婷婷国产精品久久蜜臀| 久久综合九色综合欧美就去吻| 精品在线免费观看| 欧美国产日韩a欧美在线观看| 成人黄色国产精品网站大全在线免费观看 | 国产日韩欧美不卡在线| 99久久精品免费观看| 亚洲综合在线电影| 91精品国产免费| 精品制服美女丁香| 亚洲私人黄色宅男| 欧美日韩国产首页在线观看| 免费xxxx性欧美18vr| 中文字幕乱码久久午夜不卡| 99久久伊人久久99| 亚洲成精国产精品女| 精品久久久久久最新网址| 不卡视频在线看| 亚洲h动漫在线| 精品国产成人系列| 在线观看一区日韩| 韩国毛片一区二区三区| 久久精品欧美一区二区三区不卡| av欧美精品.com| 免费欧美日韩国产三级电影| 国产精品久久久久久亚洲伦| 欧美日韩中文字幕一区二区| 经典一区二区三区| 亚洲综合激情另类小说区| 久久综合久久99| 欧美亚洲一区二区在线观看| 国产在线不卡一区| 亚洲电影欧美电影有声小说| 久久精品一级爱片| 欧美日本在线播放| jlzzjlzz国产精品久久| 久久精品国产精品亚洲精品| 亚洲欧美国产三级| 国产亚洲va综合人人澡精品| 欧美日韩大陆一区二区| 成人美女在线观看| 美女在线一区二区| 一级精品视频在线观看宜春院| 久久久www免费人成精品| 欧美精品aⅴ在线视频| 91麻豆免费看| 国产成人综合网站| 久久福利资源站| 婷婷综合在线观看| 亚洲成av人片在线观看无码| 国产精品激情偷乱一区二区∴| 久久女同精品一区二区| 日韩区在线观看| 欧美高清激情brazzers| 欧美在线视频日韩| 在线免费一区三区| 色婷婷久久99综合精品jk白丝| 不卡的电影网站| 国产成人综合视频| 国产成人av福利| 国产精一区二区三区| 国产麻豆视频一区| 国产美女视频91| 久久国产精品免费| 国内外成人在线| 国产盗摄精品一区二区三区在线| 久久99精品久久久久久国产越南| 日韩av不卡一区二区| 青青草伊人久久| 精品一区二区久久久| 国产乱码精品一区二区三| 国产一区不卡精品| 成人在线综合网| av高清久久久| 欧美日韩综合一区| 91精品国产综合久久久久久漫画 | 亚洲国产精品久久久久秋霞影院| 亚洲精品国产成人久久av盗摄| 亚洲猫色日本管| 亚洲精品视频自拍| 午夜一区二区三区在线观看| 午夜电影一区二区| 精品一区二区免费在线观看| 国产精品亚洲人在线观看| 成人美女在线观看| 欧美私人免费视频| 欧美电影免费提供在线观看| 国产精品国产三级国产普通话蜜臀| 国产午夜亚洲精品理论片色戒| 中文字幕av在线一区二区三区| 国产精品久久久久久久午夜片| 有坂深雪av一区二区精品| 亚洲v日本v欧美v久久精品| 久久99国产乱子伦精品免费| 国产成人精品www牛牛影视| 91美女视频网站| 91精品国产乱码久久蜜臀| 中文字幕第一页久久| 午夜成人免费视频| 成人开心网精品视频| 9191国产精品| 亚洲国产高清aⅴ视频| 天天操天天干天天综合网| 国产成人在线影院| 欧美视频三区在线播放| 国产人伦精品一区二区| 五月天一区二区三区| 成人激情免费电影网址| 欧美一区二区三区视频免费播放| 国产精品私人影院| 激情综合五月天| 欧美三级蜜桃2在线观看| 日本一区二区成人|