Variant VariableExpression::set(VariableEnvironment &env, CVarRef val) const {
    Variant &lhs = lval(env);
    if (RuntimeOption::EnableStrict) {
        if (!checkCompatibleAssignment(lhs, val)) {
            throw_strict(TypeVariableChangeException(location_to_string(loc())),
                         StrictMode::StrictHardCore);
        }
    }
    return lhs = val;
}
Variant IncOpExpression::evalUncommon(
  LvalExpression *lval, Variant &left, CVarRef right,
  bool inc, const Location &self, const Location *other) {
  if (RuntimeOption::EnableStrict) {
    if (!VariableExpression::CheckCompatibleAssignment(left, right)) {
      // inline SET_LINE
      if (!set_line(self.line0, self.char0, self.line1, self.char1)) {
        return Variant::lvalBlackHole();
      }
      throw_strict(TypeVariableChangeException(
                   location_to_string(other)),
                   StrictMode::StrictHardCore);
    }
  }
  // inline SET_LINE
  if (!set_line(self.line0, self.char0, self.line1, self.char1)) {
    return Variant::lvalBlackHole();
  }
  return lval->setOpVariant(left, inc ? (int)T_INC : (int)T_DEC, right);
}
Beispiel #3
0
static void
replay_node(SGFNode *node, int color_to_replay, float *replay_score,
	    float *total_score)
{
  SGFProperty *sgf_prop;  /* iterate over properties of the node */
  SGFProperty *move_prop = NULL; /* remember if we see a move property */
  int color; /* color of move to be made at this node. */
  
  int old_move; /* The move played in the file. */
  int new_move; /* The move generated by GNU Go. */

  char buf[BUFSIZE];

  /* Handle any AB / AW properties, and note presence
   * of move properties.
   */

  for (sgf_prop = node->props; sgf_prop; sgf_prop = sgf_prop->next) {
    switch (sgf_prop->name) {
    case SGFAB:
      /* add black */
      add_stone(get_sgfmove(sgf_prop), BLACK);
      break;
    case SGFAW:
      /* add white */
      add_stone(get_sgfmove(sgf_prop), WHITE);
      break;
    case SGFB:
    case SGFW:
      move_prop = sgf_prop;  /* remember it for later */
      break;
    }
  }

  /* Only generate moves at move nodes. */
  if (!move_prop)
    return;

  old_move = get_sgfmove(move_prop);
  color = (move_prop->name == SGFW) ? WHITE : BLACK;

  if (color == color_to_replay || color_to_replay == GRAY) {
    float new_move_value = 0.0;
    float old_move_value = 0.0;
  
    /* Get a move from the engine for color. */
    int resign;
    new_move = genmove(color, NULL, &resign);
    
    /* Pick up the relevant values from the potential_moves[] array. */
    if (new_move != PASS_MOVE)
      new_move_value = potential_moves[new_move]; 
    if (old_move != PASS_MOVE)
      old_move_value = potential_moves[old_move];
    
    /* Now report on how well the computer generated the move. */
    if (new_move != old_move || !quiet) {
      mprintf("Move %d (%C): ", movenum + 1, color);
    
      if (resign)
	printf("GNU Go resigns ");
      else {
	mprintf("GNU Go plays %1m ", new_move);
	if (new_move != PASS_MOVE)
	  printf("(%.2f) ", new_move_value);
      }
      
      mprintf("- Game move %1m ", old_move);
      if (new_move != PASS_MOVE && old_move_value > 0.0)
	printf("(%.2f) ", old_move_value);
      printf("\n");

      *replay_score += new_move_value - old_move_value;
      *total_score += new_move_value;
    }
    
    if (new_move != old_move) {
      if (resign)
	gg_snprintf(buf, BUFSIZE, "GNU Go resigns - Game move %s (%.2f)",
		    location_to_string(old_move), old_move_value);
      else {      
	gg_snprintf(buf, BUFSIZE,
		    "GNU Go plays %s (%.2f) - Game move %s (%.2f)",
		    location_to_string(new_move), new_move_value,
		    location_to_string(old_move), old_move_value);
	if (new_move != PASS_MOVE)
	  sgfCircle(node, I(new_move), J(new_move));
      }
    }
    else
      gg_snprintf(buf, BUFSIZE, "GNU Go plays the same move %s (%.2f)",
		  location_to_string(new_move), new_move_value);
    
    sgfAddComment(node, buf);
    sgffile_add_debuginfo(node, 0.0);
  }

  /* Finally, do play the move from the file. */
  play_move(old_move, color);
}