Skip to content

Commit

Permalink
refactor: use fmt::format
Browse files Browse the repository at this point in the history
Mauritz8 committed May 19, 2024
1 parent 7d35e9f commit 221b307
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/board.cpp
Original file line number Diff line number Diff line change
@@ -46,15 +46,15 @@ bool Board::operator==(const Board &other) const {
}

std::string Board::to_string() const {
auto to_str = [](std::string str, Square square) {
bool last_col = (square.pos + 1) % 8 == 0;
return str + " " +
(square.piece ? square.piece->get_char_representation() : '_') +
(last_col ? "\n" : "");
auto to_str = [](std::string str, Square s) {
bool last_col = (s.pos + 1) % 8 == 0;
return fmt::format("{} {}{}", str,
s.piece ? s.piece->get_char_representation() : '_',
last_col ? "\n" : "");
};
std::string board =
std::accumulate(squares.begin(), squares.end(), std::string(""), to_str);
return board + "\n";
return board;
}

int Board::get_king_square(Color color) const {
5 changes: 3 additions & 2 deletions src/board/fen.cpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#include "board/defs.hpp"
#include "evaluation/evaluation.hpp"
#include "fen.hpp"
#include "fmt/core.h"
#include "utils.hpp"

namespace fen {
@@ -42,8 +43,8 @@ Color calc_player_to_move(const std::string &player_to_move) {
} else if (player_to_move == "b") {
return BLACK;
} else {
throw std::invalid_argument("Invalid FEN: " + player_to_move +
" is not a valid color\n");
throw std::invalid_argument(
fmt::format("Invalid FEN: {} is not a valid color\n", player_to_move));
}
}

4 changes: 2 additions & 2 deletions src/uci.cpp
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ std::string UCI::show(const SearchSummary &ss) {
const std::string pv =
std::accumulate(ss.pv.begin(), ss.pv.end(), std::string(""),
[](std::string acc, const Move &m) {
return acc + " " + m.to_uci_notation();
return fmt::format("{} {}", acc, m.to_uci_notation());
});

return fmt::format("info depth {} seldepth {} multipv 1 score {} nodes {} "
@@ -88,7 +88,7 @@ std::string UCI::get_fen(const std::vector<std::string> &words) const {
}

auto join = [](std::string str1, std::string str2) {
return str1 + " " + str2;
return fmt::format("{} {}", str1, str2);
};
auto moves_it = std::find(words.begin(), words.end(), "moves");
std::string fen =

0 comments on commit 221b307

Please sign in to comment.