Skip to content

Commit

Permalink
0.3alpha
Browse files Browse the repository at this point in the history
改善AI
增加對其他模擬器的支援
可自行修正顏色偏差
  • Loading branch information
LFsWang committed Apr 21, 2014
1 parent 3a227bd commit deadc89
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 64 deletions.
3 changes: 2 additions & 1 deletion SmartTOSAI/SmartTOSAI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="baseScreenSizeDef.h" />
<ClInclude Include="config.h" />
<ClInclude Include="IDAstar.h" />
<ClInclude Include="src\BluestackCapture.h" />
<ClInclude Include="src\board.h" />
<ClInclude Include="src\config.h" />
<ClInclude Include="src\configFunction.h" />
<ClInclude Include="src\Path.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
5 changes: 4 additions & 1 deletion SmartTOSAI/SmartTOSAI.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
<ClInclude Include="baseScreenSizeDef.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="config.h">
<ClInclude Include="src\configFunction.h">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="src\config.h">
<Filter>標頭檔</Filter>
</ClInclude>
</ItemGroup>
Expand Down
33 changes: 25 additions & 8 deletions SmartTOSAI/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include"src\BluestackCapture.h"
#include"src\board.h"
#include"src\Path.h"

#include"src\configFunction.h"
#include"IDAstar.h"
using namespace std;

Expand All @@ -35,17 +35,34 @@ int main()
IMAGE img;
Board boardMain;
ostringstream oss;
config globalConfig;
int aiTImeLimit=16;
/*
* Load AI use C++ 11
Init
*/
_mkdir("img");
if(!BoardInit()){
cout<<"color.dat¿ò¥¢©Î·l·´"<<endl;
_getch();
exit(0);
}
if(!LoadConfig(globalConfig)){
if(!CreateConfig(globalConfig)){
cout<<"Config ERROR!"<<endl;
_getch();
exit(0);
}
}
/*
* Load AI use C++ 11
*/

/*
* Intro Massage
*/
cout<<"SmartTOSAI By LFsWang!"<<endl
<<"======================"<<endl
<<"Ver.0.21alpha"<<endl
<<"Ver.0.30alpha"<<endl
<<"Build :"<<__DATE__<<' '<<__TIME__<<endl
<<"======================"<<endl<<endl;
cout<<"Set AI Timelimit (Second) :";
Expand All @@ -59,15 +76,15 @@ int main()
}

cout<<"Find Bluestack"<<endl
<<"Please click your bluestack window to continue..."<<endl;
<<"Please click your TOS window to continue..."<<endl;

/*
* Get BlueStack handle and set enviroment
*/
hwndBluestack=GetBluestackWindow();
if(hwndBluestack==NULL)
{
cout<<"Error while handle Bluestack!"<<endl;pause();
cout<<"Error while handle Screen!"<<endl;pause();
exit(1);
}
if(!SetWindowsTopMost(hwndBluestack))
Expand All @@ -81,7 +98,7 @@ int main()
*/
bool Stopflag=false;
initgraph(500,400);
Sleep(3000);
//Sleep(3000);
int config[2]={0};/*TEST*/
while(true)
{
Expand All @@ -104,7 +121,7 @@ int main()
}
Stopflag=false;
}
if(!CaptureWindowImage(hwndBluestack,&img))
if(!CaptureWindowImage(hwndBluestack,&img,globalConfig))
{
cout<<"Some thing worng! Can\'t get screen!";
break;
Expand Down Expand Up @@ -166,7 +183,7 @@ int main()
//IDAStar(boardMain,&p,&posStart);
outtextxy(0,0,"!");
if(!path.empty()){
applyPath(hwndBluestack,boardMain,path,posStart);
applyPath(hwndBluestack,boardMain,path,posStart,globalConfig);
oss.str("");
oss<<"img\\"<<time(NULL)<<".bmp";
saveimage(oss.str().c_str());
Expand Down
20 changes: 20 additions & 0 deletions SmartTOSAI/color.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
0 20
10 32
108 144
108 144
40 45
38 110
325 350
325 350
190 210
150 210
294 302
250 295

TIP
��
��
��
��
��
�t
21 changes: 0 additions & 21 deletions SmartTOSAI/config.h

This file was deleted.

2 changes: 2 additions & 0 deletions SmartTOSAI/smartTosAi.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35 316 462 671
90
18 changes: 13 additions & 5 deletions SmartTOSAI/src/BluestackCapture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _BLUESTACKCAPTURE_H
#define _BLUESTACKCAPTURE_H

#include<Windows.h>
#include"config.h"

#define BLUESTACK_TEXT "BlueStacks App Player for Windows (beta-1)"
HWND GetBluestackWindow()
Expand All @@ -14,6 +16,9 @@ HWND GetBluestackWindow()
if(strcmp(text,BLUESTACK_TEXT)==0){
return hWnd;
}
if(text[0]=='G'){
return hWnd;
}
}
Sleep(500);
}while(true);
Expand All @@ -26,7 +31,7 @@ inline bool SetWindowsTopMost(HWND hWnd)

