Skip to content

Commit c83ca1c

Browse files
committed
initialize projects
1 parent 3d14d1d commit c83ca1c

16 files changed

+736
-6
lines changed

.dockerignroe

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/out
2+
/cmake-build-debug
3+
/ARM64
4+
/.vs
5+
work.sln
6+
*.vcxproj

.gitignore

+18-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ CMakeCache.txt
33
CMakeFiles
44
CMakeScripts
55
Testing
6-
Makefile
7-
cmake_install.cmake
8-
install_manifest.txt
9-
compile_commands.json
10-
CTestTestfile.cmake
11-
_deps
6+
7+
cmake-build-debug
8+
9+
.DS_Store
10+
build
11+
.vs
12+
13+
.idea
14+
15+
## visual studio
16+
x64
17+
x86
18+
Debug
19+
Release
20+
*.sdf
21+
*.opensdf
22+
*.suo
23+
*.vcxproj.user

CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.22.1)
2+
project(work)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
add_executable(work src/main.cpp
8+
header/Stone.h
9+
src/ReversiBoard.cpp
10+
header/ReversiBoard.h
11+
src/List.cpp
12+
header/List.h
13+
header/cout.h
14+
)

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:latest
2+
3+
# 必要なパッケージのインストール
4+
RUN apt-get update && apt-get install -y software-properties-common && \
5+
add-apt-repository ppa:ubuntu-toolchain-r/test && \
6+
apt-get update && apt-get install -y \
7+
g++-13 \
8+
cmake \
9+
make \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
ENV CXX=g++-13
13+
# 作業ディレクトリの設定
14+
WORKDIR /app

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
run:
2+
rm -rf build
3+
mkdir -p build
4+
cd build && cmake .. && make
5+
./build/work
6+
7+
docker:
8+
docker compose up --build
9+
clean:
10+
rm -rf build

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
# reversi-cpp
22
c++のリバーシ
3+
4+
## Environment
5+
- apple m2
6+
- macOS Sonoma 14.0
7+
- cmake min:3.22.1 (current:3.27.7)
8+
- c++20~
9+
- g++13
10+
11+
## How to run
12+
`cmake` or `docker` or `Visual Studio 2022`
13+
14+
### in Visual Studio 2022 (recommended)
15+
- open Visual Studio 2022
16+
- run on `Debug` mode
17+
18+
### cmake
19+
```bash
20+
make run
21+
```

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3'
2+
3+
services:
4+
cpp-app:
5+
build: .
6+
volumes:
7+
- ./:/app:z
8+
command: >
9+
bash -c "rm -rf build/* &&
10+
mkdir -p build &&
11+
cd build &&
12+
cmake .. &&
13+
make &&
14+
./work"

header/List.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Created by matuyuhi on 2023/11/08.
3+
//
4+
5+
#ifndef WORK01_LIST_H
6+
#define WORK01_LIST_H
7+
8+
#include <vector>
9+
#include <algorithm>
10+
#include <utility>
11+
#include <iostream>
12+
13+
template <typename T>
14+
class List {
15+
private:
16+
std::vector<T> placeableCells;
17+
public:
18+
// pointをリストに追加
19+
void add(const T& p) {
20+
placeableCells.push_back(p);
21+
}
22+
23+
// 指定したpointをリストから削除
24+
bool remove(const T& p) {
25+
auto it = std::find(placeableCells.begin(), placeableCells.end(), p);
26+
if (it != placeableCells.end()) {
27+
placeableCells.erase(it);
28+
return true; // 削除成功
29+
}
30+
return false; // 要素が見つからない場合
31+
}
32+
33+
// リストからすべての要素を削除
34+
void clear() {
35+
placeableCells.clear();
36+
}
37+
38+
// pointがリストに含まれているか確認
39+
bool contains(const T& p) const {
40+
return std::find(placeableCells.begin(), placeableCells.end(), p) != placeableCells.end();
41+
}
42+
43+
// デバッグ用にリストの内容を出力
44+
void printList() const {
45+
for (const auto& p : placeableCells) {
46+
std::cout << "(" << p.first << ", " << p.second << ") ";
47+
}
48+
std::cout << std::endl;
49+
}
50+
51+
int size() {
52+
return placeableCells.size();
53+
}
54+
};
55+
56+
57+
#endif //WORK01_LIST_H

