Skip to content

Commit

Permalink
perf: remove 'use namespace std;' ⬇️
Browse files Browse the repository at this point in the history
  • Loading branch information
Joker2770 committed Aug 21, 2024
1 parent d62f360 commit 4daae15
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 262 deletions.
11 changes: 5 additions & 6 deletions src/CaroJudge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ SOFTWARE.

#include <algorithm>
#include <iostream>
using namespace std;

bool CaroJudge::findShap(const board_type &board, int last_move, const pair<int, int> &p_drt)
bool CaroJudge::findShap(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
vector<int> vColor;
std::vector<int> vColor;

size_t n = board.size();
pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

// push back current stone color
if (1 == board[last_move / n][last_move % n])
Expand Down Expand Up @@ -131,7 +130,7 @@ bool CaroJudge::checkWin(const board_type &board, int last_move)
}

size_t n = board.size();
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
bool b_up = findShap(board, last_move, p_drt_up);
bool b_left = findShap(board, last_move, p_drt_left);
bool b_leftup = findShap(board, last_move, p_drt_leftup);
Expand Down
3 changes: 1 addition & 2 deletions src/CaroJudge.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ SOFTWARE.

#include "rule.h"
#include <iostream>
using namespace std;

const int WIN_SHAPES[][7] = {
{1, 1, 1, 1, 1, 0, 0},
Expand Down Expand Up @@ -91,7 +90,7 @@ class CaroJudge final : public rule

private:
bool isPosOutOfBoard(unsigned int n, int x, int y);
bool findShap(const board_type &board, int last_move, const pair<int, int> &p_drt);
bool findShap(const board_type &board, int last_move, const std::pair<int, int> &p_drt);
};

#endif
9 changes: 4 additions & 5 deletions src/FreeStyleJudge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ SOFTWARE.

#include "FreeStyleJudge.h"
#include <iostream>
using namespace std;

bool FreeStyleJudge::isPosOutOfBoard(unsigned int n, int x, int y)
{
return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0;
}

int FreeStyleJudge::countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt)
int FreeStyleJudge::countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
int i_count = 0;
if (-1 == last_move)
return 0;

size_t n = board.size();
pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second])
{
Expand Down Expand Up @@ -76,7 +75,7 @@ bool FreeStyleJudge::checkWin(const board_type &board, int last_move)

size_t n = board.size();

pair<int, int> p_drt_up(0, -1),
std::pair<int, int> p_drt_up(0, -1),
p_drt_down(0, 1),
p_drt_left(-1, 0),
p_drt_right(1, 0),
Expand Down
5 changes: 2 additions & 3 deletions src/FreeStyleJudge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
MIT License
Copyright (c) 2023 Joker2770
Copyright (c) 2023-2024 Joker2770
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -34,7 +34,6 @@ SOFTWARE.

#include "rule.h"
#include <iostream>
using namespace std;

class FreeStyleJudge final : public rule
{
Expand All @@ -43,7 +42,7 @@ class FreeStyleJudge final : public rule

private:
bool isPosOutOfBoard(unsigned int n, int x, int y);
int countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt);
int countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt);
};

#endif
37 changes: 18 additions & 19 deletions src/RenjuJudge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ SOFTWARE.
#include "RenjuJudge.h"
#include <algorithm>
#include <iostream>
using namespace std;

bool RenjuJudge::isOverLine(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), p_drt_leftup(-1, -1), p_drt_rightdown(1, 1), p_drt_rightup(1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), p_drt_leftup(-1, -1), p_drt_rightdown(1, 1), p_drt_rightup(1, -1), p_drt_leftdown(-1, 1);
int i_up = countNearStone(board, last_move, p_drt_up);
int i_down = countNearStone(board, last_move, p_drt_down);
int i_left = countNearStone(board, last_move, p_drt_left);
Expand All @@ -52,15 +51,15 @@ bool RenjuJudge::isOverLine(const board_type &board, int last_move)
return false;
}

