Skip to content

Commit 488290c

Browse files
committed
Use std::vector in NewTable
1 parent c17c911 commit 488290c

File tree

7 files changed

+14
-16
lines changed

7 files changed

+14
-16
lines changed

src/games/file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ class TableFileGame {
306306
std::vector<TableFilePlayer> m_players;
307307

308308
size_t NumPlayers() const { return m_players.size(); }
309-
Array<int> NumStrategies() const
309+
std::vector<int> NumStrategies() const
310310
{
311-
Array<int> ret(m_players.size());
311+
std::vector<int> ret(m_players.size());
312312
std::transform(m_players.begin(), m_players.end(), ret.begin(),
313313
[](const TableFilePlayer &player) { return player.m_strategies.size(); });
314314
return ret;

src/games/game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ inline GameStrategy GamePlayerRep::GetStrategy(int st) const
704704
/// Factory function to create new game tree
705705
Game NewTree();
706706
/// Factory function to create new game table
707-
Game NewTable(const Array<int> &p_dim, bool p_sparseOutcomes = false);
707+
Game NewTable(const std::vector<int> &p_dim, bool p_sparseOutcomes = false);
708708

709709
/// @brief Reads a game representation in .efg format
710710
///

src/games/gametable.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ std::shared_ptr<PureStrategyProfileRep> TablePureStrategyProfileRep::Copy() cons
6464
return std::make_shared<TablePureStrategyProfileRep>(*this);
6565
}
6666

67-
Game NewTable(const Array<int> &p_dim, bool p_sparseOutcomes /*= false*/)
67+
Game NewTable(const std::vector<int> &p_dim, bool p_sparseOutcomes /*= false*/)
6868
{
6969
return new GameTableRep(p_dim, p_sparseOutcomes);
7070
}
@@ -265,12 +265,12 @@ template class TableMixedStrategyProfileRep<Rational>;
265265
// GameTableRep: Lifecycle
266266
//------------------------------------------------------------------------
267267

268-
GameTableRep::GameTableRep(const Array<int> &dim, bool p_sparseOutcomes /* = false */)
268+
GameTableRep::GameTableRep(const std::vector<int> &dim, bool p_sparseOutcomes /* = false */)
269269
: m_results(std::accumulate(dim.begin(), dim.end(), 1, std::multiplies<>()))
270270
{
271-
for (size_t pl = 1; pl <= dim.size(); pl++) {
272-
m_players.push_back(new GamePlayerRep(this, pl, dim[pl]));
273-
m_players.back()->m_label = lexical_cast<std::string>(pl);
271+
for (const auto &nstrat : dim) {
272+
m_players.push_back(new GamePlayerRep(this, m_players.size() + 1, nstrat));
273+
m_players.back()->m_label = lexical_cast<std::string>(m_players.size());
274274
std::for_each(
275275
m_players.back()->m_strategies.begin(), m_players.back()->m_strategies.end(),
276276
[st = 1](GameStrategyRep *s) mutable { s->SetLabel(lexical_cast<std::string>(st++)); });

src/games/gametable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GameTableRep : public GameExplicitRep {
4949
//@{
5050
/// Construct a new table game with the given dimension
5151
/// If p_sparseOutcomes = true, outcomes for all contingencies are left null
52-
explicit GameTableRep(const Array<int> &p_dim, bool p_sparseOutcomes = false);
52+
explicit GameTableRep(const std::vector<int> &p_dim, bool p_sparseOutcomes = false);
5353
Game Copy() const override;
5454
//@}
5555

src/gui/gameframe.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ void gbtGameFrame::OnFileNewEfg(wxCommandEvent &)
636636

637637
void gbtGameFrame::OnFileNewNfg(wxCommandEvent &)
638638
{
639-
Gambit::Array<int> dim(2);
639+
std::vector<int> dim(2);
640+
dim[0] = 2;
640641
dim[1] = 2;
641-
dim[2] = 2;
642642
const Gambit::Game nfg = Gambit::NewTable(dim);
643643
nfg->SetTitle("Untitled Strategic Game");
644644
nfg->GetPlayer(1)->SetLabel("Player 1");

src/pygambit/gambit.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from libcpp cimport bool
22
from libcpp.string cimport string
33
from libcpp.memory cimport shared_ptr, unique_ptr
44
from libcpp.list cimport list as stdlist
5+
from libcpp.vector cimport vector as stdvector
56

67

78
cdef extern from "gambit.h":
@@ -230,7 +231,7 @@ cdef extern from "games/game.h":
230231
c_MixedStrategyProfile[T] NewMixedStrategyProfile[T](T) # except + doesn't compile
231232

232233
c_Game NewTree() except +
233-
c_Game NewTable(Array[int]) except +
234+
c_Game NewTable(stdvector[int]) except +
234235

235236

236237
cdef extern from "games/stratpure.h":

src/pygambit/game.pxi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,7 @@ class Game:
517517
Game
518518
The newly-created strategic game.
519519
"""
520-
cdef Array[int] d
521-
for v in dim:
522-
d.push_back(v)
523-
g = Game.wrap(NewTable(d))
520+
g = Game.wrap(NewTable(list(dim)))
524521
g.title = title
525522
return g
526523

0 commit comments

Comments
 (0)