gsmoper.cc

来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 2,227 行 · 第 1/5 页

CC
2,227
字号
//// $Source: /home/gambit/CVS/gambit/sources/gcl/gsmoper.cc,v $// $Date: 2002/08/27 18:57:18 $// $Revision: 1.6 $//// DESCRIPTION:// Implementations for GCL operator functions//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//#include <stdlib.h>#include <ctype.h>#include <sys/types.h>#ifndef __BORLANDC__#include <sys/time.h>#endif#include <time.h>#include "base/base.h"#include "gsm.h"#include "portion.h"#include "gsmfunc.h"#include "math/rational.h"#include "nash/mixedsol.h"#include "nash/behavsol.h"#include "game/nfg.h"#include "game/efg.h"#include "base/system.h"#include "base/base.h"#include "gcmdline.h"//------------------------------------// Utilities for formatting options//------------------------------------NumberPortion _WriteWidth(0);NumberPortion _WritePrecis(6);BoolPortion _WriteExpmode(triFALSE);BoolPortion _WriteQuoted(triTRUE);BoolPortion _WriteListBraces(triTRUE);BoolPortion _WriteListCommas(triTRUE);NumberPortion _WriteListLF(0);NumberPortion _WriteListIndent(2);BoolPortion _WriteSolutionInfo(triFALSE);BoolPortion _WriteSolutionLabels(triFALSE);NumberPortion _WriteGameDecimals(6);static void GSM_SetWriteOptions(void){  Portion::_SetWriteWidth(_WriteWidth.Value());  Portion::_SetWritePrecis(_WritePrecis.Value());  Portion::_SetWriteExpmode(_WriteExpmode.Value());  Portion::_SetWriteQuoted(_WriteQuoted.Value());  Portion::_SetWriteListBraces(_WriteListBraces.Value());  Portion::_SetWriteListCommas(_WriteListCommas.Value());  Portion::_SetWriteListLF(_WriteListLF.Value());  Portion::_SetWriteListIndent(_WriteListIndent.Value());  Portion::_SetWriteSolutionInfo(_WriteSolutionInfo.Value());  Portion::_SetWriteSolutionLabels(_WriteSolutionLabels.Value());  ToTextWidth(_WriteWidth.Value());  ToTextPrecision(_WritePrecis.Value());}//-------// And//-------static Portion *GSM_And(GSM &, Portion **param){  gTriState x = ((BoolPortion *) param[0])->Value();  gTriState y = ((BoolPortion *) param[1])->Value();  if (x == triTRUE && y == triTRUE)        return new BoolPortion(triTRUE);  else if (x == triFALSE || y == triFALSE)    return new BoolPortion(triFALSE);   else    return new BoolPortion(triUNKNOWN);  }//---------// Clear//---------static Portion *GSM_Clear(GSM &gsm, Portion **){  gsm.Clear();  return new BoolPortion(true);}//----------// Divide//----------static Portion *GSM_Divide(GSM &, Portion **param){  if(((NumberPortion*) param[1])->Value() != (gNumber)0)    return new NumberPortion(((NumberPortion*) param[0])->Value() /			     ((NumberPortion*) param[1])->Value());  else    return new NullPortion(porNUMBER);}//--------// Equal//--------static Portion *GSM_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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_Equal_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());}//--------// Exp//--------static Portion *GSM_Exp(GSM &, Portion **param){  return new NumberPortion    (exp((double) ((NumberPortion *) param[0])->Value()));}//---------// Float//---------static Portion *GSM_Float(GSM &, Portion **param){  return new NumberPortion((double) ((NumberPortion *) param[0])->Value());}//------------// Greater//------------static Portion *GSM_Greater_Number(GSM &, Portion **param){  return new BoolPortion(((NumberPortion*) param[0])->Value() >                         ((NumberPortion*) param[1])->Value());}static Portion *GSM_Greater_Text(GSM &, Portion **param){  return new BoolPortion(((TextPortion*) param[0])->Value() >			 ((TextPortion*) param[1])->Value());}//---------------// GreaterEqual//---------------static Portion *GSM_GreaterEqual_Number(GSM &, Portion **param){  return new BoolPortion(((NumberPortion*) param[0])->Value() >=                         ((NumberPortion*) param[1])->Value());}static Portion *GSM_GreaterEqual_Text(GSM &, Portion **param){  return new BoolPortion(((TextPortion*) param[0])->Value() >=			 ((TextPortion*) param[1])->Value());}//--------// Help//--------static Portion *GSM_Help(GSM &gsm, Portion **param){  return gsm.Help(((TextPortion*) param[0])->Value(),		  ((BoolPortion*) param[1])->Value(),		  ((BoolPortion*) param[2])->Value());}//------------// HelpVars//------------static Portion *GSM_HelpVars(GSM &gsm, Portion **param){  return gsm.HelpVars(((TextPortion*) param[0])->Value());}//--------// Input//--------static Portion *GSM_Input(GSM &, Portion **param){  try {    return new InputPortion(*new gFileInput(((TextPortion*) param[0])->Value()));  }  catch (gFileInput::OpenFailed &) {    throw gclRuntimeError((gText) "Error opening file \"" +			  ((TextPortion*) param[0])->Value() + "\"");  }}//-----------------// IntegerDivide//-----------------static Portion *GSM_IntegerDivide(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);}//-------------// IsDefined//-------------static Portion *GSM_IsDefined(GSM &gsm, Portion **param){  if (param[0]->Spec().Type != porREFERENCE)    return new BoolPortion(true);  else    return new BoolPortion(gsm.VarIsDefined(((ReferencePortion *) param[0])->Value()));}static Portion *GSM_IsDefined_Undefined(GSM &, Portion **){  return new BoolPortion(false);}//--------// IsEof//--------static Portion *GSM_IsEof(GSM &, Portion **param){  return new BoolPortion(((InputPortion *) param[0])->Value().eof());}//---------// IsNull//---------static Portion *GSM_IsNull(GSM &, Portion **param){  return new BoolPortion(param[0]->Spec().Type == porNULL);}//---------// Less//---------static Portion *GSM_Less_Number(GSM &, Portion **param){  return new BoolPortion(((NumberPortion*) param[0])->Value() <                         ((NumberPortion*) param[1])->Value());}static Portion *GSM_Less_Text(GSM &, Portion **param){  return new BoolPortion(((TextPortion*) param[0])->Value() <			 ((TextPortion*) param[1])->Value());}//-------------// LessEqual//-------------static Portion *GSM_LessEqual_Number(GSM &, Portion **param){  return new BoolPortion(((NumberPortion*) param[0])->Value() <=

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?