gsmoper.cc
来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 2,227 行 · 第 1/5 页
CC
2,227 行
((NumberPortion*) param[1])->Value());}static Portion *GSM_LessEqual_Text(GSM &, Portion **param){ return new BoolPortion(((TextPortion*) param[0])->Value() <= ((TextPortion*) param[1])->Value());}//--------// Log//--------static Portion *GSM_Log(GSM &, Portion **param){ double d = (double) ((NumberPortion *) param[0])->Value(); if(d <= 0.0) return new NullPortion(porNUMBER); else return new NumberPortion(log(d));}//---------// Manual//---------static gText GetLine(gInput &f){ char c = 0; gText result; bool valid = true; while (valid) { try { f >> c; } catch (gFileInput::ReadFailed &) { valid = false; } if (f.eof()) break; if (c != '\n') result += c; else break; } return result;}static Portion *GSM_Manual(GSM &gsm, Portion** param){ gText txt = ((TextPortion*) param[0])->Value(); gOutput& s = ((OutputPortion*) param[1])->Value(); ListPortion *Prototypes = (ListPortion*) gsm.Help(txt, true, true, true); int i; int body = 0; for (i = 1; i <= Prototypes->Length(); i++) { s << ((TextPortion*) (*Prototypes)[i])->Value() << '\n'; } char *name = "gcl.man"; // this change necessary for BC gFileInput* f = NULL; // This section is very inelegantly adopted from gcompile.yy... // This section and its gcompile.yy parallel should be converted into // one function... extern char* _SourceDir; const char* SOURCE = _SourceDir;#ifdef __GNUG__ const char SLASH1= '/'; const char SLASH = '/';#elif defined __BORLANDC__ const char SLASH1= '\\'; const char * SLASH = "\\";#endif // __GNUG__ bool search = false; if (strchr( name, SLASH1 ) == NULL) search = true; gText ManFileName; ManFileName = (gText) name; bool man_found = 0; f = 0; try { f = new gFileInput(ManFileName); } catch (gFileInput::OpenFailed &) { if (search) { if (!man_found && System::GetEnv("HOME") != NULL) { ManFileName = ((gText) System::GetEnv("HOME")) + gText(SLASH) + name; try { f = new gFileInput(ManFileName); } catch(gFileInput::OpenFailed &) { f = NULL; } if(f) { man_found = true;} } if( !man_found && (System::GetEnv( "GCLLIB" ) != NULL) ) { ManFileName = (gText) System::GetEnv("GCLLIB") + gText(SLASH) + name; try{ f = new gFileInput( ManFileName ); } catch(gFileInput::OpenFailed &) { f = NULL; } if (f) {man_found = true;} } if( !man_found && (SOURCE != NULL) ) { ManFileName = (gText) SOURCE + gText(SLASH) + name; try{ f = new gFileInput( ManFileName ); } catch(gFileInput::OpenFailed &) { f = NULL; } if (f) {man_found = true;} } } } // End bad section if (f == NULL) return new BoolPortion(false); gText line; gText line_out; bool found = false; bool valid = true; while(valid && !f->eof() && !found) { try{ line = GetLine(*f); } catch(gFileInput::ReadFailed &) {valid=false;} if(line.Length() > txt.Length()) if( line.Left(txt.Length() + 1).Dncase() == (txt + "[").Dncase() ) found = true; } if(found) { body = 0; bool valid = true; while(valid && !f->eof()) { try{ line = GetLine(*f); } catch(gFileInput::ReadFailed &) {valid = false;} if(line.Length()>=3 && line.Left(3) == "\\bd") body++; if(body > 0) { line_out = line; while(true) { char* s; unsigned int idx; int numchars; if((s=strstr((char *) line_out, "\\bd")) != 0) numchars = 3; else if((s=strstr((char *) line_out, "\\ed")) != 0) numchars = 3; else if((s=strstr((char *) line_out, "\\item")) != 0) numchars = 5; else if((s=strstr((char *) line_out, "\\tt")) != 0) numchars = 4; else if((s=strstr((char *) line_out, "\\em")) != 0) numchars = 4; else if((s=strstr((char *) line_out, "$")) != 0) { idx = s - (char *) line_out; line_out[idx] = '\''; numchars = 0; } else if((s=strstr((char *) line_out, "\\verb")) != 0) { numchars = 5; idx = s - (char *) line_out; for(i=0; i<numchars; i++) line_out.Remove(idx); if(line_out.Length()>idx) { char c; c = line_out[idx]; line_out[idx] = '\"'; while(line_out.Length()>idx) { idx++; if(line_out[idx]==c) break; } line_out[idx] = '\"'; } numchars = 0; } else break; idx = s - (char *) line_out; if(idx>= 0) { // this is necessary to prevent case where Remove() makes idx neg for(i=0; i<numchars; i++) line_out.Remove(idx); if(line_out.Length()>idx && line_out[idx] == ' ') line_out.Remove(idx); } } for(i=0; i<body; i++) s << ' '; s << line_out << '\n'; } if(line.Length()>=3 && line.Left(3) == "\\ed") { body--; if(body <= 0) break; } } } delete f; return new BoolPortion(found);}//---------// Minus//---------static Portion *GSM_Minus_Number(GSM &, Portion **param){ return new NumberPortion(((NumberPortion *) param[0])->Value() - ((NumberPortion *) param[1])->Value());}static Portion *GSM_Minus_Mixed(GSM &, Portion **param){ MixedPortion *result = new MixedPortion(new MixedSolution(*((MixedPortion *) param[0])->Value())); *result->Value() -= *((MixedPortion*) param[1])->Value(); return result;}static Portion *GSM_Minus_Behav(GSM &, Portion** param){ if(((BehavPortion*) param[0])->Value()->Support() != ((BehavPortion*) param[1])->Value()->Support()) throw gclRuntimeError("Support mismatch"); BehavPortion *result = new BehavPortion(new BehavSolution(*((BehavPortion *) param[0])->Value())); *result->Value() -= *((BehavPortion*) param[1])->Value(); return result;}//-----------// Modulus//-----------static Portion *GSM_Modulus(GSM &, Portion **param){ if (((NumberPortion *) param[1])->Value() != (gNumber) 0) { gRational x = ((NumberPortion *) param[0])->Value().operator gRational(); gRational y = ((NumberPortion *) param[1])->Value().operator gRational(); return new NumberPortion(x.numerator() % y.numerator()); } else return new NullPortion(porNUMBER);}//----------// Negate//----------static Portion *GSM_Negate(GSM &, Portion **param){ return new NumberPortion(-((NumberPortion *) param[0])->Value());}//------// Not//------static Portion *GSM_Not(GSM &, Portion **param){ gTriState x = ((BoolPortion *) param[0])->Value(); if (x == triTRUE) return new BoolPortion(triFALSE); else if (x == triFALSE) return new BoolPortion(triTRUE); else return new BoolPortion(triUNKNOWN); }//-----------// NotEqual//-----------static Portion *GSM_NotEqual_Number(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((NumberPortion *) param[0])->Value() != ((NumberPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Text(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((TextPortion *) param[0])->Value() != ((TextPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Boolean(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((BoolPortion *) param[0])->Value() != ((BoolPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Efg(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((EfgPortion *) param[0])->Value() != ((EfgPortion *) param[1])->Value());}static Portion *GSM_NotEqual_EfPlayer(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((EfPlayerPortion *) param[0])->Value() != ((EfPlayerPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Node(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((NodePortion *) param[0])->Value() != ((NodePortion *) param[1])->Value());}static Portion *GSM_NotEqual_Infoset(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((InfosetPortion *) param[0])->Value() != ((InfosetPortion *) param[1])->Value());}static Portion *GSM_NotEqual_EfOutcome(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((EfOutcomePortion *) param[0])->Value() != ((EfOutcomePortion *) param[1])->Value());}static Portion *GSM_NotEqual_Action(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((ActionPortion *) param[0])->Value() != ((ActionPortion *) param[1])->Value());}static Portion *GSM_NotEqual_EfSupport(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion((*((EfSupportPortion *) param[0])->Value()) != (*((EfSupportPortion *) param[1])->Value()));}static Portion *GSM_NotEqual_Behav(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(*((BehavPortion *) param[0])->Value() != *((BehavPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Nfg(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((NfgPortion *) param[0])->Value() != ((NfgPortion *) param[1])->Value());}static Portion *GSM_NotEqual_NfPlayer(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((NfPlayerPortion *) param[0])->Value() != ((NfPlayerPortion *) param[1])->Value());}static Portion *GSM_NotEqual_Strategy(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((StrategyPortion *) param[0])->Value() != ((StrategyPortion *) param[1])->Value());}static Portion *GSM_NotEqual_NfOutcome(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(((NfOutcomePortion *) param[0])->Value() != ((NfOutcomePortion *) param[1])->Value());}static Portion *GSM_NotEqual_NfSupport(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion((*((NfSupportPortion *) param[0])->Value()) != (*((NfSupportPortion *) param[1])->Value()));}static Portion *GSM_NotEqual_Mixed(GSM &, Portion **param){ if ((param[0]->Spec().Type == porNULL) || (param[1]->Spec().Type == porNULL)) return new BoolPortion(param[0]->Spec().Type != param[1]->Spec().Type); else return new BoolPortion(*((MixedPortion *) param[0])->Value() != *((MixedPortion *) param[1])->Value());}//-------// Null
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?