void ReadNewUser() { userFirstLine = 1; inputCount = 0; ClearUserVariables(); ResetTopicSystem(); // set his random seed bool hasUpperCharacters; unsigned int rand = (unsigned int) Hashit((unsigned char *) loginID,strlen(loginID),hasUpperCharacters); char word[MAX_WORD_SIZE]; randIndex = rand & 4095; sprintf(word,"%d",randIndex); SetUserVariable("$randindex",word ); strcpy(word,computerID); word[0] = toUppercaseData[(unsigned char)word[0]]; SetUserVariable("$bot",word ); SetUserVariable("$login",loginName); sprintf(readBuffer,"^%s",computerID); WORDP D = FindWord(readBuffer,0,LOWERCASE_LOOKUP); if (!D) { ReportBug("Cannot find bot %s\r\n",computerID); return; } int oldjump = jumpIndex; char* macroArgumentList = AllocateBuffer(); *macroArgumentList = 0; globalDepth = 2; unsigned int result; currentOutputBase = macroArgumentList; DoFunction(D->word,macroArgumentList,macroArgumentList,result); globalDepth = 0; jumpIndex = oldjump; // return to old error handler FreeBuffer(); }
void InitChatbot(char* name) { // initialize system InitSystem(0,NULL); InitStandalone(); SetUserVariable("$loebner","1"); // treat each invocation as a new judge FILE* in = fopen("counter.txt","rb"); int judgeid = 0; char buffer[1000]; if (in) { fread(buffer,1,100,in); fclose(in); judgeid = atoi(buffer); } ++judgeid; FILE* out = fopen("counter.txt","wb"); fprintf(out,"%d\r\n",judgeid); fclose(out); // read in last sequence id to hopefully send ok on restart. in = fopen("sequence", "rb"); if (in) { fgets(buffer,1000,in); fclose(in); sequence = atoi(buffer); } sprintf(buffer,"judge%d",judgeid); strcpy(loginID,buffer); ourMainInputBuffer[0] = 0; PerformChat(loginID,"",ourMainInputBuffer,NULL,ourMainOutputBuffer); // start up chat with a judge, swallow first message ProcessOOB(ourMainOutputBuffer); // process relevant out of band messaging and remove }
double CParseTreeNode::Evaluate(bool log /* = false */){ write_log(preferences.debug_formula(), "[CParseTreeNode] Evaluating node type %i %s\n", _node_type, TokenString(_node_type)); p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number); // Most common types first: numbers and identifiers if (_node_type == kTokenNumber) { write_log(preferences.debug_formula(), "[CParseTreeNode] Number evaluates to %6.3f\n", _constant_value); return _constant_value; } else if (_node_type == kTokenIdentifier) { assert(_first_sibbling == NULL); assert(_second_sibbling == NULL); assert(_third_sibbling == NULL); assert(_terminal_name != ""); double value = EvaluateIdentifier(_terminal_name, log); write_log(preferences.debug_formula(), "[CParseTreeNode] Identifier evaluates to %6.3f\n", value); // In case of f$-functions the line changed inbetween, // so we have to set it to the current location (again) // for the next log. p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number); return value; } // Actions second, which are also "unary". // We have to encode all possible outcomes in a single floating-point, // therefore: // * positive values mean: raise size (by big-blinds, raise-to-semantics) // * negative values mean: elementary actions else if (_node_type == kTokenActionRaiseToBigBlinds) { // RaiseTo N Force return EvaluateSibbling(_first_sibbling, log); } else if (_node_type == kTokenActionRaiseByBigBlinds) { // RaiseBy N Force double raise_by_amount_in_bblinds = EvaluateSibbling(_first_sibbling, log); double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets() + raise_by_amount_in_bblinds; write_log(preferences.debug_formula(), "[CParseTreeNode] raiseby = %.2f ncallbets = %.2f final = %.2f\n", raise_by_amount_in_bblinds, p_symbol_engine_chip_amounts->ncallbets(), final_betsize_in_bblinds); return final_betsize_in_bblinds; } else if (_node_type == kTokenActionRaiseByPercentagedPotsize) { // RaiseBy X% Force double raise_by_percentage = EvaluateSibbling(_first_sibbling, log); assert(p_symbol_engine_tablelimits->bet() > 0); double pot_size_after_call_in_big_blinds = (p_symbol_engine_chip_amounts->pot() / p_symbol_engine_tablelimits->bet()) + p_symbol_engine_chip_amounts->nbetstocall(); assert(pot_size_after_call_in_big_blinds >= 0); double raise_by_amount_in_bblinds = 0.01 * raise_by_percentage * pot_size_after_call_in_big_blinds; double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets() + raise_by_amount_in_bblinds; write_log(preferences.debug_formula(), "[CParseTreeNode] raiseby percentage = %.2f pot after call = %.2f raiseby = %.2f final = %.2f\n", raise_by_percentage, pot_size_after_call_in_big_blinds, raise_by_amount_in_bblinds, final_betsize_in_bblinds); return final_betsize_in_bblinds; } else if (_node_type == kTokenActionUserVariableToBeSet) { // User-variables are a special case of elementary actions // Therefore need to be handled first. SetUserVariable(_terminal_name); return kUndefinedZero; } else if (TokenIsElementaryAction(_node_type)) { return (0 - _node_type); } // Finally operators else if (TokenIsUnary(_node_type)) { return EvaluateUnaryExpression(log); } else if (TokenIsBinary(_node_type)) { return EvaluateBinaryExpression(log); } else if (TokenIsTernary(_node_type)) { return EvaluateTernaryExpression(log); } assert(false); return kUndefined; }