2

Hi guys I have a problem with using stockfish engine which is using UCI protocol. I wanted to play black and the computer white. But so far I think that uci engine has no notion of state and it gives me the same best moves over. I wanted to know if there's a way to set UCI engine to play as black or white so when am playing as white and gives it move in FEN string notation. It will suggest a move to black.

I have the following log below:

...
option name Emergency Move Time type spin default 30 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name Slow Mover type spin default 80 min 10 max 1000
option name UCI_Chess960 type check default false
...

uciok
setoption name Hash value 128
ucinewgame

position startpost moves Ng1f3
info depth 1 seldepth 1 score cp 82 nodes 27 nps 27000 time 1 multipv 1 pv e2e4
info depth 2 seldepth 2 score cp 9 nodes 155 nps 155000 time 1 multipv 1 pv d2d4
 d7d5
info depth 3 seldepth 3 score cp 56 nodes 278 nps 278000 time 1 multipv 1 pv d2d
4 d7d5 g1f3
info depth 4 seldepth 4 score cp 8 nodes 749 nps 749000 time 1 multipv 1 pv d2d4
 g8f6 g1f3 d7d6
...
stop

bestmove e2e4 ponder e7e5

Comment : I make a move e2e4 and computer makes a move e7e5

position startpos e7e5 (based on last computer move)

go infinite
wait (5sec)

bestmove e2e4 ponder e7e5

Why is it still e2e4 ponder e7e5, the same best move as the last one. How can I set it to give a best move for black player (me). What kind of commands do i need to set here? Desperately need your help on this guys. Thanks

EDITED

Guys I really appreciate your healthy discussion over this. But I only understand a few concepts regarding UCI engine.

Here's what I have understood so far. -> There is no FEN to PGN conversion because FEN is the positions of the chess pieces after a number of moves and its not possible to convert it to PGN because FEN doesn't contain the sequence necessary to be converted to PGN -> PGN on the other hand contains the moves of the players in sequence so it can easily be converted to FEN

Right now my problem is that DGTs electronic board only gives FEN where I use it as an input to our application and am still researching on how I can get PGN from it. I know Fritz shows the PGN as well as other GUI's.
Any ideas on where to proceed from here?

  • ponder ponders the opponents best move – john ktejik Apr 3 at 18:07
1

Use the "position fen" command.

For example, take a look at http://support.stockfishchess.org/kb/advanced-topics/uci-protocol. From the example in the link, you could easily change to black's move by

"position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1"

Simply change "... w KQkq" to "... b KQkq". The letter tells the engine which color to move for the position.

To start an infinite analysis, use "go infinite".

Please note that "position startpos" assumes a valid move sequence. Failed to do so will result in undefined behavior - it could crash, do nothing or something else.

Edited:

  1. FEN and PGN are two different things. FEN represents a particular position on the board. PGN is the whole game. You don't convert from one to the other. Talking about conversion is meaningless.

  2. You don't do "position startpos FEN1 FEN2 FEN3 FEN4", please read the UCI specification again. You give the moves with the startpos command, not the position itself.

  3. Stockfish doesn't care how you tell it to reach a particular position.

  4. There is a comment that giving a startpos would be a better way to start a game. But why? Think again, and ask yourself, why?? Why would you think giving a command like "startpos e2e4 e7e5 .... ..... (20 more moves) .... .... " is better than simply giving out the FEN of the position? You typically use a chess GUI to interact with an engine, and the chess GUI must have its own chess-board validator. It's quite easy to generate a FEN string from a validator. However, generating a sequence of moves from the initial position would involve looping over all moves, the complexity of the operation is O(n) where n is the number of moves in the game. Furthermore, you'd have to reserve extra buffer to save the long string. The engine would then have to parse the long string, again this is a slow operation. The startpos is strictly unnecessary.

Edited Again for the poster

PGN can technically be converted into a sequence of FEN positions, but it's meaningless. Nobody does that. Your confusion is all based on the fact that you don't know how to interact with an engine. Don't worry, I'll guide you.

Before you can do anything, you'll need a board generator in your own code. You'll need it because you need something to tell Stockfish what to do, and the only way to do that is with a board generator. Every single chess GUI has it.

Make sure you can use your board generator to convert your position to a FEN or a sequence of moves from the initial position. Either way works, you don't need a PGN. I repeat, you DON'T NEED a PGN to interact with a chess engine. Forget about the PGN, period.

Now, it's easy. You make a move on your physical chess board. Your board generator updates the move and sends the update to Stockfish. The update could be a FEN string or a sequence of moves from the initial position. It doesn't really matter which way you go. I recommend the FEN approach because it'll be easier for you to debug your UCI session.

  • The problem wasn't who's move it is. The problem was that dimas thought the "position startpos moves" command updates the current position, which it doesn't. – BlindKungFuMaster Jan 29 '15 at 12:36
  • hi studentt, thanks for replying. That's an interesting notation. My board doesn't give out KQkq - 01. Am not sure how I can show it either. But right now am just doing trial and error on the commands. From the example you have given, you knew its blacks move because of "b" before KQkq ? – dimas Jan 29 '15 at 12:45
  • @BlindKunfFuMaster The asker states "I wanted to know if there's a way to set UCI engine.." This means he's interested in whether there's a way, the fact that he got confused in the output because he didn't know there was another command. My answer is correct and precise. – SmallChess Jan 29 '15 at 12:50
  • @BlindKungFuMaster He did indeed believed the position was updated, but the real problem was that he actually needed another better way to do what he wanted to do. – SmallChess Jan 29 '15 at 12:51
  • @dimas FEN is a standard. Read en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation If your board doesn't give out KQkq, it's a bug. It's not a correct software. – SmallChess Jan 29 '15 at 12:52
0

When you give the position, you always have to give all the game moves, if you start with 'startpos'. The command basically means: Start with the starting position and then execute all these moves and then start to think …

'position startpos e7e5' is probably just the starting position, because e7e5 isn't a legal move. After all in the starting position it's white to move. (To relinquish the move right you'd have to give a zero move which is 0000, I think.)

So it just isn't thinking about the position you think it is thinking about.

There surely is a way to just update the position held internally by the engine, but I'm too lazy to look it up now.

Edit: As you are a chess-stackexchange (and therefore maybe chess-) newcomer, I also want to add, that possibly you won't have much fun playing against stockfish. The top engines just crush every human player. If your goal is to play an open game with chances for both sides, there are probably better options …

Edit: So actually this is the situation:

  • The DGT-board gives you a FEN.
  • You'll give "position fen FEN" to stockfish.
  • Stockfish gives you a bestmove.
  • You'll give the move to the robot and it executes it on the board.
  • Your human player makes a move.
  • … and back to the first point.
  • Thanks for replying BlindKungfuMaster, so whenever I try to do a position startpos I have to add all the moves made by white and black according to its sequence. Is that correct? – dimas Jan 29 '15 at 7:45
  • Actually am trying to create an application using stockfish engine. I'd be playing with it in order to test if my application is running correctly. But the intended audience for this are players who have better background in chess than I am. Right now am just concerned on how to interface with the engine using the application am developing. – dimas Jan 29 '15 at 7:58
  • Yes, exactly. Is it just a playing app, or do you have something different in mind? – BlindKungFuMaster Jan 29 '15 at 8:12
  • Nope, its a human versus robot. We have a robotic arm that plays the computer using stockfish engine as the ai. The app i am creating will act as interface between the electronic board, stockfish engine and the robotic arm. – dimas Jan 29 '15 at 9:04
  • Ok, cool. Good luck with that. – BlindKungFuMaster Jan 29 '15 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.