Skip to content

Commit

Permalink
Pass a reference to state_to_string.
Browse files Browse the repository at this point in the history
We don't allow it to be null, so pass a reference instead of a pointer.
Also use make_unique rather than new.
  • Loading branch information
gcp committed Oct 25, 2017
1 parent 4e421c6 commit b41d86f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/GTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ bool GTP::execute(GameState & game, std::string xinput) {
cmdstream >> tmp; // eat printsgf
cmdstream >> filename;

auto sgf_text = SGFTree::state_to_string(&game, 0);
auto sgf_text = SGFTree::state_to_string(game, 0);

if (cmdstream.fail()) {
gtp_printf(id, "%s\n", sgf_text.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/SGFTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ std::vector<int> SGFTree::get_mainline() {
return moves;
}

std::string SGFTree::state_to_string(GameState * pstate, int compcolor) {
std::unique_ptr<GameState> state(new GameState);
std::string SGFTree::state_to_string(GameState& pstate, int compcolor) {
auto state = std::make_unique<GameState>();

// make a working copy
*state = *pstate;
*state = pstate;

std::string header;
std::string moves;
Expand Down
2 changes: 1 addition & 1 deletion src/SGFTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SGFTree {
};
FastBoard::square_t get_winner();

static std::string state_to_string(GameState * state, int compcolor);
static std::string state_to_string(GameState& state, int compcolor);

private:
void populate_states(void);
Expand Down

0 comments on commit b41d86f

Please sign in to comment.