3

My goal is to make a script to finding the most and least likely move an engine will play, and then make a list it. I tried using the scores to make such a list, with the best score equalling the most likely move, but every time I got d ifferent scores for the same position.

After compering high-scoring moves with engine moves with the code engine.play(board, chess.engine.Limit(time=0.100)), I noticed that the engine moves are totally different from the move that have the highest score on my outputs.

When I use the same version from my engine, but onvother sites that have the engine installed, I found that it chooses a different move from what my engine script chooses. I know that the engine is not just a bot who is repeating moves every time, but what's the best way make it as such?

Here is my code if you want to have a look:

import asyncio
import chess
#import chess.uci
import chess.engine
import chess.pgn
import io
from chess.engine import Cp, Mate, MateGiven
#Let's try our code with the starting position of chess:

fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
board = chess.Board(fen)


#Now make sure you give the correct location for your stockfish engine file
#...in the line that follows: e.g., /home/.../stockfish_6_x64


engine = chess.engine.SimpleEngine.popen_uci('/home/shar/Desktop/cheat detect python/stockfish-10-linux/Linux/stockfish_10_x64')

if board.turn: print( 'White to move');
else: print( 'black to move');
counter = 0
while counter < 1:
  # do processing
  counter = counter + 1

  result = engine.play(board, chess.engine.Limit(time=0.100))
  print('the engine move',result.move)

#getting legal moves scores part
for el in board.legal_moves:

    pgn = io.StringIO(board.san(el))

    thnwpgntofen = chess.pgn.read_game(pgn);
    nwinfo = engine.analyse(thnwpgntofen.board(),chess.engine.Limit(time=0.100));



    print(board.san(el),nwinfo.get("score"), nwinfo.get("depth"))



    print("-------------------------");
4
  • This is a chess forum. Why do you expect people to understand code?
    – David
    Commented Aug 20, 2019 at 11:23
  • 3
    @David According to the help center (chess.stackexchange.com/help/on-topic) "Chess-specific questions about programming a chess engine or other chess software are welcome." There was a vote on this in Meta 4 years ago (chess.meta.stackexchange.com/questions/418/…) and the decision was to allow questions like this.
    – Brian Towers
    Commented Aug 20, 2019 at 12:28
  • @BrianTowers This may sound as a novel concept, but not liking something and wanting something banned are two different things! I am just warning the OP that the people in this community may not have the knowledge to give a good answer
    – David
    Commented Aug 20, 2019 at 13:15
  • 1
    @David It is not at all a novel concept although you miss out a third possibility, that of someone voting to close a question. There is one vote to close this question. We both know who cast that vote. I'm just telling you why that vote was denied.
    – Brian Towers
    Commented Aug 20, 2019 at 14:28

1 Answer 1

3

The volatility of the score here is caused by the time limit you have set. With time=0.100 you're restricting the engine to 100 milliseconds. With such a small time limit, there are a lot of small factors that can dramatically change the results. You can try increasing the time limit, or instead of using a time limit you can try a depth limit instead. This will make the engine search to a specific depth, rather than searching for a set amount of time. A depth limit will probably make your results more robust.

An example of depth limit would be:

chess.engine.Limit(depth=20)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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