ofeksadlo / lichess-cheat

Simple chess cheat for lichess based on opencv.
19 stars 14 forks source link

AttributeError #4

Closed mikhailhaimovich closed 3 years ago

mikhailhaimovich commented 3 years ago

pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html Enter your starting color (b = black / w = white): w Traceback (most recent call last): File "C:\Users\User\Desktop\lichess-cheat-master\main.py", line 58, in stockfish = Stockfish('C:\stockfish_12_win_x64.exe', parameters={"Threads" : 7, "Ponder" : True, "Minimum Thinking Time": 20, "Skill Level": 20, "Hash":16, "Contempt": 0, "Slow Mover": 84}) File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\stockfish\models.py", line 34, in init path, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1207, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified Exception ignored in: <function Stockfish.del at 0x1567CF18> Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\stockfish\models.py", line 270, in del self.stockfish.kill() AttributeError: 'Stockfish' object has no attribute 'stockfish'

New to Py, wanted to play around with this code vs the computer. This is the error that I am running in to

ofeksadlo commented 3 years ago

1) Have you downloaded stockfish engine from here: https://stockfishchess.org/download/ and pasted it to C:\stockfish_12_win_x64.exe? 2) Does the python script and stockfish engine running on the same drive? Because in another issue that opened. The problem was that the python script and the engine didn't sat on the same drive. So this is most likely the problem.

The exception indicates it cannot find the stockfish engine exe file. And this are the most logical reasons.

mikhailhaimovich commented 3 years ago

Thank you for your reply. I saw that previous issue, and I have both files on the same drive.

I wonder if my syntax in the main.py file is my issue. For example, I saved the stockfish executable on the desktop. Therefore, I edited main.py to say:

stockfish = Stockfish('C:\stockfish_20090216_x64.exe'

This is the exact filename. Could this be my issue? Thank you

ofeksadlo commented 3 years ago

Thank you for your reply. I saw that previous issue, and I have both files on the same drive.

I wonder if my syntax in the main.py file is my issue. For example, I saved the stockfish executable on the desktop. Therefore, I edited main.py to say:

stockfish = Stockfish('C:\stockfish_20090216_x64.exe'

This is the exact filename. Could this be my issue? Thank you

The file name needs to point to the exact path of the stockfish exe file. If the exe file is located as shown:
Then my stockfish path should be C:\stockfish_20090216_x64_bmi2.exe If it's on your desktop the path should be different probably something like: C:\Users\YourUserName\Desktop\stockfish_20090216_x64_bmi2.exe So make sure you point to the right path because the code shouldn't be the problem. Given your exception FileNotFoundError: [WinError 2] The system cannot find the file specified.

mikhailhaimovich commented 3 years ago

Thank you for the response. I found my error and fixed it. Now, it shows the first move, and after making that move, it does not show any more moves after the computer responds. thank you again

ofeksadlo commented 3 years ago

That's wierd. Keep in mind that you need to not click anywhere but the move on the board when it's your turn. The reason is that the program retrive your moves from your clicks on the board. It's not perfect yet In order to avoid missread client moves. 3 conditions needs to be checked to make it perfect:

As of now any click that is not a move will cause the program to missread your move. And any prediction from that point will be wrong.

So the program state right now ain't very stable. But you should still manage to use it. Try not clicking anywhere but the move on the board.

mikhailhaimovich commented 3 years ago

Thank you! I am understanding how it works now. If it detects the player move by clicks, how does it detect the computer's move? Should I run the program from my other monitor, to not obfuscate the view of the board?

ofeksadlo commented 3 years ago

Well I never tested it with 2 monitors but it would probabbly mess up things. Because I use pyautogui to capture the board and as far as I know pyautogui is not really supportive with multiple monitors. You can try it though.

In order to capture the computer moves we snap an image of the board. And then gathering the last move. Using a very simple method the last move of the computer will be marked with green background. So we will have 2 cells one blank green cell where the piece moved from. And one cell with a piece in it with green background color that the cell moved to

Glad to hear everything working well now.