Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Cpp11BracedListStyle: true
DerivePointerAlignment: false # Make sure the * or & align on the left
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
Expand All @@ -59,7 +59,7 @@ NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
ReflowComments: false
ReflowComments: true
# SeparateDefinitionBlocks: Always # Only support since clang-format 14
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/analysis.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "analysis/analysis.h"

#include <algorithm>
#include <memory>
#include <utility>
#include <vector>

#include "analysis/handnode.h"
#include "analysis/handtree.h"
#include "types/hand.h"
Expand Down Expand Up @@ -78,8 +80,8 @@ std::unique_ptr<Node> breakdownHand(const std::vector<Piece>& pieces) {
b.pieces = pieces;
countPieces(&b);
std::ranges::sort(b.pieces);
auto [begin,end] = std::ranges::unique(b.pieces);
b.pieces.erase(begin,end);
auto [begin, end] = std::ranges::unique(b.pieces);
b.pieces.erase(begin, end);

driver(&b);

Expand Down
3 changes: 1 addition & 2 deletions src/analysis/handtree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ void driver(Breakdown* b) {
// Check if we can start a chi with this piece
if (possibleChiForward(b->counts, chi_start)) {
// Find the position of chi_start in the pieces vector
auto piece_itr =
std::ranges::find(b->pieces, chi_start);
auto piece_itr = std::ranges::find(b->pieces, chi_start);
if (piece_itr != b->pieces.end()) {
breakdownForwardChi(b, *piece_itr);
}
Expand Down
1 change: 1 addition & 0 deletions src/analysis/handtree.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <map>

#include "analysis/handnode.h"
#include "types/piecetype.h"
namespace mahjong {
Expand Down
1 change: 1 addition & 0 deletions src/analysis/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdlib>
#include <map>
#include <vector>

#include "analysis/analysis.h"
#include "types/hand.h"
#include "types/pieces.h"
Expand Down
5 changes: 3 additions & 2 deletions src/api/gamestate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <memory>
#include <vector>

#include "api/types.h"
#include "controllers/controllermanager.h"
#include "statefunctions/statecontroller.h"
Expand Down Expand Up @@ -95,8 +96,8 @@ bool IsValidGameController(const char* controller) {

mahjong::GameState* InitGameState(const CGameSettings* settings) {
const mahjong::GameSettings cpp_settings = convertGameSettings(settings);
// Check controllers ahead of time as C++ throws will not be handled correctly by
// all library consumers (rust)
// Check controllers ahead of time as C++ throws will not be handled correctly
// by all library consumers (rust)
for (const auto& controller : cpp_settings.seatControllers) {
if (!IsValidGameController(controller.c_str())) {
return nullptr;
Expand Down
18 changes: 9 additions & 9 deletions src/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ struct CHand {
};

struct CObservedGameState {
int currentPlayer; // Whose turn it is
int turnNum; // Turn counter within current round
int roundNum; // Current round number
int riichiSticks; // Number of riichi sticks on the table
int counters; // Honba counters
int lastCall; // Turn number when last call (chi/pon/kan) was made
int lastCaller; // Player index who made the last call
bool
concealedKan; // Whether concealed kan was just performed (affects ron rules)
int currentPlayer; // Whose turn it is
int turnNum; // Turn counter within current round
int roundNum; // Current round number
int riichiSticks; // Number of riichi sticks on the table
int counters; // Honba counters
int lastCall; // Turn number when last call (chi/pon/kan) was made
int lastCaller; // Player index who made the last call
bool concealedKan; // Whether concealed kan was just performed (affects ron
// rules)
uint64_t seed; // Random seed used for wall generation and shuffling
CPiece pendingPiece; // Current piece being processed
int scores[4]; // Temporary round score changes
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/alphabeticalbot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void AlphabeticalBot::ReceiveEvent(Event e) {
break;
case Event::kDiscard:
if (e.decision && e.player == id_) {
// std::cout << "Player " << id_ << " pushing piece into hand: " << e.piece << std::endl;
// std::cout << "Player " << id_ << " pushing piece into hand: " <<
// e.piece << std::endl;
hand_.emplace_back(e.piece);
}
break;
Expand Down
18 changes: 12 additions & 6 deletions src/controllers/fasttanyao.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ bool FastTanyao::ShouldKeep(Piece piece) {
}

void FastTanyao::OutputSet(uint8_t /*unused*/, const pieceSet& /*unused*/) {
// std::cout << "(" << Piece(id).toStr() << ", " << unsigned(set.at(id)) << ")" << std::endl;
// std::cout << "(" << Piece(id).toStr() << ", " << unsigned(set.at(id)) <<
// ")" << std::endl;
}

void FastTanyao::IncrementPiece(Piece piece, pieceSet& set) {
Expand Down Expand Up @@ -52,7 +53,8 @@ void FastTanyao::DecrementPiece(Piece piece, pieceSet& set) {
void FastTanyao::ProcessNewPiece(Piece piece) {
if (!ShouldKeep(piece)) {
immediate_discard_.push_back(piece);
// std::cout << Piece(piece).toStr() << " should be immediately discarded." << std::endl;
// std::cout << Piece(piece).toStr() << " should be immediately discarded."
// << std::endl;
return;
}

Expand All @@ -71,7 +73,8 @@ Piece FastTanyao::ChooseDiscard() {
if (!immediate_discard_.empty()) {
auto discard = immediate_discard_.back();
immediate_discard_.pop_back();
// std::cout << "Chose piece " << discard.toStr() << " to discard (imm discard)" << std::endl;
// std::cout << "Chose piece " << discard.toStr() << " to discard (imm
// discard)" << std::endl;
return discard;
}

Expand All @@ -85,7 +88,8 @@ Piece FastTanyao::ChooseDiscard() {
if (possible_triple.second + set_contains_piece->second == 4 &&
possible_triple.second < 3) {
DecrementPiece(Piece(piece), possible_triples_);
// std::cout << "Chose piece " << Piece(piece).toStr() << " to discard (all pieces in play)" << std::endl;
// std::cout << "Chose piece " << Piece(piece).toStr() << " to discard
// (all pieces in play)" << std::endl;
return Piece(piece);
}
if (possible_triple.second > 0) {
Expand All @@ -97,10 +101,12 @@ Piece FastTanyao::ChooseDiscard() {
auto min_value = *std::ranges::min_element(
discard_options,
[](const auto& l, const auto& r) { return l.second < r.second; });
// std::cout << unsigned(minValue.first) << ", " << unsigned(minValue.second) << std::endl;
// std::cout << unsigned(minValue.first) << ", " << unsigned(minValue.second)
// << std::endl;
auto discard_piece = Piece(min_value.first);
DecrementPiece(discard_piece, possible_triples_);
// std::cout << "Chose piece " << discardPiece.toStr() << " to discard (min risk)" << std::endl;
// std::cout << "Chose piece " << discardPiece.toStr() << " to discard (min
// risk)" << std::endl;
return discard_piece;
}

Expand Down
1 change: 1 addition & 0 deletions src/scoring/scoring.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "scoring/scoring.h"

#include <algorithm>
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions src/scoring/yakus.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "scoring/yakus.h"

#include <vector>

#include "types/yaku.h"

namespace mahjong {
Expand Down
3 changes: 2 additions & 1 deletion src/scoring/yakus/outsidehand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ bool isOutsideHand(const GameState& state, int player,
}
}
}
// Terminals in all Sets and All Terminals and Honors are more valuable and score instead of Outside Hand.
// Terminals in all Sets and All Terminals and Honors are more valuable and
// score instead of Outside Hand.
return chi && !isTerminalsInAllSets(state, player, branch) &&
!isAllTerminalsAndHonors(state, player);
}
Expand Down
1 change: 0 additions & 1 deletion src/statefunctions/decisionfunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "analysis/util.h"
#include "scoring/scoring.h"
#include "scoring/yakus/thirteenorphans.h"

#include "statefunctions/stateutilities.h"
#include "types/gamestate.h"
#include "types/piecetype.h"
Expand Down
3 changes: 0 additions & 3 deletions src/types/gamestate.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#pragma once
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <random>
#include <vector>

#include "types/hand.h"
#include "types/piecetype.h"
Expand Down
1 change: 1 addition & 0 deletions src/types/yaku.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <functional>

#include "analysis/handnode.h"
#include "types/gamestate.h"

Expand Down
8 changes: 5 additions & 3 deletions tests/api/game_control.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>
#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -79,8 +80,8 @@ TEST(Api, ObserveGameState) {
// Check state function name, the rest will be in unknown positions
// until we advance the game state
EXPECT_EQ(observed.nextState,
api::CStateFunctionType::
kGameStart); // Initial state should be GameStart
api::CStateFunctionType::kGameStart); // Initial state should be
// GameStart

// Check arrays are properly sized and initialized
for (int i = 0; i < 4; i++) {
Expand Down Expand Up @@ -114,7 +115,8 @@ TEST(Api, ObserveGameStateAfterAdvancement) {
EXPECT_EQ(observed.seed, state->seed);

// After advancement, some fields should have changed from initial values
// (exact values depend on game logic, but we can check they're copied correctly)
// (exact values depend on game logic, but we can check they're copied
// correctly)
EXPECT_EQ(observed.riichiSticks, state->riichiSticks);
EXPECT_EQ(observed.counters, state->counters);

Expand Down
1 change: 1 addition & 0 deletions tests/can_chi.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>

#include "statefunctions/decisionfunction.h"
Expand Down
1 change: 1 addition & 0 deletions tests/count_pieces.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>

#include "statefunctions/stateutilities.h"
Expand Down
1 change: 1 addition & 0 deletions tests/discard_piece.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>

#include "statefunctions/stateutilities.h"
Expand Down
1 change: 1 addition & 0 deletions tests/game_play.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>

#include "scoring/scoring.h"
Expand Down
1 change: 1 addition & 0 deletions tests/remove_pieces.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions tests/rules/basic_rules.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <memory>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions tests/rules/calls.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <cstdint>
#include <memory>
#include <utility>
Expand Down
1 change: 1 addition & 0 deletions tests/setup.test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>

#include <array>
#include <memory>
#include <utility>
Expand Down
8 changes: 2 additions & 6 deletions tests/utils/gamestate_utils.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#pragma once
#include <functional>
#include <memory>
#include <optional>
#include <vector>

#include "controllers/playercontroller.h"
#include "statefunctions/router.h"
#include "types/event.h"
#include "types/gamestate.h"
#include "types/piecetype.h"
#include "types/statefunction.h"

namespace mahjong {
Expand All @@ -18,7 +13,8 @@ std::unique_ptr<GameState> AdvanceUntilState(std::unique_ptr<GameState> state,
StateFunctionType targetState,
int maxIterations = 100);

// Advances game state until it reaches the target state, then advances once more
// Advances game state until it reaches the target state, then advances once
// more
std::unique_ptr<GameState> AdvanceThroughState(std::unique_ptr<GameState> state,
StateFunctionType targetState,
int maxIterations = 100);
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/gamestate_utils.test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "gamestate_utils.h"

#include <gtest/gtest.h>

#include <cstdint>
#include <memory>
#include <stdexcept>
#include <utility>

#include "gamestate_utils.h"
#include "types/gamestate.h"
#include "types/settings.h"
#include "types/statefunction.h"
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/handformer.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "utils/handformer.h"

#include <cctype>

#include <algorithm>
#include <cctype>
#include <cstdint>
#include <iterator>
#include <map>
Expand Down Expand Up @@ -46,7 +45,8 @@ std::vector<Piece> HandFromNotation(const std::string& notation) {
std::vector<int8_t> current_tiles;
for (const auto& c : notation) {
if (!std::isdigit(c) && !std::isalpha(c)) {
// Push -1 if input is invalid (which is later translated to an error piece)
// Push -1 if input is invalid (which is later translated to an error
// piece)
current_tiles.push_back(-1);
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/utils/handformer.test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "utils/handformer.h"

#include <gtest/gtest.h>

#include <string>
#include <vector>

#include "types/pieces.h"
#include "types/piecetype.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/yakus/afterkan.test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <gtest/gtest.h>

#include <array>
#include <memory>
#include <string>

#include "analysis/analysis.h"

#include "analysis/handnode.h"
#include "scoring/yakus/afterakan.h"
#include "types/gamestate.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/yakus/allpon.test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <gtest/gtest.h>

#include <array>
#include <memory>
#include <string>
#include <vector>

#include "analysis/analysis.h"

#include "analysis/handnode.h"
#include "scoring/yakus/allpons.h"
#include "types/gamestate.h"
Expand Down
Loading