⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 efgshow.cc

📁 Gambit 是一个游戏库理论软件
💻 CC
📖 第 1 页 / 共 4 页
字号:
//// $Source: /home/gambit/CVS/gambit/sources/gui/efgshow.cc,v $// $Date: 2002/09/30 20:10:17 $// $Revision: 1.84.2.8 $//// DESCRIPTION:// Implementation of extensive form viewing frame//// 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 "wx/wxprec.h"#ifndef WX_PRECOMP#include "wx/wx.h"#endif  // WX_PRECOMP#include "wx/notebook.h"#include "wx/fontdlg.h"#include "wx/printdlg.h"#include "dlspinctrl.h"#include "wxstatus.h"#include "math/gmath.h"#include "game/efg.h"#include "game/infoset.h"#include "game/node.h"#include "game/efplayer.h"#include "game/efgutils.h"#include "nash/behavsol.h"#include "game/nfg.h"#include "nash/efgqre.h"#include "efgconst.h"#include "treewin.h"#include "efgprint.h"#include "efgshow.h"#include "efgprofile.h"#include "efgnavigate.h"#include "efgoutcome.h"#include "efgsupport.h"#include "nfgshow.h"#include "dlinsertmove.h"#include "dlefgdelete.h"#include "dlefgreveal.h"#include "dleditnode.h"#include "dleditmove.h"#include "dleditefg.h"#include "dlefglayout.h"#include "dlefglegend.h"#include "dlefgcolor.h"#include "dlelimbehav.h"#include "dlefgnash.h"#include "dlqrefile.h"#include "dlreport.h"#include "dleditbehav.h"//=====================================================================//                 Implementation of class EfgShow//=====================================================================const int idTREEWINDOW = 999;const int idNODEWINDOW = 998;const int idTOOLWINDOW = 997;const int idSOLUTIONWINDOW = 996;const int idINFONOTEBOOK = 995;BEGIN_EVENT_TABLE(EfgShow, wxFrame)  EVT_MENU(wxID_NEW, EfgShow::OnFileNew)  EVT_MENU(wxID_OPEN, EfgShow::OnFileOpen)  EVT_MENU(wxID_CLOSE, EfgShow::Close)  EVT_MENU(wxID_SAVE, EfgShow::OnFileSave)  EVT_MENU(wxID_SAVEAS, EfgShow::OnFileSave)  EVT_MENU(wxID_PRINT_SETUP, EfgShow::OnFilePageSetup)  EVT_MENU(wxID_PREVIEW, EfgShow::OnFilePrintPreview)  EVT_MENU(wxID_PRINT, EfgShow::OnFilePrint)  EVT_MENU(wxID_EXIT, EfgShow::OnFileExit)  EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, EfgShow::OnFileMRUFile)  EVT_MENU(wxID_CUT, EfgShow::OnEditCut)  EVT_MENU(wxID_COPY, EfgShow::OnEditCopy)  EVT_MENU(wxID_PASTE, EfgShow::OnEditPaste)  EVT_MENU(efgmenuEDIT_INSERT, EfgShow::OnEditInsert)  EVT_MENU(efgmenuEDIT_DELETE, EfgShow::OnEditDelete)  EVT_MENU(efgmenuEDIT_REVEAL, EfgShow::OnEditReveal)  EVT_MENU(efgmenuEDIT_TOGGLE_SUBGAME, EfgShow::OnEditToggleSubgame)  EVT_MENU(efgmenuEDIT_MARK_SUBGAME_TREE, EfgShow::OnEditMarkSubgameTree)  EVT_MENU(efgmenuEDIT_UNMARK_SUBGAME_TREE, EfgShow::OnEditUnmarkSubgameTree)  EVT_MENU(efgmenuEDIT_NODE, EfgShow::OnEditNode)  EVT_MENU(efgmenuEDIT_MOVE, EfgShow::OnEditMove)  EVT_MENU(efgmenuEDIT_GAME, EfgShow::OnEditGame)  EVT_MENU(efgmenuVIEW_PROFILES, EfgShow::OnViewProfiles)  EVT_MENU(efgmenuVIEW_NAVIGATION, EfgShow::OnViewCursor)  EVT_MENU(efgmenuVIEW_OUTCOMES, EfgShow::OnViewOutcomes)  EVT_MENU(efgmenuVIEW_SUPPORTS, EfgShow::OnViewSupports)  EVT_MENU(efgmenuVIEW_ZOOMIN, EfgShow::OnViewZoomIn)  EVT_MENU(efgmenuVIEW_ZOOMOUT, EfgShow::OnViewZoomOut)  EVT_MENU(efgmenuVIEW_SUPPORT_REACHABLE, EfgShow::OnViewSupportReachable)  EVT_MENU(efgmenuFORMAT_FONTS_ABOVENODE, EfgShow::OnFormatFontsAboveNode)  EVT_MENU(efgmenuFORMAT_FONTS_BELOWNODE, EfgShow::OnFormatFontsBelowNode)  EVT_MENU(efgmenuFORMAT_FONTS_AFTERNODE, EfgShow::OnFormatFontsAfterNode)  EVT_MENU(efgmenuFORMAT_FONTS_ABOVEBRANCH, EfgShow::OnFormatFontsAboveBranch)  EVT_MENU(efgmenuFORMAT_FONTS_BELOWBRANCH, EfgShow::OnFormatFontsBelowBranch)  EVT_MENU(efgmenuFORMAT_DISPLAY_LAYOUT, EfgShow::OnFormatDisplayLayout)  EVT_MENU(efgmenuFORMAT_DISPLAY_LEGEND, EfgShow::OnFormatDisplayLegend)  EVT_MENU(efgmenuFORMAT_DISPLAY_COLORS, EfgShow::OnFormatDisplayColors)  EVT_MENU(efgmenuFORMAT_DISPLAY_DECIMALS, EfgShow::OnFormatDisplayDecimals)  EVT_MENU(efgmenuTOOLS_DOMINANCE, EfgShow::OnToolsDominance)  EVT_MENU(efgmenuTOOLS_EQUILIBRIUM, EfgShow::OnToolsEquilibrium)  EVT_MENU(efgmenuTOOLS_QRE, EfgShow::OnToolsQre)  EVT_MENU(efgmenuTOOLS_NFG_REDUCED, EfgShow::OnToolsNormalReduced)  EVT_MENU(efgmenuTOOLS_NFG_AGENT, EfgShow::OnToolsNormalAgent)  EVT_MENU(wxID_ABOUT, EfgShow::OnHelpAbout)  EVT_MENU(efgmenuSUPPORT_DUPLICATE, EfgShow::OnSupportDuplicate)  EVT_MENU(efgmenuSUPPORT_DELETE, EfgShow::OnSupportDelete)  EVT_MENU(efgmenuPROFILES_NEW, EfgShow::OnProfilesNew)  EVT_MENU(efgmenuPROFILES_DUPLICATE, EfgShow::OnProfilesDuplicate)  EVT_MENU(efgmenuPROFILES_DELETE, EfgShow::OnProfilesDelete)  EVT_MENU(efgmenuPROFILES_PROPERTIES, EfgShow::OnProfilesProperties)  EVT_MENU(efgmenuPROFILES_REPORT, EfgShow::OnProfilesReport)  EVT_LIST_ITEM_ACTIVATED(idEFG_SOLUTION_LIST, EfgShow::OnProfilesProperties)  EVT_LIST_ITEM_SELECTED(idEFG_SOLUTION_LIST, EfgShow::OnProfileSelected)  EVT_SET_FOCUS(EfgShow::OnFocus)  EVT_SIZE(EfgShow::OnSize)  EVT_CLOSE(EfgShow::OnCloseWindow)  EVT_SASH_DRAGGED_RANGE(idSOLUTIONWINDOW, idTREEWINDOW, EfgShow::OnSashDrag)  EVT_NOTEBOOK_PAGE_CHANGED(idINFONOTEBOOK, EfgShow::OnInfoNotebookPage)END_EVENT_TABLE()//---------------------------------------------------------------------//               EfgShow: Constructor and destructor//---------------------------------------------------------------------EfgShow::EfgShow(efgGame &p_efg, wxWindow *p_parent)  : wxFrame(p_parent, -1, "", wxPoint(0, 0), wxSize(600, 400)),    m_efg(p_efg), m_treeWindow(0),     m_cursor(0), m_copyNode(0), m_cutNode(0),    m_currentProfile(0), m_profileTable(0), m_solutionSashWindow(0),    m_navigateWindow(0), m_outcomeWindow(0), m_supportWindow(0){  SetSizeHints(300, 300);  // Give the frame an icon#ifdef __WXMSW__  SetIcon(wxIcon("efg_icn"));#else#include "bitmaps/efg.xbm"  SetIcon(wxIcon(efg_bits, efg_width, efg_height));#endif  CreateStatusBar();  wxAcceleratorEntry entries[7];  entries[0].Set(wxACCEL_CTRL, (int) 'N', wxID_NEW);  entries[1].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN);  entries[2].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE);  entries[3].Set(wxACCEL_CTRL, (int) 'P', wxID_PRINT);  entries[4].Set(wxACCEL_CTRL, (int) 'C', wxID_COPY);  entries[5].Set(wxACCEL_CTRL, (int) 'V', wxID_PASTE);  entries[6].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);  wxAcceleratorTable accel(7, entries);  SetAcceleratorTable(accel);  MakeMenus();  MakeToolbar();    m_currentSupport = new EFSupport(m_efg);  m_currentSupport->SetName("Full Support");  m_supports.Append(m_currentSupport);  m_nodeSashWindow = new wxSashWindow(this, idNODEWINDOW,				      wxPoint(0, 40), wxSize(200, 200),				      wxNO_BORDER | wxSW_3D);  m_nodeSashWindow->SetSashVisible(wxSASH_RIGHT, true);  m_treeWindow = new TreeWindow(this, this);  m_treeWindow->SetSize(200, 40, 200, 200);  m_treeWindow->RefreshTree();  m_treeWindow->RefreshLayout();  m_infoNotebook = new wxNotebook(m_nodeSashWindow, idINFONOTEBOOK);  m_navigateWindow = new EfgNavigateWindow(this, m_infoNotebook);  m_navigateWindow->Set(m_cursor);  m_navigateWindow->SetSize(200, 200);  m_infoNotebook->AddPage(m_navigateWindow, "Navigation");  m_outcomeWindow = new EfgOutcomeWindow(this, m_infoNotebook);  m_outcomeWindow->UpdateValues();  m_navigateWindow->SetSize(200, 200);  m_infoNotebook->AddPage(m_outcomeWindow, "Outcomes");  m_supportWindow = new EfgSupportWindow(this, m_infoNotebook);  m_supportWindow->SetSize(200, 200);  m_infoNotebook->AddPage(m_supportWindow, "Supports");  m_infoNotebook->SetSelection(0);  m_nodeSashWindow->Show(false);  m_nodeSashWindow->SetSashVisible(wxSASH_LEFT, false);    m_solutionSashWindow = new wxSashWindow(this, idSOLUTIONWINDOW,					  wxDefaultPosition,					  wxSize(600, 100));  m_solutionSashWindow->SetSashVisible(wxSASH_TOP, true);  m_profileTable = new EfgProfileList(this, m_solutionSashWindow);  m_profileTable->Show(false);  m_solutionSashWindow->Show(false);  m_efg.SetIsDirty(false);  AdjustSizes();  m_treeWindow->FitZoom();  Show(true);  // Force this at end to make sure item is unchecked; under MSW,  // the ordering of events in creating the window leaves this checked  GetMenuBar()->Check(efgmenuVIEW_NAVIGATION, false);  UpdateMenus();}EfgShow::~EfgShow(){  wxGetApp().RemoveGame(&m_efg);}//---------------------------------------------------------------------//               EfgShow: Manipulation of profile list//---------------------------------------------------------------------void EfgShow::ChangeProfile(int sol){  m_currentProfile = sol;  m_treeWindow->RefreshLabels();  if (m_navigateWindow) {    m_navigateWindow->Set(m_cursor);  }  if (m_profileTable) {    m_profileTable->UpdateValues();  }}void EfgShow::RemoveProfile(int p_profile){  m_profiles.Remove(p_profile);  if (m_currentProfile == p_profile) {    m_currentProfile = (m_profiles.Length() > 0) ? 1 : 0;  }  else if (m_currentProfile > p_profile) {    m_currentProfile--;  }  m_treeWindow->RefreshLabels();    if (m_navigateWindow) {    m_navigateWindow->Set(m_cursor);  }  if (m_profileTable) {    m_profileTable->UpdateValues();  }}void EfgShow::RemoveProfiles(void){  m_currentProfile = 0;  m_profiles.Flush();  if (m_navigateWindow) {    m_navigateWindow->Set(m_cursor);  }}const BehavSolution &EfgShow::GetCurrentProfile(void) const{  return m_profiles[m_currentProfile];}void EfgShow::AddProfile(const BehavSolution &p_profile, bool p_map){  if (p_profile.GetName() == "") {    BehavSolution tmp(p_profile);    tmp.SetName(UniqueProfileName());    m_profiles.Append(tmp);  }  else {    m_profiles.Append(p_profile);  }  if (m_efg.AssociatedNfg() && p_map) {    MixedSolution mixed(MixedProfile<gNumber>(*p_profile.Profile()),			p_profile.Creator());    wxGetApp().GetWindow(m_efg.AssociatedNfg())->AddProfile(mixed, false);  }  m_profileTable->UpdateValues();  UpdateMenus();}gText EfgShow::UniqueProfileName(void) const{  int number = m_profiles.Length() + 1;  while (1) {    int i;    for (i = 1; i <= m_profiles.Length(); i++) {      if (m_profiles[i].GetName() == "Profile" + ToText(number)) {	break;      }    }    if (i > m_profiles.Length())      return "Profile" + ToText(number);        number++;  }}gText EfgShow::GetRealizProb(const Node *p_node) const{  if (m_currentProfile == 0 || !p_node) {    return "";  }  return ToText(m_profiles[m_currentProfile].RealizProb(p_node),		NumDecimals());}gText EfgShow::GetBeliefProb(const Node *p_node) const{  if (m_currentProfile == 0 || !p_node || !p_node->GetPlayer()) {    return "";  }  return ToText(m_profiles[m_currentProfile].BeliefProb(p_node),		NumDecimals());}gText EfgShow::GetNodeValue(const Node *p_node) const{  if (m_currentProfile == 0 || !p_node) {    return "";  }  gText tmp = "(";  for (int pl = 1; pl <= m_efg.NumPlayers(); pl++) {    tmp += ToText(m_profiles[m_currentProfile].NodeValue(p_node)[pl], 		  NumDecimals());    if (pl < m_efg.NumPlayers()) {      tmp += ",";    }    else {      tmp += ")";    }  }  return tmp;}gText EfgShow::GetInfosetProb(const Node *p_node) const{  if (m_currentProfile == 0 || !p_node || !p_node->GetPlayer()) {    return "";  }  return ToText(m_profiles[m_currentProfile].IsetProb(p_node->GetInfoset()),		NumDecimals());}gText EfgShow::GetInfosetValue(const Node *p_node) const{  if (m_currentProfile == 0 || !p_node || !p_node->GetPlayer() ||      p_node->GetPlayer()->IsChance()) {    return "";  }  if (GetCurrentProfile().IsetProb(p_node->GetInfoset()) > gNumber(0)) {    return ToText(GetCurrentProfile().IsetValue(p_node->GetInfoset()),		  NumDecimals());  }  else {    // this is due to a bug in the value computation    return "";  }}gText EfgShow::GetActionProb(const Node *p_node, int p_act) const{  if (p_node->GetPlayer() && p_node->GetPlayer()->IsChance()) {    return ToText(m_efg.GetChanceProb(p_node->GetInfoset(), p_act),		  NumDecimals());  }  if (m_currentProfile == 0 || !p_node->GetPlayer()) {    return "";  }  return ToText(GetCurrentProfile().ActionProb(p_node->GetInfoset()->Actions()[p_act]),		NumDecimals());}gText EfgShow::GetActionValue(const Node *p_node, int p_act) const{  if (m_currentProfile == 0 || !p_node || !p_node->GetPlayer() ||      p_node->GetPlayer()->IsChance()) {    return "";  }  if (GetCurrentProfile().IsetProb(p_node->GetInfoset()) > gNumber(0)) {    return ToText(GetCurrentProfile().ActionValue(p_node->GetInfoset()->Actions()[p_act]),		  NumDecimals());  }  else  {    // this is due to a bug in the value computation    return "";  }}gNumber EfgShow::ActionProb(const Node *p_node, int p_action) const{  if (p_node->GetPlayer() && p_node->GetPlayer()->IsChance()) {    return m_efg.GetChanceProb(p_node->GetInfoset(), p_action);  }  if (m_currentProfile && p_node->GetInfoset()) {    return m_profiles[m_currentProfile](p_node->GetInfoset()->Actions()[p_action]);  }  return -1;}//---------------------------------------------------------------------//            EfgShow: Coordinating updates of child windows//---------------------------------------------------------------------void EfgShow::OnOutcomesEdited(void){

⌨️ 快捷键说明

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