Answers.Body: <p>I didn't run your code, but by just looking:</p>
  
  <ul>
  <li>You should return the score when <code>score &gt;= beta</code>. This is consistent to Wikipedia:</li>
  </ul>
  
  <p><a href="https://i.sstatic.net/IPAgu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IPAgu.png" alt="enter image description here"></a></p>
  
  <p>Note when alpha >= beta, Wikipedia returns the score, not beta.</p>
  
  <ul>
  <li>Your code doesn't detect checkmate? I don't see how your engine can report Scholar mate without detecting checkmate.</li>
  <li>Minor issue. The condition should be <code>&gt;=</code> not <code>&gt;</code>, but that shouldn't change anything.</li>
  <li>What outputs did you get from: <code>print('New good move ...</code>?</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T05:21:02.960Z
Answers.Text: Previously, when I used my minimal implementation, the engine could prevent simple checkmates. Coincidence???
Answers.UserDisplayName: AggressiveBee15
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T05:21:47.753Z
Answers.Text: @AggresiveBee15 I don't know about your previous implementation, but I don't see how your engine would work if you don't check for end of game by checkmate.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T05:22:42.310Z
Answers.Text: Where would I add the checkmate check? Should I add the check right after the move is pushed?
Answers.UserDisplayName: AggressiveBee15
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T05:23:20.993Z
Answers.Text: In evaluation, if the position is checkmate your evaluator must return infinity.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T13:16:51.337Z
Answers.Text: Also, currently I run the engine with the depth of 3. The game went: 1. e4 a5 2. d4 b5 3. Bxb5  Why did it blunder a pawn? The evaluation function is really basic, but should be able to calculate the material loss.
Answers.UserDisplayName: AggressiveBee15
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T13:20:18.357Z
Answers.Text: @AggresiveBee15 I don't know! Can you please post your sample outputs?
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-04T05:15:59.067Z
Answers.LastActivityDate: 2017-08-04T05:15:59.067Z
Answers.UserDisplayName: SmallChess
Body: <p>I am currently attempting to make a basic chess engine in Python (Learning some basic concepts), but for some reason the engine is suicidal and does not detect the scholars mate. I am using python-chess for the board because I am lazy, but I think the issue is my implementation of negamax? I've read on chessprogramming wiki but still can't figure out the issue.</p>
  
  <p>Here is the code on GitHub: <a href="https://github.com/AggressiveBee15/LousyEngine" rel="nofollow noreferrer">https://github.com/AggressiveBee15/LousyEngine</a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-04T05:08:50.257Z
Comments.Text: Why do I need to add a negative sign? Sorry I don't really understand negamax yet (I was doing separate subroutines before I switched)
Comments.UserDisplayName: AggressiveBee15
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-04T05:11:02.997Z
Comments.Text: If `score >= beta`, you should return the score, not beta.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-04T05:12:47.173Z
Comments.Text: Also, your code doesn't detect checkmate.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-04T05:40:26.310Z
Comments.Text: For the negative sign before the initial call, wikipedia seems to say that a negative sign isn't required before the root negamax call.
Comments.UserDisplayName: AggressiveBee15
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-04T06:11:52.020Z
Comments.Text: Try to add a check for checkmate, and run again. Also post the outputs.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T08:21:26.183Z
Comments.Text: The [community has decided](https://chess.meta.stackexchange.com/q/418/7297) that questions about chess programming are **on-topic**. This is also stated in the [help center](/help/on-topic): *Chess-specific questions about programming a chess engine or other chess software are welcome.*
Comments.UserDisplayName: Glorfindel
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T08:22:34.380Z
Comments.Text: That said, this question should be reduced to an [MCVE](https://stackoverflow.com/help/mcve) as soon as possible; questions should not depend on external links which may break.
Comments.UserDisplayName: Glorfindel
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T13:08:21.417Z
Comments.Text: @Glorfindel I think the question is on-topic. But if it drags on with code-level assistance, it's off-topic. In my answer, I gave general advice but actually running the code is off-topic.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T13:09:49.337Z
Comments.Text: @Glorfindel OP was asking for code-level assistance in the comments to my answer. I don't see how we can possibility answer the question unless it's edited.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T13:12:13.067Z
Comments.Text: Yeah, I agree. Lacking an MCVE is also an off-topic reason. I think one should resort to a custom off-topic reason in those cases, because just saying it's not in scope doesn't help the OP. See also [this Meta question](https://chess.meta.stackexchange.com/q/491/7297).
Comments.UserDisplayName: Glorfindel
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-05T13:38:06.150Z
Comments.Text: Sorry, I'll edit the question to fit the requirements.
Comments.UserDisplayName: AggressiveBee15
Tags: <engines><programming>
Title: What is the problem with my negamax implementation?
ThreadText: # What is the problem with my negamax implementation?
  
  (Asked by: username_0 on 2017-08-04)
  
  I am currently attempting to make a basic chess engine in Python (Learning some basic concepts), but for some reason the engine is suicidal and does not detect the scholars mate. I am using python-chess for the board because I am lazy, but I think the issue is my implementation of negamax? I've read on chessprogramming wiki but still can't figure out the issue.
  
  Here is the code on GitHub: <https://github.com/username_0/LousyEngine>
  
  **Tags:** engines, programming
  
  > **Comments:**
  > **username_0**: Why do I need to add a negative sign? Sorry I don't really understand negamax yet (I was doing separate subroutines before I switched)  
  > **username_1**: If `score >= beta`, you should return the score, not beta.  
  > **username_1**: Also, your code doesn't detect checkmate.  
  > **username_0**: For the negative sign before the initial call, wikipedia seems to say that a negative sign isn't required before the root negamax call.  
  > **username_1**: Try to add a check for checkmate, and run again. Also post the outputs.  
  > **username_2**: The [community has decided](https://chess.meta.stackexchange.com/q/418/7297) that questions about chess programming are **on-topic**. This is also stated in the [help center](/help/on-topic): *Chess-specific questions about programming a chess engine or other chess software are welcome.*  
  > **username_2**: That said, this question should be reduced to an [MCVE](https://stackoverflow.com/help/mcve) as soon as possible; questions should not depend on external links which may break.  
  > **username_1**: @username_2 I think the question is on-topic. But if it drags on with code-level assistance, it's off-topic. In my answer, I gave general advice but actually running the code is off-topic.  
  > **username_1**: @username_2 OP was asking for code-level assistance in the comments to my answer. I don't see how we can possibility answer the question unless it's edited.  
  > **username_2**: Yeah, I agree. Lacking an MCVE is also an off-topic reason. I think one should resort to a custom off-topic reason in those cases, because just saying it's not in scope doesn't help the OP. See also [this Meta question](https://chess.meta.stackexchange.com/q/491/7297).  
  > **username_0**: Sorry, I'll edit the question to fit the requirements.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-08-04. Score: 1
  
  I didn't run your code, but by just looking:
  
  * You should return the score when `score >= beta`. This is consistent to Wikipedia:
  
  [![enter image description here](https://i.sstatic.net/IPAgu.png)](https://i.sstatic.net/IPAgu.png)
  
  Note when alpha >= beta, Wikipedia returns the score, not beta.
  
  * Your code doesn't detect checkmate? I don't see how your engine can report Scholar mate without detecting checkmate.
  * Minor issue. The condition should be `>=` not `>`, but that shouldn't change anything.
  * What outputs did you get from: `print('New good move ...`?
  
  > **Comments:**
  > **username_0**: Previously, when I used my minimal implementation, the engine could prevent simple checkmates. Coincidence???  
  > **username_1**: @AggresiveBee15 I don't know about your previous implementation, but I don't see how your engine would work if you don't check for end of game by checkmate.  
  > **username_0**: Where would I add the checkmate check? Should I add the check right after the move is pushed?  
  > **username_1**: In evaluation, if the position is checkmate your evaluator must return infinity.  
  > **username_0**: Also, currently I run the engine with the depth of 3. The game went: 1. e4 a5 2. d4 b5 3. Bxb5  Why did it blunder a pawn? The evaluation function is really basic, but should be able to calculate the material loss.  
  > **username_1**: @AggresiveBee15 I don't know! Can you please post your sample outputs?  
  
  ---
  
  