header/ReversiBoard.h

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// Created by matuyuhi on 2023/11/08.
3+
//
4+
5+
#ifndef WORK01_REVERSIBOARD_H
6+
#define WORK01_REVERSIBOARD_H
7+
8+
#include <vector>
9+
#include <iostream>
10+
#include <map>
11+
#include "Stone.h"
12+
#include "List.h"
13+
#include "cout.h"
14+
15+
// リバーシのボードを管理するクラス
16+
class ReversiBoard {
17+
private:
18+
std::vector<std::vector<stone>> board;
19+
int boardSize;
20+
21+
// 置けるマスの一覧
22+
std::map<stone, List<std::pair<int, int>>> placeableCells;
23+
24+
/// 8方向のベクトル
25+
const std::vector<std::pair<int, int>> directions = {
26+
{0, 1}, {1, 0}, {0, -1}, {-1, 0},
27+
{1, 1}, {-1, -1}, {1, -1}, {-1, 1}
28+
};
29+
30+
/// 指定Stoneの置けるマス一覧を更新するメソッド
31+
/// @param row 置いたマスの行番号 0~(n-1)
32+
/// @param col 置いたマスの列番号 0~(n-1)
33+
/// @param color 置いた石の色
34+
void updatePlaceableCellsWithStone(int row, int col, stone color);
35+
36+
/// おけるマス一覧を更新するメソッド
37+
/// @param row 置いたマスの行番号 0~(n-1)
38+
/// @param col 置いたマスの列番号 0~(n-1)
39+
void updatePlaceableCells(int row, int col);
40+
41+
42+
/// 指定方向に石を置けるかをチェックするメソッド
43+
/// @param row 置くマスの行番号 0~(n-1)
44+
/// @param col 置くマスの列番号 0~(n-1)
45+
/// @param color 置く石の色
46+
/// @param dir 方向
47+
bool isCanPlaceWithDirection(int row, int col, stone color, std::pair<int, int> dir);
48+
49+
50+
public:
51+
// コンストラクタ
52+
ReversiBoard();
53+
54+
/// 指定されたマスに石を置くメソッド
55+
/// @param row 置くマスの行番号 0~(n-1)
56+
/// @param col 置くマスの列番号 0~(n-1)
57+
/// @param color 置く石の色
58+
/// @return 石を置けたかどうか
59+
bool placeStone(int row, int col, stone color);
60+
61+
/// 指定されたマスに石を置けるかどうかをチェックするメソッド
62+
/// @param row 置くマスの行番号 0~(n-1)
63+
/// @param col 置くマスの列番号 0~(n-1)
64+
/// @param color 置く石の色
65+
bool isCanPlace(int row, int col, stone color);
66+
67+
/// 指定方向の石をひっくり返すメソッド
68+
void flip(int row, int col, stone color, std::pair<int, int> dir);
69+
70+
71+
/// 現在のボードを出力するメソッド
72+
/// @param mine 自分の石の色
73+
void printBoard(stone mine);
74+
};
75+
76+
77+
#endif //WORK01_REVERSIBOARD_H

header/Stone.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Created by matuyuhi on 2023/11/08.
3+
//
4+
5+
#ifndef WORK01_STONE_H
6+
#define WORK01_STONE_H
7+
8+
#include <string>
9+
#include <iostream>
10+
// リバーシの石の状態を表すenum
11+
enum class stone {
12+
Empty,
13+
Black,
14+
White
15+
};
16+
17+
inline stone operator!(stone s) {
18+
switch (s) {
19+
case stone::Black: return stone::White;
20+
case stone::White: return stone::Black;
21+
default: return stone::Empty;
22+
}
23+
}
24+
25+
inline std::string printStone(stone s) {
26+
switch (s) {
27+
case stone::Black: return "B ";
28+
case stone::White: return "W ";
29+
default: return " ";
30+
}
31+
}
32+
33+
#endif //WORK01_STONE_H

header/cout.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by matuyuhi on 2023/11/08.
3+
//
4+
5+
#ifndef WORK01_COUT_H
6+
#define WORK01_COUT_H
7+
8+
#define RESET "\033[0m"
9+
#define BLACK "\033[30m" /* Black */
10+
#define RED "\033[31m" /* Red */
11+
#define GREEN "\033[32m" /* Green */
12+
#define YELLOW "\033[33m" /* Yellow */
13+
#define BLUE "\033[34m" /* Blue */
14+
#define MAGENTA "\033[35m" /* Magenta */
15+
#define CYAN "\033[36m" /* Cyan */
16+
#define WHITE "\033[37m" /* White */
17+
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
18+
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
19+
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
20+
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
21+
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
22+
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
23+
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
24+
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
25+
26+
#endif //WORK01_COUT_H

0 commit comments

Comments
 (0)