Answers.Body: <p>Evaluation sign should be the colour. Your implementation looks correct to me. I compared yours with:</p>
  
  <blockquote>
    <p><a href="https://chessprogramming.wikispaces.com/Minimax" rel="nofollow noreferrer">https://chessprogramming.wikispaces.com/Minimax</a></p>
  </blockquote>
  
  <p>What you did is conceptually identical to the pseudocode on the page. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-27T02:16:56.500Z
Answers.Text: So for example, if the engine is black, +100 means black is basically up by a hundred points?
Answers.UserDisplayName: Legoboy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-27T02:22:43.383Z
Answers.Text: It's white winning for about a pawn.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-27T02:27:28.013Z
Answers.Text: Ah I misinterpreted your original answer. Thanks for clarifying!
Answers.UserDisplayName: Legoboy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-27T02:09:01.377Z
Answers.LastActivityDate: 2017-10-27T02:21:41.787Z
Answers.LastEditDate: 2017-10-27T02:21:41.787Z
Answers.UserDisplayName: SmallChess
Body: <p>I am trying to code a small chess engine, but I am confused with what the sign of the score means. This is my current minimax algorithm:</p>
  
  <pre><code>INFINITY = 999999
  def minimax(self, depth, color):
      if depth == 0:
          return (1 if color else -1) * self.evaluate()
      if color == WHITE:
          max_value = -INFINITY
          for move in board.generate_moves():
              board.push(move)
              score = minimax(depth - 1, not color)
              board.pop()
              max_value = max(score, max_value)
          return max_value
      else:
          min_value = INFINITY
          for move in board.generate_moves():
              board.push(move)
              score = minimax(depth - 1, not color)
              board.pop()
              min_value = min(score, min_value)
          return min_value
  
  def evaluate(self):
      score = 0
      if board.detect_checkmate():
          return INFINITY
      score += (piece_values[KING] * (piece_count(KING, WHITE) - piece_count(KING, BLACK))
              + piece_values[QUEEN] * (piece_count(QUEEN, WHITE) - piece_count(QUEEN, BLACK))
              + piece_values[ROOK] * (piece_count(ROOK, WHITE) - piece_count(ROOK, BLACK))
              + piece_values[KNIGHT] * (piece_count(KNIGHT, WHITE) - piece_count(KNIGHT, BLACK))
              + piece_values[BISHOP] * (piece_count(BISHOP, WHITE) - piece_count(BISHOP, BLACK))
              + piece_values[PAWN] * (piece_count(PAWN, WHITE) - piece_count(PAWN, BLACK)))
      return score
  </code></pre>
  
  <p>See, what is important isn't the lousy evaluation function I have, I think it is about the sign the evaluation function returns. I am confused about the colors of the players and the maximizing player and minimizing player. Is it that if the engine is playing black, it is the maximizing player? Or is the white always the maximizing player?</p>
  
Tags: <engines><chess-algorithms><minimax>
Title: What does the sign of the score represent in chess engines?
ThreadText: # What does the sign of the score represent in chess engines?
  
  (Asked by: username_0 on 2017-10-27)
  
  I am trying to code a small chess engine, but I am confused with what the sign of the score means. This is my current minimax algorithm:
  
  ```
  INFINITY = 999999
  def minimax(self, depth, color):
      if depth == 0:
          return (1 if color else -1) * self.evaluate()
      if color == WHITE:
          max_value = -INFINITY
          for move in board.generate_moves():
              board.push(move)
              score = minimax(depth - 1, not color)
              board.pop()
              max_value = max(score, max_value)
          return max_value
      else:
          min_value = INFINITY
          for move in board.generate_moves():
              board.push(move)
              score = minimax(depth - 1, not color)
              board.pop()
              min_value = min(score, min_value)
          return min_value
  
  def evaluate(self):
      score = 0
      if board.detect_checkmate():
          return INFINITY
      score += (piece_values[KING] * (piece_count(KING, WHITE) - piece_count(KING, BLACK))
              + piece_values[QUEEN] * (piece_count(QUEEN, WHITE) - piece_count(QUEEN, BLACK))
              + piece_values[ROOK] * (piece_count(ROOK, WHITE) - piece_count(ROOK, BLACK))
              + piece_values[KNIGHT] * (piece_count(KNIGHT, WHITE) - piece_count(KNIGHT, BLACK))
              + piece_values[BISHOP] * (piece_count(BISHOP, WHITE) - piece_count(BISHOP, BLACK))
              + piece_values[PAWN] * (piece_count(PAWN, WHITE) - piece_count(PAWN, BLACK)))
      return score
  
  ```
  
  See, what is important isn't the lousy evaluation function I have, I think it is about the sign the evaluation function returns. I am confused about the colors of the players and the maximizing player and minimizing player. Is it that if the engine is playing black, it is the maximizing player? Or is the white always the maximizing player?
  
  **Tags:** engines, chess-algorithms, minimax
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-27. Score: 0 | Accepted answer
  
  Evaluation sign should be the colour. Your implementation looks correct to me. I compared yours with:
  
  > <https://chessprogramming.wikispaces.com/Minimax>
  
  What you did is conceptually identical to the pseudocode on the page.
  
  > **Comments:**
  > **username_0**: So for example, if the engine is black, +100 means black is basically up by a hundred points?  
  > **username_1**: It's white winning for about a pawn.  
  > **username_0**: Ah I misinterpreted your original answer. Thanks for clarifying!  
  
  ---
  
  