├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── README.md
├── checkImage
├── agree.png
├── continuePlay.png
├── continueTest.png
├── start.png
└── sure.png
├── chessEngine
├── BOOK.DAT
├── BugCChess.exe
├── Thumbs.db
├── XQSPIRIT.EXE
├── bug8u.exe
├── cyclone.bin
├── cyclone.exe
└── 小虫引擎合集
│ ├── 小虫0523引擎(584K)
│ ├── BugCChess.exe
│ └── Thumbs.db
│ ├── 小虫0612引擎(584K)
│ ├── Thumbs.db
│ └── bugcchess8u.exe
│ └── 所谓的网络开发版0808(1.48M)
│ ├── Thumbs.db
│ └── bug8u.exe
├── chessEngineConfig.properties
├── chessImage
├── 0.png
├── 1.png
├── 10.png
├── 11.png
├── 12.png
├── 13.png
├── 14.png
├── 15.png
├── 16.png
├── 17.png
├── 18.png
├── 19.png
├── 2.png
├── 20.png
├── 21.png
├── 22.png
├── 23.png
├── 24.png
├── 25.png
├── 26.png
├── 27.png
├── 28.png
├── 29.png
├── 3.png
├── 30.png
├── 31.png
├── 32.png
├── 33.png
├── 34.png
├── 35.png
├── 36.png
├── 37.png
├── 38.png
├── 39.png
├── 4.png
├── 40.png
├── 41.png
├── 42.png
├── 43.png
├── 44.png
├── 45.png
├── 46.png
├── 47.png
├── 48.png
├── 49.png
├── 5.png
├── 50.png
├── 51.png
├── 52.png
├── 53.png
├── 54.png
├── 55.png
├── 56.png
├── 57.png
├── 58.png
├── 59.png
├── 6.png
├── 60.png
├── 61.png
├── 62.png
├── 63.png
├── 64.png
├── 65.png
├── 66.png
├── 67.png
├── 68.png
├── 69.png
├── 7.png
├── 70.png
├── 71.png
├── 72.png
├── 73.png
├── 74.png
├── 75.png
├── 76.png
├── 77.png
├── 78.png
├── 79.png
├── 8.png
├── 80.png
├── 81.png
├── 82.png
├── 83.png
├── 84.png
├── 85.png
├── 86.png
├── 87.png
├── 88.png
├── 89.png
├── 9.png
├── a.png
├── a2.png
├── b.png
├── b2.png
├── c.png
├── c2.png
├── k.png
├── k2.png
├── n.png
├── n2.png
├── p.png
├── p2.png
├── r.png
└── r2.png
├── log4j.properties
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── chess
│ ├── StartChessEngine.java
│ ├── command
│ └── StopCommand.java
│ ├── config
│ └── ChessEngineConfig.java
│ ├── constant
│ └── ChessFlag.java
│ ├── model
│ ├── Move.java
│ └── Point.java
│ ├── process
│ └── EngineProcess.java
│ └── utilities
│ ├── ChessEngineUtilities.java
│ ├── FenUtilities.java
│ ├── MouseClickUtilities.java
│ ├── RobotUtilities.java
│ └── ScreenUtilities.java
└── test
└── java
└── com
└── chess
├── App.java
└── Image.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | chess
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 | encoding/=UTF-8
5 | encoding/log4j.properties=UTF-8
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12 | org.eclipse.jdt.core.compiler.source=1.7
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # chess
2 | 新中国象棋外挂(java语言)
3 |
4 | 工作原理:
5 |
6 | 1.抓取屏幕信息
7 |
8 | 2.象棋引擎信息处理
9 |
10 | 3.点击屏幕
11 |
12 | 4.重复以上步骤
13 |
14 | 使用的开源框架:
15 |
16 | openimaj
17 |
18 | 使用:
19 |
20 | 目前只适用于14寸的笔记本,先打开新中国棋盘(注意不要移动棋盘,棋盘不能有其他窗口阻挡),运行StartChessEngine。
21 |
22 | 提示:
23 |
24 | 由于目前只是为了个人刷评测,屏幕抓取没做成适配任何宽高的屏幕,同时也硬编码在代码里面,所有要使用的同学要根据自己的屏幕宽高修改抓取屏幕信息的坐标点。这比较
25 | 不好,不能取来即用。以后有时间在优化!
26 |
--------------------------------------------------------------------------------
/checkImage/agree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/checkImage/agree.png
--------------------------------------------------------------------------------
/checkImage/continuePlay.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/checkImage/continuePlay.png
--------------------------------------------------------------------------------
/checkImage/continueTest.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/checkImage/continueTest.png
--------------------------------------------------------------------------------
/checkImage/start.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/checkImage/start.png
--------------------------------------------------------------------------------
/checkImage/sure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/checkImage/sure.png
--------------------------------------------------------------------------------
/chessEngine/BOOK.DAT:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/BOOK.DAT
--------------------------------------------------------------------------------
/chessEngine/BugCChess.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/BugCChess.exe
--------------------------------------------------------------------------------
/chessEngine/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/Thumbs.db
--------------------------------------------------------------------------------
/chessEngine/XQSPIRIT.EXE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/XQSPIRIT.EXE
--------------------------------------------------------------------------------
/chessEngine/bug8u.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/bug8u.exe
--------------------------------------------------------------------------------
/chessEngine/cyclone.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/cyclone.bin
--------------------------------------------------------------------------------
/chessEngine/cyclone.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/cyclone.exe
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/小虫0523引擎(584K)/BugCChess.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/小虫0523引擎(584K)/BugCChess.exe
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/小虫0523引擎(584K)/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/小虫0523引擎(584K)/Thumbs.db
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/小虫0612引擎(584K)/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/小虫0612引擎(584K)/Thumbs.db
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/小虫0612引擎(584K)/bugcchess8u.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/小虫0612引擎(584K)/bugcchess8u.exe
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/所谓的网络开发版0808(1.48M)/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/所谓的网络开发版0808(1.48M)/Thumbs.db
--------------------------------------------------------------------------------
/chessEngine/小虫引擎合集/所谓的网络开发版0808(1.48M)/bug8u.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessEngine/小虫引擎合集/所谓的网络开发版0808(1.48M)/bug8u.exe
--------------------------------------------------------------------------------
/chessEngineConfig.properties:
--------------------------------------------------------------------------------
1 | goCommand=go depth 13\r\n
2 | #goCommand=go time 86 increase 0\r\n
3 | limitTime=20000
4 | engine=bug8u.exe
--------------------------------------------------------------------------------
/chessImage/0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/0.png
--------------------------------------------------------------------------------
/chessImage/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/1.png
--------------------------------------------------------------------------------
/chessImage/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/10.png
--------------------------------------------------------------------------------
/chessImage/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/11.png
--------------------------------------------------------------------------------
/chessImage/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/12.png
--------------------------------------------------------------------------------
/chessImage/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/13.png
--------------------------------------------------------------------------------
/chessImage/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/14.png
--------------------------------------------------------------------------------
/chessImage/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/15.png
--------------------------------------------------------------------------------
/chessImage/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/16.png
--------------------------------------------------------------------------------
/chessImage/17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/17.png
--------------------------------------------------------------------------------
/chessImage/18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/18.png
--------------------------------------------------------------------------------
/chessImage/19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/19.png
--------------------------------------------------------------------------------
/chessImage/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/2.png
--------------------------------------------------------------------------------
/chessImage/20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/20.png
--------------------------------------------------------------------------------
/chessImage/21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/21.png
--------------------------------------------------------------------------------
/chessImage/22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/22.png
--------------------------------------------------------------------------------
/chessImage/23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/23.png
--------------------------------------------------------------------------------
/chessImage/24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/24.png
--------------------------------------------------------------------------------
/chessImage/25.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/25.png
--------------------------------------------------------------------------------
/chessImage/26.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/26.png
--------------------------------------------------------------------------------
/chessImage/27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/27.png
--------------------------------------------------------------------------------
/chessImage/28.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/28.png
--------------------------------------------------------------------------------
/chessImage/29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/29.png
--------------------------------------------------------------------------------
/chessImage/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/3.png
--------------------------------------------------------------------------------
/chessImage/30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/30.png
--------------------------------------------------------------------------------
/chessImage/31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/31.png
--------------------------------------------------------------------------------
/chessImage/32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/32.png
--------------------------------------------------------------------------------
/chessImage/33.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/33.png
--------------------------------------------------------------------------------
/chessImage/34.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/34.png
--------------------------------------------------------------------------------
/chessImage/35.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/35.png
--------------------------------------------------------------------------------
/chessImage/36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/36.png
--------------------------------------------------------------------------------
/chessImage/37.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/37.png
--------------------------------------------------------------------------------
/chessImage/38.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/38.png
--------------------------------------------------------------------------------
/chessImage/39.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/39.png
--------------------------------------------------------------------------------
/chessImage/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/4.png
--------------------------------------------------------------------------------
/chessImage/40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/40.png
--------------------------------------------------------------------------------
/chessImage/41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/41.png
--------------------------------------------------------------------------------
/chessImage/42.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/42.png
--------------------------------------------------------------------------------
/chessImage/43.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/43.png
--------------------------------------------------------------------------------
/chessImage/44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/44.png
--------------------------------------------------------------------------------
/chessImage/45.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/45.png
--------------------------------------------------------------------------------
/chessImage/46.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/46.png
--------------------------------------------------------------------------------
/chessImage/47.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/47.png
--------------------------------------------------------------------------------
/chessImage/48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/48.png
--------------------------------------------------------------------------------
/chessImage/49.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/49.png
--------------------------------------------------------------------------------
/chessImage/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/5.png
--------------------------------------------------------------------------------
/chessImage/50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/50.png
--------------------------------------------------------------------------------
/chessImage/51.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/51.png
--------------------------------------------------------------------------------
/chessImage/52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/52.png
--------------------------------------------------------------------------------
/chessImage/53.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/53.png
--------------------------------------------------------------------------------
/chessImage/54.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/54.png
--------------------------------------------------------------------------------
/chessImage/55.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/55.png
--------------------------------------------------------------------------------
/chessImage/56.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/56.png
--------------------------------------------------------------------------------
/chessImage/57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/57.png
--------------------------------------------------------------------------------
/chessImage/58.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/58.png
--------------------------------------------------------------------------------
/chessImage/59.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/59.png
--------------------------------------------------------------------------------
/chessImage/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/6.png
--------------------------------------------------------------------------------
/chessImage/60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/60.png
--------------------------------------------------------------------------------
/chessImage/61.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/61.png
--------------------------------------------------------------------------------
/chessImage/62.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/62.png
--------------------------------------------------------------------------------
/chessImage/63.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/63.png
--------------------------------------------------------------------------------
/chessImage/64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/64.png
--------------------------------------------------------------------------------
/chessImage/65.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/65.png
--------------------------------------------------------------------------------
/chessImage/66.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/66.png
--------------------------------------------------------------------------------
/chessImage/67.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/67.png
--------------------------------------------------------------------------------
/chessImage/68.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/68.png
--------------------------------------------------------------------------------
/chessImage/69.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/69.png
--------------------------------------------------------------------------------
/chessImage/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/7.png
--------------------------------------------------------------------------------
/chessImage/70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/70.png
--------------------------------------------------------------------------------
/chessImage/71.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/71.png
--------------------------------------------------------------------------------
/chessImage/72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/72.png
--------------------------------------------------------------------------------
/chessImage/73.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/73.png
--------------------------------------------------------------------------------
/chessImage/74.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/74.png
--------------------------------------------------------------------------------
/chessImage/75.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/75.png
--------------------------------------------------------------------------------
/chessImage/76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/76.png
--------------------------------------------------------------------------------
/chessImage/77.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/77.png
--------------------------------------------------------------------------------
/chessImage/78.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/78.png
--------------------------------------------------------------------------------
/chessImage/79.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/79.png
--------------------------------------------------------------------------------
/chessImage/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/8.png
--------------------------------------------------------------------------------
/chessImage/80.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/80.png
--------------------------------------------------------------------------------
/chessImage/81.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/81.png
--------------------------------------------------------------------------------
/chessImage/82.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/82.png
--------------------------------------------------------------------------------
/chessImage/83.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/83.png
--------------------------------------------------------------------------------
/chessImage/84.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/84.png
--------------------------------------------------------------------------------
/chessImage/85.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/85.png
--------------------------------------------------------------------------------
/chessImage/86.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/86.png
--------------------------------------------------------------------------------
/chessImage/87.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/87.png
--------------------------------------------------------------------------------
/chessImage/88.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/88.png
--------------------------------------------------------------------------------
/chessImage/89.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/89.png
--------------------------------------------------------------------------------
/chessImage/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/9.png
--------------------------------------------------------------------------------
/chessImage/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/a.png
--------------------------------------------------------------------------------
/chessImage/a2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/a2.png
--------------------------------------------------------------------------------
/chessImage/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/b.png
--------------------------------------------------------------------------------
/chessImage/b2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/b2.png
--------------------------------------------------------------------------------
/chessImage/c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/c.png
--------------------------------------------------------------------------------
/chessImage/c2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/c2.png
--------------------------------------------------------------------------------
/chessImage/k.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/k.png
--------------------------------------------------------------------------------
/chessImage/k2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/k2.png
--------------------------------------------------------------------------------
/chessImage/n.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/n.png
--------------------------------------------------------------------------------
/chessImage/n2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/n2.png
--------------------------------------------------------------------------------
/chessImage/p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/p.png
--------------------------------------------------------------------------------
/chessImage/p2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/p2.png
--------------------------------------------------------------------------------
/chessImage/r.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/r.png
--------------------------------------------------------------------------------
/chessImage/r2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/java86/chess/083ddf8125da3e5dd7ad54a03f5e05ff50787a31/chessImage/r2.png
--------------------------------------------------------------------------------
/log4j.properties:
--------------------------------------------------------------------------------
1 | ### set log levels ###
2 | log4j.rootLogger = debug,stdout,D,S
3 |
4 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.Target = System.out
6 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
8 |
9 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
10 | log4j.appender.D.File = /chessLog/chess.log
11 | log4j.appender.D.Append = true
12 | log4j.appender.D.Threshold = INFO
13 | log4j.appender.D.MaxBackupIndex = 10
14 | log4j.appender.D.MaxFileSize =2048KB
15 | log4j.appender.D.layout = org.apache.log4j.PatternLayout
16 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
17 |
18 | log4j.appender.S = org.apache.log4j.DailyRollingFileAppender
19 | log4j.appender.S.File = /chessLog/debug.log
20 | log4j.appender.S.Append = true
21 | log4j.appender.S.Threshold = DEBUG
22 | log4j.appender.S.MaxBackupIndex = 10
23 | log4j.appender.S.MaxFileSize =2048KB
24 | log4j.appender.S.layout = org.apache.log4j.PatternLayout
25 | log4j.appender.S.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.86
6 | chess
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | chess
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 4.12
22 | test
23 |
24 |
25 | org.openimaj
26 | image-processing
27 | 1.3.6
28 |
29 |
30 | org.openimaj
31 | image-feature-extraction
32 | 1.3.6
33 |
34 |
35 | org.openimaj
36 | image-local-features
37 | 1.3.6
38 |
39 |
40 | org.slf4j
41 | slf4j-log4j12
42 | 1.7.2
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/StartChessEngine.java:
--------------------------------------------------------------------------------
1 | package com.chess;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 | import java.util.concurrent.ExecutorService;
6 | import java.util.concurrent.Executors;
7 | import java.util.concurrent.ScheduledExecutorService;
8 | import java.util.concurrent.TimeUnit;
9 |
10 | import org.apache.log4j.Logger;
11 | import org.apache.log4j.PropertyConfigurator;
12 |
13 | import com.chess.command.StopCommand;
14 | import com.chess.process.EngineProcess;
15 | import com.chess.utilities.ChessEngineUtilities;
16 | import com.chess.utilities.RobotUtilities;
17 |
18 | public class StartChessEngine implements Runnable {
19 | public static long requestTime = 0L;
20 | public static boolean hasReturn = false;
21 | private static Logger log ;
22 | static {
23 | PropertyConfigurator.configure("log4j.properties");
24 | log= Logger.getLogger(RobotUtilities.class);
25 | }
26 |
27 | @Override
28 | public void run() {
29 | try {
30 | while (true) {
31 | // 处理准备开始,悔棋,求和。保证当前局面已到我方开始走棋,返回当前棋盘局面。
32 | String fen = RobotUtilities.prepareToPlay();
33 | // 通过fen获取最佳下法
34 | String bestmove = ChessEngineUtilities.getBastMove(fen);
35 | // 通过最佳下法操作鼠标点击
36 | RobotUtilities.playByBestmove(bestmove);
37 | }
38 |
39 | } catch (Exception e) {
40 | e.printStackTrace();
41 | }
42 | }
43 | public static void main(String[] args) throws IOException {
44 | // 使引擎在空闲状态
45 | final OutputStream outputStream = EngineProcess.getOutputStream();
46 | outputStream.write("ucci\r\n".getBytes());
47 | outputStream.write("setoption Hash 256\r\n".getBytes());
48 | outputStream.flush();
49 | // 开始检测定时器,要注意根据限时设置时间,要不会影响引擎的棋力
50 | ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
51 | executor.scheduleAtFixedRate(new StopCommand(), 0, 2000, TimeUnit.MILLISECONDS);
52 | // 开始挂机线程
53 | ExecutorService exec = Executors.newSingleThreadExecutor();
54 | exec.execute(new StartChessEngine());
55 | log.debug("engine starting success!!");
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/command/StopCommand.java:
--------------------------------------------------------------------------------
1 | package com.chess.command;
2 |
3 | import java.io.OutputStream;
4 |
5 | import org.apache.log4j.Logger;
6 |
7 | import com.chess.StartChessEngine;
8 | import com.chess.config.ChessEngineConfig;
9 | import com.chess.process.EngineProcess;
10 |
11 | public class StopCommand implements Runnable {
12 | private static final long LIMITTIME = Integer.valueOf(ChessEngineConfig.limitTime);// 引擎最多可以考虑的时间,超过就要马上返回下法。
13 | private Logger log = Logger.getLogger(StopCommand.class);
14 |
15 | @Override
16 | public void run() {
17 | long currentTimeMillis = System.currentTimeMillis();
18 | if (StartChessEngine.requestTime != 0 && !StartChessEngine.hasReturn
19 | && currentTimeMillis - StartChessEngine.requestTime > LIMITTIME) {
20 | try {
21 | OutputStream outputStream = EngineProcess.getOutputStream();
22 | outputStream.write("stop\r\n".getBytes());
23 | outputStream.flush();
24 | log.debug("stop");
25 | } catch (Exception e) {
26 | e.printStackTrace();
27 | }
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/config/ChessEngineConfig.java:
--------------------------------------------------------------------------------
1 | package com.chess.config;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.FileInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.util.Properties;
8 |
9 | public class ChessEngineConfig {
10 | public static String goCommand;
11 | public static String limitTime;
12 | public static String engine;
13 | static{
14 | init();
15 | }
16 | private static void init() {
17 | Properties prop=new Properties();
18 | try {
19 | InputStream in = new BufferedInputStream (new FileInputStream("chessEngineConfig.properties"));
20 | prop.load(in);
21 | goCommand=prop.getProperty("goCommand");
22 | limitTime=prop.getProperty("limitTime");
23 | engine=prop.getProperty("engine");
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/chess/constant/ChessFlag.java:
--------------------------------------------------------------------------------
1 | package com.chess.constant;
2 |
3 | public enum ChessFlag {
4 | 红车("R"), 红马("N"), 红相("B"), 红仕("A"), 红帅("K"), 红炮("C"), 红兵("P"), 黑车("r"), 黑马("n"), 黑象("b"), 黑士("a"), 黑将("k"), 黑炮("c"), 黑卒("p");
5 |
6 | private String flag;
7 |
8 | ChessFlag(String flag) {
9 | this.flag = flag;
10 | }
11 |
12 | public String getFlag() {
13 | return flag;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/model/Move.java:
--------------------------------------------------------------------------------
1 | package com.chess.model;
2 |
3 | public class Move {
4 | public String flag;
5 | public String bestmove;
6 |
7 | public Move(String flag, String bestmove) {
8 | this.flag = flag;
9 | this.bestmove = bestmove;
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/model/Point.java:
--------------------------------------------------------------------------------
1 | package com.chess.model;
2 |
3 | public class Point {
4 | public int x;
5 | public int y;
6 |
7 | public Point(int x, int y) {
8 | this.x = x;
9 | this.y = y;
10 | }
11 |
12 | @Override
13 | public String toString() {
14 | return "Point [x=" + x + ", y=" + y + "]";
15 | }
16 |
17 | @Override
18 | public boolean equals(Object obj) {
19 | if (obj instanceof Point) {
20 | return ((Point) obj).x == this.x && ((Point) obj).y == this.y;
21 | }
22 | return false;
23 | }
24 |
25 | @Override
26 | public int hashCode() {
27 | return this.x * 30 + this.y * 86;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/process/EngineProcess.java:
--------------------------------------------------------------------------------
1 | package com.chess.process;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 |
7 | import com.chess.config.ChessEngineConfig;
8 |
9 | public class EngineProcess {
10 | private static Process p;
11 | private static InputStream inputStream;
12 | private static OutputStream outputStream;
13 | static {
14 | init();
15 | }
16 |
17 | private static void init() {
18 | final String cmd = "chessEngine/"+ChessEngineConfig.engine;
19 | try {
20 | p = Runtime.getRuntime().exec(cmd);
21 | inputStream = p.getInputStream();
22 | outputStream = p.getOutputStream();
23 | } catch (IOException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 |
28 | public static InputStream getInputStream() {
29 | return inputStream;
30 | }
31 |
32 | public static OutputStream getOutputStream() {
33 | return outputStream;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/utilities/ChessEngineUtilities.java:
--------------------------------------------------------------------------------
1 | package com.chess.utilities;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.OutputStream;
8 |
9 | import org.apache.log4j.Logger;
10 |
11 | import com.chess.StartChessEngine;
12 | import com.chess.config.ChessEngineConfig;
13 | import com.chess.process.EngineProcess;
14 |
15 | public class ChessEngineUtilities {
16 | private static Logger log = Logger.getLogger(ChessEngineUtilities.class);
17 |
18 | public static String getBastMove(String fen) throws IOException {
19 | OutputStream outputStream = EngineProcess.getOutputStream();
20 | outputStream.write(fen.getBytes());
21 | outputStream.write(ChessEngineConfig.goCommand.getBytes());
22 | outputStream.flush();
23 | StartChessEngine.requestTime = System.currentTimeMillis();
24 | StartChessEngine.hasReturn = false;
25 | // 取得命令结果的输出流
26 | InputStream fis = EngineProcess.getInputStream();
27 | // 用一个读输出流类去读
28 | InputStreamReader isr = new InputStreamReader(fis);
29 | // 用缓冲器读行
30 | BufferedReader br = new BufferedReader(isr);
31 | String bestmove = null;
32 | while (true) {
33 | bestmove = br.readLine();
34 | if (bestmove == null)
35 | continue;
36 | if (bestmove.startsWith("bestmove")) {
37 | log.debug(bestmove);
38 | StartChessEngine.hasReturn = true;
39 | return bestmove.substring(9, 13);
40 | } else if (bestmove.startsWith("nobestmove")
41 | ||(System.currentTimeMillis()-StartChessEngine.requestTime)>1000*60*5) {
42 | log.debug(bestmove);
43 | StartChessEngine.hasReturn = true;
44 | return "null";
45 | }
46 | log.debug(bestmove);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/utilities/FenUtilities.java:
--------------------------------------------------------------------------------
1 | package com.chess.utilities;
2 |
3 | import java.awt.AWTException;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Map.Entry;
10 |
11 | import org.openimaj.feature.DoubleFVComparison;
12 | import org.openimaj.image.ImageUtilities;
13 | import org.openimaj.image.MBFImage;
14 | import org.openimaj.image.pixel.statistics.HistogramModel;
15 | import org.openimaj.math.statistics.distribution.MultidimensionalHistogram;
16 |
17 | /**
18 | * 把当前屏幕棋局局面转换成fen,方便调用象棋软件引擎
19 | *
20 | * @author 86
21 | * @date 2017年10月11日 下午4:15:40
22 | */
23 | public class FenUtilities {
24 | private static final Map pieces = new HashMap<>();// 新中国象棋棋子图像,用来对比当前格子是什么棋子
25 | private static final int pieceLineNum = 9;// 新中国象棋一行有几个棋子
26 | // 加载棋子图像
27 | static {
28 | try {
29 | pieces.put("R", ImageUtilities.readMBF(new File("chessImage/r2.png")));
30 | pieces.put("N", ImageUtilities.readMBF(new File("chessImage/n2.png")));
31 | pieces.put("B", ImageUtilities.readMBF(new File("chessImage/b2.png")));
32 | pieces.put("A", ImageUtilities.readMBF(new File("chessImage/a2.png")));
33 | pieces.put("K", ImageUtilities.readMBF(new File("chessImage/k2.png")));
34 | pieces.put("C", ImageUtilities.readMBF(new File("chessImage/c2.png")));
35 | pieces.put("P", ImageUtilities.readMBF(new File("chessImage/p2.png")));
36 | pieces.put("r", ImageUtilities.readMBF(new File("chessImage/r.png")));
37 | pieces.put("n", ImageUtilities.readMBF(new File("chessImage/n.png")));
38 | pieces.put("b", ImageUtilities.readMBF(new File("chessImage/b.png")));
39 | pieces.put("a", ImageUtilities.readMBF(new File("chessImage/a.png")));
40 | pieces.put("k", ImageUtilities.readMBF(new File("chessImage/k.png")));
41 | pieces.put("c", ImageUtilities.readMBF(new File("chessImage/c.png")));
42 | pieces.put("p", ImageUtilities.readMBF(new File("chessImage/p.png")));
43 | for (int i = 0; i < 90; i++) {
44 | pieces.put("s" + i, ImageUtilities.readMBF(new File("chessImage/" + i + ".png")));
45 | }
46 | } catch (IOException e) {
47 | e.printStackTrace();
48 | }
49 |
50 | }
51 |
52 | public static String getFenByImages(List chessImages) {
53 | StringBuilder sb = new StringBuilder();
54 | HistogramModel model = new HistogramModel(4, 4, 4);
55 | double tempMinScore = Double.MAX_VALUE;
56 | int count = 0;
57 | int countSpace = 0;
58 | String tempString = "";
59 | for (MBFImage mbf : chessImages) {
60 | if (count != 0 && count % pieceLineNum == 0) {
61 | if (countSpace != 0) {
62 | sb.append(countSpace + "/");
63 | countSpace = 0;
64 | } else {
65 | sb.append("/");
66 | }
67 | }
68 | for (Entry entry : pieces.entrySet()) {
69 | MBFImage piece = entry.getValue();
70 | model.estimateModel(piece);
71 | MultidimensionalHistogram pieceH = model.histogram.clone();
72 | model.estimateModel(mbf);
73 | MultidimensionalHistogram mbfH = model.histogram.clone();
74 | double distanceScore = pieceH.compare(mbfH, DoubleFVComparison.EUCLIDEAN);
75 | if (distanceScore < tempMinScore) {
76 | tempString = entry.getKey();
77 | tempMinScore = distanceScore;
78 | }
79 | }
80 | // 当前格子没有棋子
81 | if (tempString.contains("s")) {
82 | countSpace++;
83 | count++;
84 | tempMinScore = Double.MAX_VALUE;
85 | tempString = "";
86 | continue;
87 | }
88 | if (countSpace != 0) {
89 | sb.append(countSpace + tempString);
90 | } else {
91 | sb.append(tempString);
92 | }
93 | count++;
94 | countSpace = 0;
95 | tempMinScore = Double.MAX_VALUE;
96 | tempString = "";
97 | }
98 | if (countSpace != 0)
99 | sb.append(countSpace);
100 | return sb.toString();
101 | }
102 |
103 | public static void main(String[] args) throws InterruptedException, AWTException {
104 | List grapChessPiecesByScreen = ScreenUtilities.grapChessPiecesByScreen();
105 | String fenByImages = getFenByImages(grapChessPiecesByScreen);
106 | System.out.println(fenByImages);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/utilities/MouseClickUtilities.java:
--------------------------------------------------------------------------------
1 | package com.chess.utilities;
2 |
3 | import java.awt.AWTException;
4 | import java.awt.Robot;
5 | import java.awt.event.KeyEvent;
6 |
7 | import com.chess.model.Point;
8 |
9 | public class MouseClickUtilities {
10 | public static void clickByXY(int x, int y) throws AWTException {
11 | Robot robot = new Robot();
12 | robot.mouseMove(x, y);
13 | robot.mousePress(KeyEvent.BUTTON1_MASK);
14 | robot.mouseRelease(KeyEvent.BUTTON1_MASK);
15 | }
16 |
17 | public static void clickInOrder(Point[] clickPoints) throws AWTException {
18 | for (Point p : clickPoints)
19 | clickByXY(p.x, p.y);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/utilities/RobotUtilities.java:
--------------------------------------------------------------------------------
1 | package com.chess.utilities;
2 |
3 | import java.awt.AWTException;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.regex.Matcher;
10 | import java.util.regex.Pattern;
11 |
12 | import org.apache.log4j.Logger;
13 | import org.openimaj.image.MBFImage;
14 |
15 | import com.chess.constant.ChessFlag;
16 | import com.chess.model.Move;
17 | import com.chess.model.Point;
18 |
19 | public class RobotUtilities {
20 | private static String flag;// 标明我方是红还是黑
21 | private static String preFen = "/9/9/9/9/9/9/9/9/9/9";// 上一个局面,用于检测对方是否已经下棋。
22 | private static String prePlay = "/9/9/9/9/9/9/9/9/9/9";// 上一个局面,用于检测我方是否已经下棋。
23 | private static String eatFen;// 上一个吃子局面,用于发送给引擎
24 | private static List moves = new ArrayList<>();
25 | private static final String RED = "w";// 红方
26 | private static final String BLACK = "b";// 黑方
27 | private static final List moveflag = Arrays
28 | .asList(new Character[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
29 | 'i' });
30 | private static final Map transMap = new HashMap<>();
31 | private static final String[] checkStrings = new String[] { "b", "r" };
32 | private static Logger log = Logger.getLogger(RobotUtilities.class);
33 | static {
34 | transMap.put('a', 'i');
35 | transMap.put('b', 'h');
36 | transMap.put('c', 'g');
37 | transMap.put('d', 'f');
38 | transMap.put('i', 'a');
39 | transMap.put('h', 'b');
40 | transMap.put('g', 'c');
41 | transMap.put('f', 'd');
42 | transMap.put('e', 'e');
43 | transMap.put('0', '9');
44 | transMap.put('1', '8');
45 | transMap.put('2', '7');
46 | transMap.put('3', '6');
47 | transMap.put('4', '5');
48 | transMap.put('5', '4');
49 | transMap.put('6', '3');
50 | transMap.put('7', '2');
51 | transMap.put('8', '1');
52 | transMap.put('9', '0');
53 | }
54 |
55 | public static void main(String[] args) throws AWTException {
56 | refreshFen("h0g2");
57 | System.out.println(preFen);
58 | }
59 |
60 | public static void playByBestmove(String bestmove) throws AWTException {
61 | // String transBestmove = bestmove;
62 | try {
63 | // if ("b".equals(flag)) {
64 | // transBestmove = transBestmove(bestmove);
65 | // log.debug("trans: " + bestmove);
66 | // }
67 | // 根据bestmove拿到屏幕坐标
68 | Point[] clickPoints = ScreenUtilities.getPointsByBestmove("b"
69 | .equals(flag) ? transBestmove(bestmove) : bestmove);
70 | // 获取当前页面
71 | List grapChessPiecesByScreen = ScreenUtilities
72 | .grapChessPiecesByScreen();
73 | // 获取当前局面的fen
74 | String fenByImages = FenUtilities
75 | .getFenByImages(grapChessPiecesByScreen);
76 | fenByImages = "b".equals(flag) ? transFen(fenByImages)
77 | : fenByImages;
78 | if (!fenByImages.equals(preFen))// 对方重新走棋。
79 | return;
80 | // 依次点击屏幕
81 | MouseClickUtilities.clickInOrder(clickPoints);
82 | // 更新当前局面
83 | String refreshFen = refreshFen(bestmove);
84 | // 更新move局面
85 | refreshMoveFen(refreshFen, bestmove);
86 | } catch (Exception e) {
87 | e.printStackTrace();
88 | }
89 |
90 | }
91 |
92 | private static void refreshMoveFen(String refreshFen, String bestmove) {
93 | if (isEat(refreshFen)) {
94 | // if ("b".equals(flag))
95 | // eatFen = transFen(preFen);
96 | // else
97 | eatFen = preFen;
98 | moves.clear();
99 | } else {
100 | moves.add(new Move(flag, bestmove));
101 | }
102 | }
103 |
104 | private static String transBestmove(String bestmove) {
105 | StringBuilder sb = new StringBuilder();
106 | for (int i = 0; i < 4; i++) {
107 | char charAt = bestmove.charAt(i);
108 | Character character = transMap.get(charAt);
109 | sb.append(character);
110 | }
111 | return sb.toString();
112 | }
113 |
114 | private static String refreshFen(String bestmove) {
115 | String[] lineFens = preFen.split("/");
116 | int length = lineFens.length;
117 | // 处理起点坐标
118 | String startPoint = bestmove.substring(0, 2);
119 | Integer startLineNum = length
120 | - (Integer.valueOf(startPoint.charAt(1)) - 48) - 1;
121 | int startIndexOfLine = moveflag.indexOf(startPoint.charAt(0));
122 | String startlineFen = lineFens[startLineNum];// 找出起点坐标所在行
123 | // 找出位于起点坐标的棋子,移除
124 | char[] startChar = startlineFen.toCharArray();
125 | char[] startCharCopy = charCopy(startChar);
126 | char find = startCharCopy[startIndexOfLine];
127 | startCharCopy[startIndexOfLine] = 0;
128 | // 更新起点所在行的fen
129 | String startReplace = sumSpace(startCharCopy);
130 | lineFens[startLineNum] = startReplace;
131 | // 处理终点坐标
132 | String endPoint = bestmove.substring(2, 4);
133 | Integer endLineNum = length
134 | - (Integer.valueOf(endPoint.charAt(1)) - 48) - 1;
135 | int endIndexOfLine = moveflag.indexOf(endPoint.charAt(0));
136 | String endLineFen = lineFens[endLineNum];// 找出终点坐标所在行
137 | // 找出终点坐标的格子,替换成走棋后的棋子
138 | char[] endChar = endLineFen.toCharArray();
139 | char[] endCharCopy = charCopy(endChar);
140 | endCharCopy[endIndexOfLine] = find;
141 | // 更新终点所在行的fen
142 | String endReplace = sumSpace(endCharCopy);
143 | lineFens[endLineNum] = endReplace;
144 | // 更新fen
145 | StringBuilder sb = new StringBuilder();
146 | for (String s : lineFens) {
147 | sb.append(s).append("/");
148 | }
149 | String preFenR = preFen;
150 | preFen = sb.substring(0, sb.length() - 1);
151 | log.info("playFen:" + preFen);
152 | return preFenR;
153 |
154 | }
155 |
156 | private static String sumSpace(char[] startCharCopy) {
157 | int countSpace = 0;
158 | char[] starCharReplace = new char[9];
159 | for (int i = 0; i < 9; i++) {
160 | char c = startCharCopy[i];
161 | if (c == 0) {
162 | countSpace++;
163 | continue;
164 | }
165 | if (countSpace != 0) {
166 | starCharReplace[i - 1] = (char) (countSpace + 48);
167 | countSpace = 0;
168 | }
169 | starCharReplace[i] = c;
170 | }
171 | if (countSpace != 0)
172 | starCharReplace[8] = (char) (countSpace + 48);
173 | String startReplace = new String(starCharReplace).replaceAll("\0+", "");// 去除空格,char默认值为\0
174 | return startReplace;
175 | }
176 |
177 | private static char[] charCopy(char[] startChar) {
178 | char[] startCharCopy = new char[9];
179 | int startCharLength = startChar.length;
180 | int setIndex = 0;
181 | for (int i = 0; i < startCharLength; i++) {
182 | char c = startChar[i];
183 | boolean digit = Character.isDigit(c);
184 | if (digit) {
185 | setIndex += Integer.valueOf(c) - 48;
186 | } else {
187 | startCharCopy[setIndex] = c;
188 | setIndex++;
189 | }
190 | }
191 | return startCharCopy;
192 | }
193 |
194 | public static String prepareToPlay() throws AWTException,
195 | InterruptedException {
196 | while (true) {
197 | Thread.sleep(3000);
198 | // 检查当前界面
199 | Point p = ScreenUtilities.needClick();
200 | if (p != null) {
201 | // 点击当前屏幕
202 | MouseClickUtilities.clickByXY(p.x, p.y);
203 | preFen = "/9/9/9/9/9/9/9/9/9/9";
204 | eatFen = null;
205 | continue;
206 | }
207 | // 满50步没吃子新中国象棋会弹出提示框,影响棋盘抓取。坑爹,不想去对比画面了,每次抓取的时候都点一下确定的坐标吧,我的是(679,411)
208 | MouseClickUtilities.clickByXY(679, 411);
209 | MouseClickUtilities.clickByXY(679, 411);// 点两次棋子就是等于没点。
210 | // 获取当前页面
211 | List grapChessPiecesByScreen = ScreenUtilities
212 | .grapChessPiecesByScreen();
213 | // 获取当前局面的fen
214 | String fenByImages = FenUtilities
215 | .getFenByImages(grapChessPiecesByScreen);
216 | initTag(fenByImages);
217 | fenByImages = "b".equals(flag) ? transFen(fenByImages)
218 | : fenByImages;
219 | // 对方还没走棋,继续下一个循环
220 | // check
221 | if (check(fenByImages)) {
222 | continue;
223 | }
224 | // 我方没成功走棋
225 | if (fenByImages.equals(prePlay)) {
226 | preFen = "/9/9/9/9/9/9/9/9/9/9";
227 | }
228 | log.debug("oldFen:" + preFen);
229 | log.info("newFen:" + fenByImages);
230 | // 检查有没有吃子
231 | if (isEat(fenByImages)) {
232 | eatFen = fenByImages;
233 | moves.clear();
234 | preFen = fenByImages;
235 | prePlay = fenByImages;
236 | fenByImages = "position fen " + fenByImages + " " + flag
237 | + "\r\n";
238 | } else {
239 | if (eatFen == null)
240 | eatFen = flag.equals("w") ? "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR"
241 | : "RNBAKABNR/9/1C5C1/P1P1P1P1P/9/9/p1p1p1p1p/1c5c1/9/rnbakabnr";
242 | String move = analyzeMove(fenByImages);// 分析对方走了什么棋
243 | String f = flag.equals("w") ? "b" : "w";
244 | moves.add(new Move(f, move));
245 | Move firstMove = moves.get(0);
246 | preFen = fenByImages;
247 | prePlay = fenByImages;
248 | fenByImages = "position fen " + eatFen + " " + firstMove.flag
249 | + " moves " + movesString() + "\r\n";
250 | }
251 | log.debug(fenByImages);
252 | return fenByImages;
253 | }
254 | }
255 |
256 | private static String analyzeMove(String fenByImages) {
257 | String[] eatfens = preFen.split("/");
258 | String[] movefens = fenByImages.split("/");
259 | int[] startPoint = new int[2];
260 | int[] endPoint = new int[2];
261 | int length = movefens.length;
262 | for (int y = 0; y < length; y++) {
263 | String movefen = movefens[y];
264 | String eatfen = eatfens[y];
265 | if (movefen.equals(eatfen))
266 | continue;
267 | char[] movefenchar = charCopy(movefen.toCharArray());
268 | char[] eatfenchar = charCopy(eatfen.toCharArray());
269 | int length2 = movefenchar.length;
270 | for (int x = 0; x < length2; x++) {
271 | char moveX = movefenchar[x];
272 | char eatX = eatfenchar[x];
273 | if (moveX == eatX)
274 | continue;
275 | if (moveX == 0) {
276 | startPoint[0] = x;
277 | startPoint[1] = y;
278 | } else {
279 | endPoint[0] = x;
280 | endPoint[1] = y;
281 | }
282 | }
283 | }
284 | StringBuilder sb = new StringBuilder();
285 | sb.append(moveflag.get(startPoint[0])).append(9 - startPoint[1])
286 | .append(moveflag.get(endPoint[0])).append(9 - endPoint[1]);
287 | return sb.toString();
288 | }
289 |
290 | private static String movesString() {
291 | StringBuilder sb = new StringBuilder();
292 | for (Move s : moves) {
293 | sb.append(s.bestmove).append(" ");
294 | }
295 | return sb.toString().trim();
296 | }
297 |
298 | private static boolean isEat(String fenByImages) {
299 | int chessCount = getChessCount(fenByImages);
300 | int chessCount2 = getChessCount(preFen);
301 | return chessCount != chessCount2;
302 |
303 | }
304 |
305 | private static int getChessCount(String fen) {
306 | int count = 0;
307 | int length = fen.length();
308 | for (int i = 0; i < length; i++) {
309 | char charAt = fen.charAt(i);
310 | if (!Character.isDigit(charAt))
311 | count++;
312 | }
313 | return count;
314 | }
315 |
316 | private static boolean check(String fenByImages) {
317 | if (fenByImages.equals(preFen)
318 | || !fenByImages.contains("k")
319 | || !fenByImages.contains("K")
320 | || ("rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR"
321 | .equals(fenByImages) && "b".equals(flag)))
322 | return true;
323 | for (String check : checkStrings) {
324 | int count = 0;
325 | Pattern p = Pattern.compile(check);
326 | Matcher m = p.matcher(fenByImages);
327 | while (m.find()) {
328 | count++;
329 | }
330 | if (count > 4)
331 | return true;
332 | }
333 | return false;
334 | }
335 |
336 | private static String transFen(String fenByImages) {
337 | StringBuffer sb = new StringBuffer();
338 | int length = fenByImages.length();
339 | for (int i = length - 1; i >= 0; i--) {
340 | sb.append(fenByImages.charAt(i));// 使用StringBuffer从右往左拼接字符
341 | }
342 | return sb.toString();
343 | }
344 |
345 | private static void initTag(String fenByImages) {
346 | int w = fenByImages.indexOf(ChessFlag.红帅.getFlag());
347 | int b = fenByImages.indexOf(ChessFlag.黑将.getFlag());
348 | if (w > b)
349 | flag = RED;
350 | else
351 | flag = BLACK;
352 | }
353 | }
354 |
--------------------------------------------------------------------------------
/src/main/java/com/chess/utilities/ScreenUtilities.java:
--------------------------------------------------------------------------------
1 | package com.chess.utilities;
2 |
3 | import java.awt.AWTException;
4 | import java.awt.Dimension;
5 | import java.awt.Rectangle;
6 | import java.awt.Robot;
7 | import java.awt.Toolkit;
8 | import java.awt.image.BufferedImage;
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.util.ArrayList;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 | import java.util.Map.Entry;
16 |
17 | import javax.imageio.ImageIO;
18 |
19 | import org.openimaj.feature.DoubleFVComparison;
20 | import org.openimaj.image.ImageUtilities;
21 | import org.openimaj.image.MBFImage;
22 | import org.openimaj.image.pixel.statistics.HistogramModel;
23 | import org.openimaj.math.statistics.distribution.MultidimensionalHistogram;
24 |
25 | import com.chess.model.Point;
26 |
27 | /**
28 | * 获取屏幕棋盘中的棋子,棋盘左上角需和屏幕坐标(0,0)对齐
29 | *
30 | * @author 86
31 | * @date 2017年10月11日 下午3:36:37
32 | */
33 | public class ScreenUtilities {
34 | private static final int CChessDefaultWidth = 1022;// 新中国象棋棋盘默认宽度
35 | private static final int CChessDefaultHeight = 734;// 新中国象棋默认高度
36 | private static final int ChessPieceDefaultWidth = 34;// 新中国象棋棋盘格子默认宽度
37 | private static final int ChessPieceDefaultHeight = 28;// 新中国象棋默认格子高度
38 | private static final Point startP = new Point(422, 86);// 车坐标点;
39 | private static final Point[] points = new Point[90];// 可以放棋子的格子坐标
40 | private static final String[] flag = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" };
41 | private static final Map bestmoveMap = new HashMap<>();
42 | private static final Map needCheckPointMBF = new HashMap<>();// 需要检查的点的图像
43 | private static final Map needCheckPoint = new HashMap<>();// 需要检查的点的坐标、宽度和高度
44 | static {
45 | for (int i = 0; i < 90; i++) {
46 | int indexOfLine = i % 9;
47 | int lineNum = i / 9;
48 | points[i] = new Point(startP.x + 57 * indexOfLine, startP.y + 57 * lineNum);
49 |
50 | }
51 | int length = points.length;
52 | for (int index = 0; index < length; index++) {
53 | int flagIndex = index % 9;
54 | int lineNum = 9 - index / 9;
55 | bestmoveMap.put(flag[flagIndex] + lineNum, points[index]);
56 | }
57 | try {
58 | needCheckPointMBF.put(new Point(409, 676), ImageUtilities.readMBF(new File("checkImage/start.png")));
59 | needCheckPointMBF.put(new Point(593, 395), ImageUtilities.readMBF(new File("checkImage/sure.png")));
60 | needCheckPointMBF.put(new Point(584, 394), ImageUtilities.readMBF(new File("checkImage/agree.png")));
61 | needCheckPointMBF.put(new Point(543, 408), ImageUtilities.readMBF(new File("checkImage/continuePlay.png")));
62 | needCheckPointMBF.put(new Point(644, 424), ImageUtilities.readMBF(new File("checkImage/continueTest.png")));
63 | } catch (IOException e) {
64 | e.printStackTrace();
65 | }
66 | needCheckPoint.put(new Point(409, 676), new Integer[] { 53, 29 });
67 | needCheckPoint.put(new Point(593, 395), new Integer[] { 81, 29 });
68 | needCheckPoint.put(new Point(584, 394), new Integer[] { 78, 28 });
69 | needCheckPoint.put(new Point(543, 408), new Integer[] { 101, 24 });
70 | needCheckPoint.put(new Point(644, 424), new Integer[] { 99,26 });
71 | }
72 |
73 | public static List grapChessPiecesByScreen() throws AWTException {
74 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
75 | screenSize.setSize(CChessDefaultWidth, CChessDefaultHeight);
76 | Rectangle screenRectangle = new Rectangle(screenSize);
77 | Robot robot = new Robot();
78 | BufferedImage image = robot.createScreenCapture(screenRectangle);
79 | List chessPiecesMBFImages = new ArrayList<>();
80 | for (Point p : points) {
81 | BufferedImage pointImage = image.getSubimage(p.x, p.y, ChessPieceDefaultWidth, ChessPieceDefaultHeight);
82 | MBFImage createMBFImage = ImageUtilities.createMBFImage(pointImage, true);
83 | chessPiecesMBFImages.add(createMBFImage);
84 | }
85 | return chessPiecesMBFImages;
86 | }
87 |
88 | public static Map grapNeedCheckImageByScreen() throws AWTException {
89 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90 | screenSize.setSize(CChessDefaultWidth, CChessDefaultHeight);
91 | Rectangle screenRectangle = new Rectangle(screenSize);
92 | Robot robot = new Robot();
93 | BufferedImage image = robot.createScreenCapture(screenRectangle);
94 | Map needCheckPointMBF = new HashMap<>();
95 | for (Entry entry : needCheckPoint.entrySet()) {
96 | Point p = entry.getKey();
97 | Integer[] widthAndHeight = entry.getValue();
98 | BufferedImage pointImage = image.getSubimage(p.x, p.y, widthAndHeight[0], widthAndHeight[1]);
99 | MBFImage createMBFImage = ImageUtilities.createMBFImage(pointImage, true);
100 | needCheckPointMBF.put(p, createMBFImage);
101 | }
102 | return needCheckPointMBF;
103 | }
104 |
105 | public static List grapChessPiecesByScreen2() throws AWTException, IOException {
106 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
107 | screenSize.setSize(CChessDefaultWidth, CChessDefaultHeight);
108 | Rectangle screenRectangle = new Rectangle(screenSize);
109 | Robot robot = new Robot();
110 | BufferedImage image = robot.createScreenCapture(screenRectangle);
111 | List chessPiecesMBFImages = new ArrayList<>();
112 | for (int index = 0; index < points.length; index++) {
113 | BufferedImage pointImage = image.getSubimage(points[index].x, points[index].y, ChessPieceDefaultWidth,
114 | ChessPieceDefaultHeight);
115 | File f = new File("chessImage87");
116 | if (!f.exists())
117 | f.mkdirs();
118 | f = new File(f, index + ".png");
119 | ImageIO.write(pointImage, "png", f);
120 | }
121 | return chessPiecesMBFImages;
122 | }
123 | public static List grapChessPiecesByScreen3() throws AWTException, IOException {
124 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
125 | screenSize.setSize(CChessDefaultWidth, CChessDefaultHeight);
126 | Rectangle screenRectangle = new Rectangle(screenSize);
127 | Robot robot = new Robot();
128 | BufferedImage image = robot.createScreenCapture(screenRectangle);
129 | List chessPiecesMBFImages = new ArrayList<>();
130 | BufferedImage pointImage = image.getSubimage(644, 424, 99,
131 | 26);
132 | File f = new File("chessImage87");
133 | if (!f.exists())
134 | f.mkdirs();
135 | f = new File(f, 1 + ".png");
136 | ImageIO.write(pointImage, "png", f);
137 | return chessPiecesMBFImages;
138 | }
139 |
140 | public static void main(String[] args) throws AWTException, InterruptedException, IOException {
141 | grapChessPiecesByScreen3();
142 | }
143 |
144 | public static Point needClick() throws AWTException {
145 | HistogramModel model = new HistogramModel(4, 4, 4);
146 | Map grapNeedCheckImageByScreen = grapNeedCheckImageByScreen();
147 | for (Entry mbf : grapNeedCheckImageByScreen.entrySet()) {
148 | Point key = mbf.getKey();
149 | MBFImage value = mbf.getValue();
150 | MBFImage check = needCheckPointMBF.get(key);
151 | model.estimateModel(check);
152 | MultidimensionalHistogram checkH = model.histogram.clone();
153 | model.estimateModel(value);
154 | MultidimensionalHistogram mbfH = model.histogram.clone();
155 | double distanceScore = checkH.compare(mbfH, DoubleFVComparison.EUCLIDEAN);
156 | if (distanceScore < 0.086) {
157 | Integer[] sizes = needCheckPoint.get(key);
158 | return new Point(key.x + sizes[0] / 2, +key.y + sizes[1] / 2);
159 | }
160 | }
161 | return null;
162 | }
163 |
164 | public static Point[] getPointsByBestmove(String bestmove) {
165 | String firstClick = bestmove.substring(0, 2);
166 | String secondClick = bestmove.substring(2, 4);
167 | Point firstPoint = bestmoveMap.get(firstClick);
168 | Point secondPoint = bestmoveMap.get(secondClick);
169 | return new Point[] { new Point(firstPoint.x + ChessPieceDefaultWidth / 2, firstPoint.y + ChessPieceDefaultHeight / 2),
170 | new Point(secondPoint.x + ChessPieceDefaultWidth / 2, secondPoint.y + ChessPieceDefaultHeight / 2) };
171 |
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/test/java/com/chess/App.java:
--------------------------------------------------------------------------------
1 | package com.chess;
2 |
3 | import java.awt.AWTException;
4 | import java.awt.Dimension;
5 | import java.awt.Rectangle;
6 | import java.awt.Robot;
7 | import java.awt.Toolkit;
8 | import java.awt.image.BufferedImage;
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.net.MalformedURLException;
12 | import java.net.URL;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import org.junit.Test;
17 | import org.openimaj.feature.DoubleFVComparison;
18 | import org.openimaj.feature.local.list.LocalFeatureList;
19 | import org.openimaj.feature.local.matcher.FastBasicKeypointMatcher;
20 | import org.openimaj.feature.local.matcher.LocalFeatureMatcher;
21 | import org.openimaj.feature.local.matcher.consistent.ConsistentLocalFeatureMatcher2d;
22 | import org.openimaj.image.DisplayUtilities;
23 | import org.openimaj.image.ImageUtilities;
24 | import org.openimaj.image.MBFImage;
25 | import org.openimaj.image.colour.RGBColour;
26 | import org.openimaj.image.feature.local.engine.DoGSIFTEngine;
27 | import org.openimaj.image.feature.local.keypoints.Keypoint;
28 | import org.openimaj.image.pixel.statistics.HistogramModel;
29 | import org.openimaj.math.geometry.transforms.estimation.RobustAffineTransformEstimator;
30 | import org.openimaj.math.model.fit.RANSAC;
31 | import org.openimaj.math.statistics.distribution.MultidimensionalHistogram;
32 | import org.openimaj.util.pair.Pair;
33 |
34 | import com.chess.utilities.ScreenUtilities;
35 |
36 | /**
37 | * Hello world!
38 | *
39 | */
40 | public class App {
41 | @Test
42 | public void screenCapture() throws AWTException {
43 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
44 | screenSize.setSize(855, 624);
45 | Rectangle screenRectangle = new Rectangle(screenSize);
46 | Robot robot = new Robot();
47 | robot.delay(5000);
48 | BufferedImage image = robot.createScreenCapture(screenRectangle);
49 | image = image.getSubimage(340, 50, 148, 25);
50 | MBFImage createMBFImage = ImageUtilities.createMBFImage(image, true);
51 | DisplayUtilities.display(createMBFImage);
52 | robot.delay(50000);
53 | // return createMBFImage;
54 | }
55 |
56 | // 比较两个图片相识度
57 | @Test
58 | public void distanceScore() throws IOException {
59 | URL[] imageURLs = new URL[] { new URL("http://users.ecs.soton.ac.uk/dpd/projects/openimaj/tutorial/hist1.jpg"),
60 | new URL("http://users.ecs.soton.ac.uk/dpd/projects/openimaj/tutorial/hist2.jpg"),
61 | new URL("http://users.ecs.soton.ac.uk/dpd/projects/openimaj/tutorial/hist3.jpg") };
62 |
63 | List histograms = new ArrayList();
64 | HistogramModel model = new HistogramModel(4, 4, 4);
65 |
66 | for (URL u : imageURLs) {
67 | model.estimateModel(ImageUtilities.readMBF(u));
68 | histograms.add(model.histogram.clone());
69 | }
70 | double distanceScore = histograms.get(0).compare(histograms.get(1), DoubleFVComparison.EUCLIDEAN);
71 | double distanceScore2 = histograms.get(1).compare(histograms.get(2), DoubleFVComparison.EUCLIDEAN);
72 | System.out.println(distanceScore);
73 | System.out.println(distanceScore2);
74 | }
75 |
76 | @Test
77 | public void distanceScore2() throws IOException, AWTException {
78 | List histograms = new ArrayList();
79 | HistogramModel model = new HistogramModel(4, 4, 4);
80 | model.estimateModel(ImageUtilities.readMBF(new File("D:\\Users\\86\\cut.jpg")));
81 | histograms.add(model.histogram.clone());
82 | model.estimateModel(ScreenUtilities.grapChessPiecesByScreen().get(0));
83 | histograms.add(model.histogram.clone());
84 | double distanceScore = histograms.get(0).compare(histograms.get(1), DoubleFVComparison.EUCLIDEAN);
85 | System.out.println(distanceScore);
86 | }
87 |
88 | // 从图片中查找特定元素
89 | @Test
90 | public void queryImage() throws MalformedURLException, IOException, InterruptedException {
91 | MBFImage query = ImageUtilities.readMBF(new File("D:\\Users\\86\\horse.png"));
92 | MBFImage target = ImageUtilities.readMBF(new File("D:\\Users\\86\\chess2.png"));
93 | DoGSIFTEngine engine = new DoGSIFTEngine();
94 | LocalFeatureList queryKeypoints = engine.findFeatures(query.flatten());
95 | LocalFeatureList targetKeypoints = engine.findFeatures(target.flatten());
96 | RobustAffineTransformEstimator modelFitter = new RobustAffineTransformEstimator(5.0, 15000,
97 | new RANSAC.PercentageInliersStoppingCondition(0.8));
98 | LocalFeatureMatcher matcher = new ConsistentLocalFeatureMatcher2d(
99 | new FastBasicKeypointMatcher(6), modelFitter);
100 | matcher.setModelFeatures(queryKeypoints);
101 | matcher.findMatches(targetKeypoints);
102 | // 每个pair中firstObject属于target,secondObject属于query
103 | List> matches = matcher.getMatches();
104 | List targetMatchPoints = new ArrayList<>();
105 | for (Pair p : matches) {
106 | targetMatchPoints.add(p.firstObject());
107 | }
108 | target.drawPoints(targetMatchPoints, RGBColour.RED, 8);
109 | DisplayUtilities.display(target);
110 | // MBFImage consistentMatches = MatchingUtilities.drawMatches(query,
111 | // target, matches, RGBColour.RED);
112 | // DisplayUtilities.display(consistentMatches);
113 | Thread.sleep(50000);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/test/java/com/chess/Image.java:
--------------------------------------------------------------------------------
1 | package com.chess;
2 |
3 | import java.awt.AWTException;
4 | import java.awt.Dimension;
5 | import java.awt.Rectangle;
6 | import java.awt.Robot;
7 | import java.awt.Toolkit;
8 | import java.awt.image.BufferedImage;
9 | import java.io.File;
10 |
11 | import org.junit.Test;
12 | import org.openimaj.image.DisplayUtilities;
13 |
14 | public class Image {
15 | @Test
16 | public void grapScreen() throws InterruptedException, AWTException {
17 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
18 | screenSize.setSize(954, 681);
19 | Rectangle screenRectangle = new Rectangle(screenSize);
20 | Robot robot = new Robot();
21 | BufferedImage image = robot.createScreenCapture(screenRectangle);
22 | DisplayUtilities.display(image);
23 | robot.delay(60000);
24 | }
25 | @Test
26 | public void path(){
27 | String path = System.getProperty("user.dir");
28 | System.out.println(new File("chessEngine/BugCChess.exe").getPath());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------