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

📄 nfgtable.cc

📁 Gambit 是一个游戏库理论软件
💻 CC
📖 第 1 页 / 共 2 页
字号:
//// $Source: /home/gambit/CVS/gambit/sources/gui/nfgtable.cc,v $// $Date: 2002/09/12 18:52:41 $// $Revision: 1.12.2.3 $//// DESCRIPTION:// Implementation of normal form table class//// 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/config.h"#include "nfgshow.h"#include "nfgtable.h"#include "nfgconst.h"//-----------------------------------------------------------------------//               class NfgTableSettings: Member functions//-----------------------------------------------------------------------NfgTableSettings::NfgTableSettings(void){  LoadSettings();}void NfgTableSettings::SaveFont(const wxString &p_prefix, 				wxConfig &p_config, const wxFont &p_font){  p_config.Write(p_prefix + "Size", (long) p_font.GetPointSize());  p_config.Write(p_prefix + "Family", (long) p_font.GetFamily());  p_config.Write(p_prefix + "Face", p_font.GetFaceName());  p_config.Write(p_prefix + "Style", (long) p_font.GetStyle());  p_config.Write(p_prefix + "Weight", (long) p_font.GetWeight());}void NfgTableSettings::LoadFont(const wxString &p_prefix,				const wxConfig &p_config, wxFont &p_font){  long size, family, style, weight;  wxString face;  p_config.Read(p_prefix + "Size", &size, 10);  p_config.Read(p_prefix + "Family", &family, wxMODERN);  p_config.Read(p_prefix + "Face", &face, "");  p_config.Read(p_prefix + "Style", &style, wxNORMAL);  p_config.Read(p_prefix + "Weight", &weight, wxNORMAL);  p_font = *wxTheFontList->FindOrCreateFont(size, family, style, weight,					    false, face);}void NfgTableSettings::LoadSettings(void){  wxConfig config("Gambit");  config.Read("/NfgDisplay/DisplayPrecision", &m_decimals, 2);  config.Read("/NfgDisplay/OutcomeValues", &m_outcomeValues, true);  LoadFont("/NfgDisplay/DataFont", config, m_dataFont);  LoadFont("/NfgDisplay/LabelFont", config, m_labelFont);}void NfgTableSettings::SaveSettings(void) const{  wxConfig config("Gambit");  config.Write("/NfgDisplay/DisplayPrecision", (long) m_decimals);  config.Write("/NfgDisplay/OutcomeValues", (long) m_outcomeValues);  SaveFont("/NfgDisplay/DataFont", config, m_dataFont);  SaveFont("/NfgDisplay/LabelFont", config, m_labelFont);}//---------------------------------------------------------------------//                       class NfgGridTable//---------------------------------------------------------------------class NfgGridTable : public wxGridTableBase {private:  Nfg *m_nfg;  NfgTable *m_table;public:  NfgGridTable(NfgTable *p_table, Nfg *p_nfg);  virtual ~NfgGridTable() { }  int GetNumberRows(void);  int GetNumberCols(void);  wxString GetValue(int row, int col);  wxString GetRowLabelValue(int);  wxString GetColLabelValue(int);  void SetValue(int, int, const wxString &);  bool IsEmptyCell(int, int) { return false; }  bool InsertRows(size_t pos = 0, size_t numRows = 1);  bool AppendRows(size_t numRows = 1);  bool DeleteRows(size_t pos = 0, size_t numRows = 1);  bool InsertCols(size_t pos = 0, size_t numCols = 1);  bool AppendCols(size_t numCols = 1);  bool DeleteCols(size_t pos = 0, size_t numCols = 1);  wxGridCellAttr *GetAttr(int row, int col);};NfgGridTable::NfgGridTable(NfgTable *p_table, Nfg *p_nfg)  : m_nfg(p_nfg), m_table(p_table){ }int NfgGridTable::GetNumberRows(void){  return (m_table->GetSupport().NumStrats(m_table->GetRowPlayer()) +	  m_table->ShowProbs() + m_table->ShowDominance() +	  m_table->ShowValues());}int NfgGridTable::GetNumberCols(void){  return (m_table->GetSupport().NumStrats(m_table->GetColPlayer()) +	  m_table->ShowProbs() + m_table->ShowDominance() + 	  m_table->ShowValues());}wxString NfgGridTable::GetRowLabelValue(int p_row){  int numStrats = m_table->GetSupport().NumStrats(m_table->GetRowPlayer());  if (p_row + 1 <= numStrats) {    return (char *) m_table->GetSupport().Strategies(m_table->GetRowPlayer())[p_row+1]->Name();  }  else if (p_row + 1 == numStrats + m_table->ShowDominance()) {    return "Dom";  }  else if (p_row + 1 == 	   numStrats + m_table->ShowDominance() + m_table->ShowProbs()) {    return "Prob";  }  else {    return "Val";  }}wxString NfgGridTable::GetColLabelValue(int p_col){  int numStrats = m_table->GetSupport().NumStrats(m_table->GetColPlayer());  if (p_col + 1 <= numStrats) {    return (char *) m_table->GetSupport().Strategies(m_table->GetColPlayer())[p_col+1]->Name();  }  else if (p_col + 1 == numStrats + m_table->ShowDominance()) {    return "Dom";  }  else if (p_col + 1 == 	   numStrats + m_table->ShowDominance() + m_table->ShowProbs()) {    return "Prob";  }  else {    return "Val";  }}wxString NfgGridTable::GetValue(int row, int col){  int rowPlayer = m_table->GetRowPlayer();  int colPlayer = m_table->GetColPlayer();  const NFSupport &support = m_table->GetSupport();  int numRowStrats = support.NumStrats(rowPlayer);  int numColStrats = support.NumStrats(colPlayer);  if (row < numRowStrats && col < numColStrats) {    gArray<int> strategy(m_table->GetContingency());    strategy[m_table->GetRowPlayer()] = row + 1;    strategy[m_table->GetColPlayer()] = col + 1;        StrategyProfile profile(*m_nfg);    for (int pl = 1; pl <= strategy.Length(); pl++) {      profile.Set(pl, support.GetStrategy(pl, strategy[pl]));    }    NFOutcome *outcome = m_nfg->GetOutcome(profile);    if (m_table->GetSettings().OutcomeValues()) {      wxString ret = "(";      for (int pl = 1; pl <= strategy.Length(); pl++) {	ret += wxString::Format("%s",				(char *) ToText(m_nfg->Payoff(outcome, pl),						m_table->GetSettings().GetDecimals()));	if (pl < strategy.Length()) {	  ret += wxString(",");	}      }      ret += ")";      return ret;    }    else {      if (outcome) {	wxString ret = (char *) outcome->GetName();	if (ret == "") {	  ret = (char *) (gText("Outcome") + ToText(outcome->GetNumber()));	}	return ret;      }      else {	return "Null";      }    }  }  else if (row < numRowStrats &&	   col == numColStrats + m_table->ShowDominance() - 1) {    Strategy *strategy = support.GetStrategy(rowPlayer, row + 1);    if (support.IsDominated(strategy, true)) {      return "S";    }    else if (support.IsDominated(strategy, false)) {      return "W";    }    else {      return "N";    }  }  else if (row == numRowStrats + m_table->ShowDominance() - 1 &&	   col < numColStrats) {    Strategy *strategy = support.GetStrategy(colPlayer, col + 1);    if (support.IsDominated(strategy, true)) {      return "S";    }    else if (support.IsDominated(strategy, false)) {      return "W";    }    else {      return "N";    }  }  else if (row < numRowStrats && 	   col == numColStrats + m_table->ShowDominance() + m_table->ShowProbs() - 1) {    Strategy *strategy = support.GetStrategy(rowPlayer, row + 1);    return ((char *) ToText(m_table->GetProfile()(strategy)));  }  else if (row == numRowStrats + m_table->ShowDominance() + m_table->ShowProbs() - 1 && 	   col < numColStrats) {    Strategy *strategy = support.GetStrategy(colPlayer, col + 1);    return ((char *) ToText(m_table->GetProfile()(strategy)));  }  else if (row < numRowStrats && 	   col == numColStrats + m_table->ShowDominance() + m_table->ShowProbs() + m_table->ShowValues() - 1) {    Strategy *strategy = support.GetStrategy(rowPlayer, row + 1);    return ((char *) ToText(m_table->GetProfile().Payoff(strategy->Player(), strategy)));  }  else if (row == numRowStrats + m_table->ShowDominance() + m_table->ShowProbs() + m_table->ShowValues() - 1 && 	   col < numColStrats) {    Strategy *strategy = support.GetStrategy(colPlayer, col + 1);    return ((char *) ToText(m_table->GetProfile().Payoff(strategy->Player(), strategy)));  }  return "";}void NfgGridTable::SetValue(int row, int col, const wxString &){  wxGridTableMessage msg(this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES, row, col);  GetView()->ProcessTableMessage(msg);}	bool NfgGridTable::InsertRows(size_t pos, size_t numRows){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED,			 pos, numRows);  GetView()->ProcessTableMessage(msg);  return true;}bool NfgGridTable::AppendRows(size_t numRows){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, numRows);  GetView()->ProcessTableMessage(msg);  return true;}bool NfgGridTable::DeleteRows(size_t pos, size_t numRows){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_DELETED,			 pos, numRows);  GetView()->ProcessTableMessage(msg);  return true;}bool NfgGridTable::InsertCols(size_t pos, size_t numCols){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_COLS_INSERTED,			 pos, numCols);  GetView()->ProcessTableMessage(msg);  return true;}bool NfgGridTable::AppendCols(size_t numCols){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_COLS_APPENDED, numCols);  GetView()->ProcessTableMessage(msg);  return true;}bool NfgGridTable::DeleteCols(size_t pos, size_t numCols){  wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_COLS_DELETED,			 pos, numCols);  GetView()->ProcessTableMessage(msg);  return true;}wxGridCellAttr *NfgGridTable::GetAttr(int row, int col){  wxGridCellAttr *attr = new wxGridCellAttr;  if (row >= m_table->GetSupport().NumStrats(m_table->GetRowPlayer()) &&      col >= m_table->GetSupport().NumStrats(m_table->GetColPlayer())) {    attr->SetBackgroundColour(*wxBLACK);  }  else if (row >= m_table->GetSupport().NumStrats(m_table->GetRowPlayer()) ||	   col >= m_table->GetSupport().NumStrats(m_table->GetColPlayer())) {    attr->SetBackgroundColour(*wxLIGHT_GREY);  }  else {    attr->SetBackgroundColour(*wxWHITE);  }  attr->SetAlignment(wxCENTER, wxCENTER);  return attr;}class ColoredStringRenderer : public wxGridCellRenderer {public:  // draw the string  virtual void Draw(wxGrid& grid,		    wxGridCellAttr& attr,		    wxDC& dc,		    const wxRect& rect,		    int row, int col,		    bool isSelected);

⌨️ 快捷键说明

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