Skip to content

Commit 1a9cc0b

Browse files
committed
[mdaiter]: add CMake file for easier build
1 parent 754d3b8 commit 1a9cc0b

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2+
PROJECT(CONNECT4)
3+
SET(CONNECT4_VERSION_MAJOR 0)
4+
SET(CONNECT4_VERSION_MINOR 9)
5+
6+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -W -Wall -O3 -DNDEBUG")
7+
8+
ADD_LIBRARY(c4solver_dependencies STATIC
9+
Solver.cpp
10+
Solver.hpp
11+
Position.hpp
12+
TranspositionTable.hpp
13+
OpeningBook.hpp
14+
MoveSorter.hpp)
15+
16+
ADD_EXECUTABLE(c4solver
17+
main.cpp)
18+
19+
ADD_EXECUTABLE(c4generator
20+
generator.cpp)
21+
22+
TARGET_LINK_LIBRARIES(c4solver c4solver_dependencies)
23+
TARGET_LINK_LIBRARIES(c4generator c4solver_dependencies)
24+
25+
INSTALL(TARGETS c4solver_dependencies DESTINATION lib)
26+
INSTALL(TARGETS c4generator DESTINATION bin)
27+
INSTALL(TARGETS c4solver DESTINATION bin)

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
This C++ source code is published under AGPL v3 license.
44

55
Read the associated [step by step tutorial to build a perfect Connect 4 AI](http://blog.gamesolver.org) for explanations.
6+
7+
## Quick build
8+
```
9+
mkdir build && cd build
10+
cmake ../
11+
```

generator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ std::unordered_set<uint64_t> visited;
1313
* Explore and print all possible position under a given depth.
1414
* symetric positions are printed only once.
1515
*/
16-
void explore(const Position &P, char* pos_str, const int depth) {
16+
void explore(const Position &P, char* const pos_str, const int depth) {
1717
uint64_t key = P.key3();
1818
if(visited.count(key)) return; // already explored position
1919
visited.insert(key); // flag new position as visited
2020

21-
int nb_moves = P.nbMoves();
21+
const int nb_moves = P.nbMoves();
2222
if(nb_moves <= depth)
2323
std::cout << pos_str << std::endl;
2424
if(nb_moves >= depth) return; // do not explore at further depth
2525

26-
for(int i = 0; i < Position::WIDTH; i++) // explore all possible moves
26+
for(int i = 0; i < Position::WIDTH; ++i) // explore all possible moves
2727
if(P.canPlay(i) && !P.isWinningMove(i)) {
2828
Position P2(P);
2929
P2.playCol(i);
@@ -71,8 +71,9 @@ void generate_opening_book() {
7171
*/
7272
int main(int argc, char** argv) {
7373
if(argc > 1) {
74-
int depth = atoi(argv[1]);
75-
char pos_str[depth + 1] = {0};
74+
const int depth = atoi(argv[1]);
75+
char pos_str[depth + 1];
76+
memset(pos_str, 0, (depth + 1) * sizeof(int));
7677
explore(Position(), pos_str, depth);
7778
} else generate_opening_book();
7879
}

0 commit comments

Comments
 (0)