#ifdef EASYX
#include<Easyx.h>
bool CaptureWindowImage(HWND hWnd,IMAGE *img)
bool CaptureWindowImage(HWND hWnd,IMAGE *img,const config &cfg)
{
RECT rectWindow;
HDC hdcScreen;
Expand All @@ -35,15 +40,18 @@ bool CaptureWindowImage(HWND hWnd,IMAGE *img)

if(!GetWindowRect(hWnd,&rectWindow))
{return false;}

W=rectWindow.right-rectWindow.left;
H=(rectWindow.bottom-rectWindow.top)/2;
int TOP=cfg.GetTop();
int LEFT=cfg.GetLeft();
int RIGHT=cfg.GetRight();
int DOWN=cfg.GetButtom();
W=RIGHT-LEFT;
H=DOWN-TOP;

hdcScreen =GetDC(NULL);
hdcImg =GetImageHDC(img);

Resize(img,W,H);
if(!BitBlt(hdcImg,0,0,W,H,hdcScreen,rectWindow.left,rectWindow.top+H-40,SRCCOPY))
if(!BitBlt(hdcImg,0,0,W,H,hdcScreen,rectWindow.left+LEFT,rectWindow.top+TOP,SRCCOPY))
{return false;}

ReleaseDC(hWnd,hdcScreen);
Expand Down
41 changes: 25 additions & 16 deletions SmartTOSAI/src/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include"board.h"
#include<sstream>
#include<easyx.h>
#include"config.h"

using std::ostringstream;
using std::vector;

Expand Down Expand Up @@ -33,7 +35,7 @@ class _Pos{
}
};

bool applyPath(HWND hWnd ,Board &bd,vector<int> &path,_Pos &pos)
bool applyPath(HWND hWnd ,Board &bd,vector<int> &path,_Pos &pos,const config &cfg)
{
ostringstream oss;
RECT rectWin;
Expand All @@ -45,17 +47,26 @@ bool applyPath(HWND hWnd ,Board &bd,vector<int> &path,_Pos &pos)

if(!GetClientRect(hWnd,&rectWin))
return false;
winW=rectWin.right-rectWin.left;
winH=(rectWin.bottom-rectWin.top)/2;

int TOP=cfg.GetTop();
int LEFT=cfg.GetLeft();
int RIGHT=cfg.GetRight();
int DOWN=cfg.GetButtom();

winW=RIGHT-LEFT;
winH=DOWN-TOP;
#define ImgX(X) (winW*(2*(X)-1)/12)
#define ImgY(Y) (winH*(2*(Y)-1)/10)
#define RealX(X) (ImgX(X)+LEFT)
#define RealY(Y) (ImgY(Y)+TOP)
/*
#define _X(X) (3+winW*(2*(X)-1)/12)
#define _Y(Y) (int)( winH*(2*(Y)-1)/10.0+winH-40)
#define __Y(YY) (_Y(YY)-winH+40)
*/
antiCheat=3;
SendMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(_X(pos.y),_Y(pos.x)));
//fillcircle(_X(pos.y),__Y(pos.x),15);
moveto(_X(pos.y),__Y(pos.x));
SendMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(RealX(pos.y),RealY(pos.x)));
moveto(ImgX(pos.y),ImgY(pos.x));
Sleep(100);
int fixx,fixy;
for(int &n:path)
Expand All @@ -70,25 +81,23 @@ bool applyPath(HWND hWnd ,Board &bd,vector<int> &path,_Pos &pos)
antiCheat--;
for(int p=1;p<10;++p)
{
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(_X(pos.y)+rand()%5-3,_Y(pos.x)+rand()%5-3));
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(RealX(pos.y)+rand()%5-3,RealY(pos.x)+rand()%5-3));
Sleep(50);
}
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(_X(pos.y)+fixx,_Y(pos.x)+fixy));
lineto(_X(pos.y)+fixx,__Y(pos.x)+fixy);
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(RealX(pos.y)+fixx,RealY(pos.x)+fixy));
lineto(ImgX(pos.y)+fixx,ImgY(pos.x)+fixy);
}
else
{
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(_X(pos.y),_Y(pos.x)));
lineto(_X(pos.y),__Y(pos.x));
SendMessage(hWnd,WM_MOUSEMOVE,MK_LBUTTON,MAKELPARAM(RealX(pos.y),RealY(pos.x)));
lineto(ImgX(pos.y),ImgY(pos.x));
}
Sleep(90);
Sleep(cfg.GetSpeed());
}
MessageBeep(MB_OK);
SendMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(_X(pos.y),_Y(pos.x)));
SendMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(RealX(pos.y),RealY(pos.x)));
return false;
#undef _X
#undef _Y
#undef __Y

}


