|
| 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 |
0 commit comments