4. Tricky Stuff
Testing Your Plugin
When you run Qianhong with the "plugin_debug" parameter, the "Choose AI Engine" dialog
shows a button you can use to run a set of tests on the plugins. Use this feature to
help ensure your plugin handles the commands correctly.
Piped I/O
Be sure to flush STDOUT after every response!
Response Time
If your AI takes more than a second for the AI and HINTS commands (most engines will),
then you must come up with some way to respond quickly to any incoming command.
The best way is probably to use a separate thread for your AI engine. You
might also use polling, but you'll need to use a non-blocking read for the input.
Notation Conventions
Red is always on the "bottom" for ICCS moves and FEN strings. The following diagram
shows the ICCS notation coordinates and FEN row ordering (rows are described left-to-right):
(Black)
A B C D E F G H I
9 [r][h][e][a][k][a][e][h][r] 9 (first FEN row)
| | | | \|/ | | | |
8 |--+--+--+--+--+--+--+--| 8 (2nd FEN row)
| | | | /|\ | | | |
7 |-[c]-+--+--+--+--+-[c]-| 7 (3rd FEN row)
| | | | | | | | |
6 [p]-+-[p]-+-[p]-+-[p]-+-[p] 6 (4th FEN row)
| | | | | | | | |
5 |-----------------------| 5 (5th FEN row)
| |
4 |-----------------------| 4 (6th FEN row)
| | | | | | | | |
3 (P)-+-(P)-+-(P)-+-(P)-+-(P) 3 (7th FEN row)
| | | | | | | | |
2 |-(C)-+--+--+--+--+-(C)-| 2 (8th FEN row)
| | | | \|/ | | | |
1 |--+--+--+--+--+--+--+--| 1 (9th FEN row)
| | | | /|\ | | | |
0 (R)(H)(E)(A)(K)(A)(E)(H)(R) 0 (last FEN row)
A B C D E F G H I
(Red)
Player Turns
Red goes first, unless a FEN command changes it to black's turn. When the plugin gets an
AI (or HINTS) command, it is to play (or think) for whichever side is to move next.
The AI is never explicitly told which side it is playing.
BG Thinking
If you implement background thinking, you should start thinking after an AI command, and think ahead for the same color that the AI command moved for. If something unexpected comes along (UNDO, BAN, PLAY an unanticipated move, etc.), you'll have to bail on the thinking. Since a plugin is only used for one side of the game (except when a human is playing his/her self--which doesn't use AI commands), you won't get AI commands for both sides of the board.
|