Expand Down
40 changes: 28 additions & 12 deletions SmartTOSAI/src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class Board{

#ifdef EASYX
#include<easyx.h>
#include<fstream>
double cH[12][2];

bool BoardInit(){
std::ifstream fin("color.dat");
if(!fin)return false;
for(int i=0;i<12;++i){
for(int j=0;j<2;++j){
fin>>cH[i][j];
if(!fin)return false;
if(cH[i][j]<0||cH[i][j]>360)return false;
}
}
return true;
}

bool loadFromImage(Board &bo,IMAGE &img)
{

Expand Down Expand Up @@ -73,18 +89,18 @@ bool loadFromImage(Board &bo,IMAGE &img)
}
H/=9;S/=9;V/=9;

if(H<20&&S>0.89){c=C_FILE;t=T_NORMAL;}//RED OK
else if((10<H&&H<32||i==0&&j==4&&80<H&&H<83) &&V>0.94){c=C_FILE;t=T_STRENGTH;}
else if(108<H&&H<144&&V<0.9){c=C_WOOD;t=T_NORMAL;}//GREEN
else if(108<H&&H<144&&V>0.9){c=C_WOOD;t=T_STRENGTH;}
else if(40 <H&&H<45&&V<0.9){c=C_RAY;t=T_NORMAL;}//YELLOW 41 1 0.7
else if(38 <H&&H<110&&V>0.9){c=C_RAY;t=T_STRENGTH;}//38~108
else if(325<H&&H<350&&V<0.9){c=C_HEART;t=T_NORMAL;}//HEART
else if(325<H&&H<350&&V>0.9){c=C_HEART;t=T_STRENGTH;}
else if(190<H&&H<210&&V<0.9){c=C_WATER;t=T_NORMAL;}//Blue
else if(150<H&&H<210&&V>0.9){c=C_WATER;t=T_STRENGTH;}
else if(295<H&&H<302&&V<0.9){c=C_DARK;t=T_NORMAL;}//Dark 298 0.9 0.6
else if(250<H&&H<295&&V>0.9){c=C_DARK;t=T_STRENGTH;}//290~255 0.36 1
if (cH[0][0] <H&&H<cH[0][1] &&S>0.89){c=C_FILE;t=T_NORMAL;}//RED OK
else if(cH[1][0] <H&&H<cH[1][1] &&V>0.94){c=C_FILE;t=T_STRENGTH;}
else if(cH[2][0] <H&&H<cH[2][1] &&V<0.9){c=C_WOOD;t=T_NORMAL;}//GREEN
else if(cH[3][0] <H&&H<cH[3][1] &&V>0.9){c=C_WOOD;t=T_STRENGTH;}
else if(cH[4][0] <H&&H<cH[4][1] &&V<0.9){c=C_RAY;t=T_NORMAL;}//YELLOW 41 1 0.7
else if(cH[5][0] <H&&H<cH[5][1] &&V>0.9){c=C_RAY;t=T_STRENGTH;}//38~108
else if(cH[6][0] <H&&H<cH[6][1] &&V<0.9){c=C_HEART;t=T_NORMAL;}//HEART
else if(cH[7][0] <H&&H<cH[7][1] &&V>0.9){c=C_HEART;t=T_STRENGTH;}
else if(cH[8][0] <H&&H<cH[8][1] &&V<0.9){c=C_WATER;t=T_NORMAL;}//Blue
else if(cH[9][0] <H&&H<cH[9][1] &&V>0.9){c=C_WATER;t=T_STRENGTH;}
else if(cH[10][0]<H&&H<cH[10][1]&&V<0.9){c=C_DARK;t=T_NORMAL;}//Dark 298 0.9 0.6
else if(cH[11][0]<H&&H<cH[11][1]&&V>0.9){c=C_DARK;t=T_STRENGTH;}//290~255 0.36 1
else{
//Debug info
//setfillcolor(RED);
Expand Down
32 changes: 32 additions & 0 deletions SmartTOSAI/src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _CONFIG_H
#define _CONFIG_H

#include"board.h"
#include"BluestackCapture.h"
#include<fstream>

using std::fstream;
using std::endl;



class config{

int BoardTop;
int BoardLeft;
int BoardButtom;
int BoardRight;
int Speed;
public:
int GetTop()const{return BoardTop;}
int GetLeft()const{return BoardLeft;}
int GetButtom()const{return BoardButtom;}
int GetRight()const{return BoardRight;}
int GetSpeed()const{return Speed;}
friend bool LoadConfig(config &cfg);
friend bool CreateConfig(config &cfg);
friend bool SaveConfig(config &cfg);
};


#endif
Loading

0 comments on commit deadc89

Please sign in to comment.