Thursday 5 November 2020

A Nasty Problem

I hit a nasty problem when an engine recaptured with the king. Here is a simple example:

1. e4 e5 2. Bc4 Bc5 3. Bxf7+ Kxf7

This created a baffling problem when I had set a long time limit to avoid being timed out. The Novag Citrine would not accept moves and showed a strange rotating display on its LCD. I had a suspicion that the Citrine might be calculating a move. In order to diagnose the problem, I set a shorter time limit. I entered the initial moves for both sides manually on the Citrine board in "referee mode". These moves were acknowledged by the Novag Citrine.

Novag> M   1   e2-e4
Novag> M   1,  e7-e5
Novag> M   2   f1-c4
Novag> M   2,  f8-c5
Novag> M   3   c4xf7


I selected the Stockfish engine, and pressed Start Engine. Stockfish's move was automatically sent to the Novag and acknowledged by Novag (captures have be sent twice with a delay in between).

Novag> M   3,  e8xf7
Novag> M   3,  e8xf7


Making the move on the board involved lifting the black king. Novag took that as an instruction to use its internal engine to make a move for white. (That does not usually happen for engine king moves.) The Citrine flashed this move on the board and sent the move to the Citrine Interface.

Novag> M   4   d1-h5

Stockfish replied before I had a chance to make Novag's reply on the board. Stockfish's move was acknowledged by Novag.

Novag> M   4,  f7-f8

Both moves showed on the Citrine Interface board, which is driven by the Novag acknowledgements. I used the command button to send the "p" command to get Novag's view of the board position:

Novag> Position Board
Novag> .  aa bb cc dd ee ff gg hh
Novag> .8 br bn bb bq    bk bn br 8
Novag> .7 bp bp bp bp ::    bp bp 7
Novag> .6    ::    ::    ::    :: 6
Novag> .5 ::    bb    bp    :: WQ 5
Novag> .4    ::    :: WP ::    :: 4
Novag> .3 ::    ::    ::    ::    3
Novag> .2 WP WP WP WP    WP WP WP 2
Novag> .1 WR WN WB    WK    WN WR 1+
Novag> .  aa bb cc dd ee ff gg hh


That matched the position on the Citrine Interface's board. I turned off the Stockfish engine, and was able to take back the last two moves.

Novag> T   4,  f7-f8
Novag> T   4   d1-h5


Novag then signalled that the time limit had been exceeded, but I was able to continue making moves for both sides. (I could have turned Stockfish back on again to make it move and respond to subsequent moves.)

Novag> M   4   g1-f3
Novag> M   4,  b8-c6


This is a tricky one. I have set the time limit to "ea1", the lowest novice level. That ensures ensures that the Citrine's spurious move happens almost instantly, and it turns off the internal clock. The response is also not likely to be much good, so it does not give much away. There does not appear to be anything that can be done to stop the Citrine's spurious move. If I could be sure that this problem occurred if and only if the Stockfish move was a king capture, I could suppress the spurious Stockfish move. The workaround is to turn off the engine, take back the two spurious moves, make your reply and turn Stockfish back on again. The same applies to any other engine, of course - except for the Citrine engine, where this problem does not occur. Here is the latest Python code.

Some Further Refinements

I have added several refinements to the Python program.

If you click the close button on the Novag Citrine Interface window, or set up the new game position on the Citrine board, you now are offered the option of saving the game. If you click "Yes", the PGN for the game is appended to ChessGames.txt.

If you click on the rightmost button on the top frame, you are offered the option to send a command manually to the Citrine. Sending the "p" command to get the Citrine's view of the board position is sometimes helpful. I have never known that to differ from the position displayed by the interface. Nonetheless, that command sometimes gets rid of strange flashing lights when playing against the Citrine engine. Here is the latest Python code.

Connecting to the Zero from an iPad

The Raspberry Pi Zero W is much smaller than my desktop PC, but it was still using a monitor, keyboard and mouse. That was not very convenient for use with the Novag Citrine. I had an old iPad Mini version 1, and wanted to use that to display the Zero's desktop and control the device. I used the free VNC Viewer remote desktop app to do that.

https://magpi.raspberrypi.org/articles/vnc-raspberry-pi

On the Zero, select:

Menu > Preferences > Raspberry Pi Configuration > Interfaces

Set the VNC radio button to Enabled. A VNC button appears on the right hand side of the menu bar. Click it to open VNC Server, and note the IP address.

Install VNC Viewer on the iPad. Ignore the VNC Connect account login (I blanked the screen and reinstated it). Enter the Zero's IP address and raspberrypi. Type pi and the password. Pinch to zoom out.

To click a button on the Zero with VNC Viewer on the iPad, slide the cursor with one finger to position it over the button (or pull-down or menu item). Then tap the cursor.

Tapping the three dots at the top right hand side of the screen shows a series of options, including bringing up an on-screen keyboard. The Zero can be closed down by tying sudo poweroff in the Zero's terminal.

VNC Viewer worked very well, and was much more convenient for controlling the Citrine than a monitor, keyboard and mouse. VNC Viewer is also available for Android, and indeed for desktop computers. I had considered setting up a web server on the Zero, but VNC Viewer does a good job.

The iPad connects to the Zero via my WiFi router. It is possible to use the Zero to set up a WiFi hot spot (there are several tutorials on the web), but I have not done that.