int RenjuJudge::countA4(const board_type &board, int last_move, const pair<int, int> &p_drt)
int RenjuJudge::countA4(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
int i_count = 0;

vector<int> vColor;
std::vector<int> vColor;

size_t n = board.size();
pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

// push back current stone color
if (1 == board[last_move / n][last_move % n])
Expand Down Expand Up @@ -178,7 +177,7 @@ int RenjuJudge::countA4(const board_type &board, int last_move, const pair<int,

bool RenjuJudge::isDoubleFour(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
int i_up = countA4(board, last_move, p_drt_up);
int i_left = countA4(board, last_move, p_drt_left);
int i_leftup = countA4(board, last_move, p_drt_leftup);
Expand All @@ -190,13 +189,13 @@ bool RenjuJudge::isDoubleFour(const board_type &board, int last_move)
return false;
}

int RenjuJudge::countA3(const board_type &board, int last_move, const pair<int, int> &p_drt)
int RenjuJudge::countA3(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
vector<int> vColor;
std::vector<int> vColor;

size_t n = board.size();
pair<int, int> p_idx((unsigned int)(last_move / n), (unsigned int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((unsigned int)(last_move / n), (unsigned int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

// push back current stone color
if (1 == board[last_move / n][last_move % n])
Expand Down Expand Up @@ -287,7 +286,7 @@ int RenjuJudge::countA3(const board_type &board, int last_move, const pair<int,

bool RenjuJudge::isFourThree(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
int i_up_4 = countA4(board, last_move, p_drt_up);
int i_left_4 = countA4(board, last_move, p_drt_left);
int i_leftup_4 = countA4(board, last_move, p_drt_leftup);
Expand Down Expand Up @@ -342,7 +341,7 @@ bool RenjuJudge::isFourThree(const board_type &board, int last_move)

bool RenjuJudge::isFour(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
int i_up_4 = countA4(board, last_move, p_drt_up);
int i_left_4 = countA4(board, last_move, p_drt_left);
int i_leftup_4 = countA4(board, last_move, p_drt_leftup);
Expand Down Expand Up @@ -381,7 +380,7 @@ bool RenjuJudge::isFour(const board_type &board, int last_move)

bool RenjuJudge::isDoubleThree(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
int i_up_4 = countA4(board, last_move, p_drt_up);
int i_left_4 = countA4(board, last_move, p_drt_left);
int i_leftup_4 = countA4(board, last_move, p_drt_leftup);
Expand Down Expand Up @@ -444,7 +443,7 @@ bool RenjuJudge::isDoubleThree(const board_type &board, int last_move)

bool RenjuJudge::isThree(const board_type &board, int last_move)
{
pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
std::pair<int, int> p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1);
int i_up_4 = countA4(board, last_move, p_drt_up);
int i_left_4 = countA4(board, last_move, p_drt_left);
int i_leftup_4 = countA4(board, last_move, p_drt_leftup);
Expand Down Expand Up @@ -523,15 +522,15 @@ bool RenjuJudge::isPosOutOfBoard(unsigned int n, int x, int y)
return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0;
}

int RenjuJudge::countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt)
int RenjuJudge::countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
int i_count = 0;
if (-1 == last_move)
return 0;

size_t n = board.size();
pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second])
{
Expand Down Expand Up @@ -561,7 +560,7 @@ bool RenjuJudge::checkWin(const board_type &board, int last_move)

size_t n = board.size();

pair<int, int> p_drt_up(0, -1),
std::pair<int, int> p_drt_up(0, -1),
p_drt_down(0, 1),
p_drt_left(-1, 0),
p_drt_right(1, 0),
Expand Down
9 changes: 4 additions & 5 deletions src/RenjuJudge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
MIT License
Copyright (c) 2023 Joker2770
Copyright (c) 2023-2024 Joker2770
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -34,7 +34,6 @@ SOFTWARE.

#include "rule.h"
#include <iostream>
using namespace std;

typedef enum pattern
{
Expand Down Expand Up @@ -83,10 +82,10 @@ class RenjuJudge final : public rule
bool isDoubleThree(const board_type &board, int last_move);
// after double-three, only 3
bool isThree(const board_type &board, int last_move);
int countA4(const board_type &board, int last_move, const pair<int, int> &p_drt);
int countA3(const board_type &board, int last_move, const pair<int, int> &p_drt);
int countA4(const board_type &board, int last_move, const std::pair<int, int> &p_drt);
int countA3(const board_type &board, int last_move, const std::pair<int, int> &p_drt);
bool isPosOutOfBoard(unsigned int n, int x, int y);
int countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt);
int countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt);

int m_renju_state;
};
Expand Down
9 changes: 4 additions & 5 deletions src/StandardJudge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ SOFTWARE.

#include "StandardJudge.h"
#include <iostream>
using namespace std;

bool StandardJudge::isPosOutOfBoard(unsigned int n, int x, int y)
{
return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0;
}

int StandardJudge::countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt)
int StandardJudge::countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt)
{
int i_count = 0;
if (-1 == last_move)
return 0;

size_t n = board.size();
pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);
std::pair<int, int> p_idx((int)(last_move / n), (int)(last_move % n));
std::pair<int, int> p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second);

while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second])
{
Expand Down Expand Up @@ -76,7 +75,7 @@ bool StandardJudge::checkWin(const board_type &board, int last_move)

size_t n = board.size();

pair<int, int> p_drt_up(0, -1),
std::pair<int, int> p_drt_up(0, -1),
p_drt_down(0, 1),
p_drt_left(-1, 0),
p_drt_right(1, 0),
Expand Down
5 changes: 2 additions & 3 deletions src/StandardJudge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
MIT License
Copyright (c) 2023 Joker2770
Copyright (c) 2023-2024 Joker2770
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -34,7 +34,6 @@ SOFTWARE.

#include "rule.h"
#include <iostream>
using namespace std;

class StandardJudge final : public rule
{
Expand All @@ -43,7 +42,7 @@ class StandardJudge final : public rule

private:
bool isPosOutOfBoard(unsigned int n, int x, int y);
int countNearStone(const board_type &board, int last_move, const pair<int, int> &p_drt);
int countNearStone(const board_type &board, int last_move, const std::pair<int, int> &p_drt);
};

#endif
2 changes: 1 addition & 1 deletion src/onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ NeuralNetwork::NeuralNetwork(const std::string &model_path, const unsigned int b
// print input node names
char *input_name = shared_session->GetInputName(i, allocator);
// printf("Input %d : name = %s\n", i, input_name);
input_node_names[i] = input_name;
this->input_node_names[i] = input_name;

// print input node types
Ort::TypeInfo type_info = shared_session->GetInputTypeInfo(i);
Expand Down
Loading

0 comments on commit 4daae15

Please sign in to comment.