├── python ├── .res.txt ├── py_vliang_chinesechess │ ├── __init__.py │ ├── path.py │ ├── evaluator.py │ └── chessboard.py ├── .DS_Store ├── bin │ └── vliang_py_interface ├── create_bin.sh └── web_game.py ├── .idea ├── .name ├── misc.xml ├── vcs.xml ├── .gitignore ├── vliang-chinese-chess.iml ├── modules.xml └── encodings.xml ├── cmake-build-release ├── .cmake │ └── api │ │ └── v1 │ │ └── query │ │ ├── cache-v2 │ │ ├── cmakeFiles-v1 │ │ ├── codemodel-v2 │ │ └── toolchains-v1 ├── CMakeFiles │ ├── progress.marks │ ├── clion-environment.txt │ ├── cmake.check_cache │ ├── 3.20.2 │ │ ├── CompilerIdC │ │ │ └── CMakeCCompilerId.o │ │ ├── CMakeDetermineCompilerABI_C.bin │ │ ├── CMakeDetermineCompilerABI_CXX.bin │ │ ├── CompilerIdCXX │ │ │ └── CMakeCXXCompilerId.o │ │ ├── CMakeSystem.cmake │ │ ├── CMakeCCompiler.cmake │ │ └── CMakeCXXCompiler.cmake │ ├── vliang_chinese_chess.dir │ │ ├── main.cpp.o │ │ ├── py_interface.cpp.o │ │ ├── progress.make │ │ ├── flags.make │ │ ├── link.txt │ │ ├── cmake_clean.cmake │ │ ├── DependInfo.cmake │ │ ├── CXX.includecache │ │ ├── depend.make │ │ ├── depend.internal │ │ └── build.make │ ├── TargetDirectories.txt │ ├── clion-log.txt │ ├── CMakeDirectoryInformation.cmake │ ├── Makefile.cmake │ ├── Makefile2 │ └── CMakeError.log ├── vliang_chinese_chess ├── vliang_chinese_chess.exe ├── Testing │ └── Temporary │ │ └── LastTest.log ├── cmake_install.cmake ├── vliang_chinese_chess.cbp └── Makefile ├── .DS_Store ├── html ├── img │ ├── owl.ico │ ├── stype_1 │ │ ├── bg.jpg │ │ ├── bg.png │ │ ├── 棋子.png │ │ ├── b_c.png │ │ ├── b_j.png │ │ ├── b_m.png │ │ ├── b_p.png │ │ ├── b_s.png │ │ ├── b_x.png │ │ ├── b_z.png │ │ ├── dot.png │ │ ├── r_c.png │ │ ├── r_j.png │ │ ├── r_m.png │ │ ├── r_p.png │ │ ├── r_s.png │ │ ├── r_x.png │ │ ├── r_z.png │ │ ├── b_box.png │ │ ├── bg_源文件.png │ │ └── r_box.png │ └── stype_2 │ │ ├── bg.jpg │ │ ├── bg.png │ │ ├── 棋子.png │ │ ├── b_c.png │ │ ├── b_j.png │ │ ├── b_m.png │ │ ├── b_p.png │ │ ├── b_s.png │ │ ├── b_x.png │ │ ├── b_z.png │ │ ├── dot.png │ │ ├── r_c.png │ │ ├── r_j.png │ │ ├── r_m.png │ │ ├── r_p.png │ │ ├── r_s.png │ │ ├── r_x.png │ │ ├── r_z.png │ │ ├── b_box.png │ │ ├── bg_源文件.png │ │ └── r_box.png ├── css │ └── zzsc.css ├── index.html └── js │ └── play.js ├── test └── evaluator_so.cpp ├── CMakeLists.txt ├── cpp ├── include │ ├── quiescence.h │ ├── transition_table.hpp │ ├── alpha_beta.h │ ├── tree_creator.hpp │ ├── path_filter.h │ ├── mtdf.h │ ├── evaluator.h │ ├── tree_search.h │ ├── chessboard.h │ └── weights.h └── source │ ├── tree_search.cpp │ ├── mtdf.cpp │ ├── evaluator.cpp │ ├── alpha_beta.cpp │ └── quiescence.cpp ├── Readme.md ├── py_interface.cpp └── main.cpp /python/.res.txt: -------------------------------------------------------------------------------- 1 | 3,7,3,4,-7 -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | vliang_chinese_chess -------------------------------------------------------------------------------- /python/py_vliang_chinesechess/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake-build-release/.cmake/api/v1/query/cache-v2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake-build-release/.cmake/api/v1/query/cmakeFiles-v1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake-build-release/.cmake/api/v1/query/codemodel-v2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake-build-release/.cmake/api/v1/query/toolchains-v1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/.DS_Store -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/clion-environment.txt: -------------------------------------------------------------------------------- 1 | ToolSet: 1.0 (local)Options: 2 | 3 | Options: -------------------------------------------------------------------------------- /html/img/owl.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/owl.ico -------------------------------------------------------------------------------- /python/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/python/.DS_Store -------------------------------------------------------------------------------- /html/img/stype_1/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/bg.jpg -------------------------------------------------------------------------------- /html/img/stype_1/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/bg.png -------------------------------------------------------------------------------- /html/img/stype_1/棋子.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/棋子.png -------------------------------------------------------------------------------- /html/img/stype_2/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/bg.jpg -------------------------------------------------------------------------------- /html/img/stype_2/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/bg.png -------------------------------------------------------------------------------- /html/img/stype_2/棋子.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/棋子.png -------------------------------------------------------------------------------- /html/img/stype_1/b_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_c.png -------------------------------------------------------------------------------- /html/img/stype_1/b_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_j.png -------------------------------------------------------------------------------- /html/img/stype_1/b_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_m.png -------------------------------------------------------------------------------- /html/img/stype_1/b_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_p.png -------------------------------------------------------------------------------- /html/img/stype_1/b_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_s.png -------------------------------------------------------------------------------- /html/img/stype_1/b_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_x.png -------------------------------------------------------------------------------- /html/img/stype_1/b_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_z.png -------------------------------------------------------------------------------- /html/img/stype_1/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/dot.png -------------------------------------------------------------------------------- /html/img/stype_1/r_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_c.png -------------------------------------------------------------------------------- /html/img/stype_1/r_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_j.png -------------------------------------------------------------------------------- /html/img/stype_1/r_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_m.png -------------------------------------------------------------------------------- /html/img/stype_1/r_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_p.png -------------------------------------------------------------------------------- /html/img/stype_1/r_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_s.png -------------------------------------------------------------------------------- /html/img/stype_1/r_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_x.png -------------------------------------------------------------------------------- /html/img/stype_1/r_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_z.png -------------------------------------------------------------------------------- /html/img/stype_2/b_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_c.png -------------------------------------------------------------------------------- /html/img/stype_2/b_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_j.png -------------------------------------------------------------------------------- /html/img/stype_2/b_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_m.png -------------------------------------------------------------------------------- /html/img/stype_2/b_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_p.png -------------------------------------------------------------------------------- /html/img/stype_2/b_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_s.png -------------------------------------------------------------------------------- /html/img/stype_2/b_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_x.png -------------------------------------------------------------------------------- /html/img/stype_2/b_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_z.png -------------------------------------------------------------------------------- /html/img/stype_2/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/dot.png -------------------------------------------------------------------------------- /html/img/stype_2/r_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_c.png -------------------------------------------------------------------------------- /html/img/stype_2/r_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_j.png -------------------------------------------------------------------------------- /html/img/stype_2/r_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_m.png -------------------------------------------------------------------------------- /html/img/stype_2/r_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_p.png -------------------------------------------------------------------------------- /html/img/stype_2/r_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_s.png -------------------------------------------------------------------------------- /html/img/stype_2/r_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_x.png -------------------------------------------------------------------------------- /html/img/stype_2/r_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_z.png -------------------------------------------------------------------------------- /html/img/stype_1/b_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/b_box.png -------------------------------------------------------------------------------- /html/img/stype_1/bg_源文件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/bg_源文件.png -------------------------------------------------------------------------------- /html/img/stype_1/r_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_1/r_box.png -------------------------------------------------------------------------------- /html/img/stype_2/b_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/b_box.png -------------------------------------------------------------------------------- /html/img/stype_2/bg_源文件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/bg_源文件.png -------------------------------------------------------------------------------- /html/img/stype_2/r_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/html/img/stype_2/r_box.png -------------------------------------------------------------------------------- /python/bin/vliang_py_interface: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/python/bin/vliang_py_interface -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /cmake-build-release/vliang_chinese_chess: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/vliang_chinese_chess -------------------------------------------------------------------------------- /cmake-build-release/vliang_chinese_chess.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/vliang_chinese_chess.exe -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /cmake-build-release/Testing/Temporary/LastTest.log: -------------------------------------------------------------------------------- 1 | Start testing: Aug 14 17:45 CST 2 | ---------------------------------------------------------- 3 | End testing: Aug 14 17:45 CST 4 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CompilerIdC/CMakeCCompilerId.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/3.20.2/CompilerIdC/CMakeCCompilerId.o -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/main.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/main.cpp.o -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/3.20.2/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/3.20.2/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CompilerIdCXX/CMakeCXXCompilerId.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/3.20.2/CompilerIdCXX/CMakeCXXCompilerId.o -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RayZhhh/vliang-chinesechess-cpp/HEAD/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/vliang-chinese-chess.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | CMAKE_PROGRESS_3 = 3 4 | CMAKE_PROGRESS_4 = 4 5 | CMAKE_PROGRESS_5 = 5 6 | CMAKE_PROGRESS_6 = 6 7 | CMAKE_PROGRESS_7 = 7 8 | CMAKE_PROGRESS_8 = 8 9 | CMAKE_PROGRESS_9 = 9 10 | CMAKE_PROGRESS_10 = 10 11 | 12 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir 2 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/edit_cache.dir 3 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/rebuild_cache.dir 4 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /python/create_bin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "g++ -std=c++20 -O3 -o ./bin/vliang_py_interface ../py_interface.cpp ../cpp/source/*.cpp" 4 | 5 | # 创建bin目录 6 | if [ -f "bin" ] 7 | then 8 | echo "bin is already exist" 9 | else 10 | mkdir bin 11 | fi 12 | 13 | # 编译得到 vliang_py_interface 并放入 bin/ 目录下 14 | g++ -std=c++20 -O3 -o ./bin/vliang_py_interface ../py_interface.cpp ../cpp/source/*.cpp 15 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # compile CXX with /Library/Developer/CommandLineTools/usr/bin/c++ 5 | CXX_DEFINES = 6 | 7 | CXX_INCLUDES = 8 | 9 | CXX_FLAGS = -O3 -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -std=gnu++20 10 | 11 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/clion-log.txt: -------------------------------------------------------------------------------- 1 | /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - Unix Makefiles" -S /Users/zhangrui/Developer/vliang-chinesechess-cpp -B /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release 2 | -- Configuring done 3 | -- Generating done 4 | -- Build files have been written to: /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release 5 | -------------------------------------------------------------------------------- /test/evaluator_so.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/8/9. 3 | // 4 | 5 | 6 | #include 7 | #include 8 | #include "../cpp/include/evaluator.h" 9 | 10 | extern "C" 11 | void test() { 12 | Chessboard chessboard; 13 | ChessPath path = ChessPath(2, 1, 2, 4, 0); 14 | chessboard.move_chess(path); 15 | 16 | auto eva = MultiThreadEvaluator(chessboard, 8, TreeType::MTDF); 17 | eva.get_best_path(); 18 | } -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Darwin-21.3.0") 2 | set(CMAKE_HOST_SYSTEM_NAME "Darwin") 3 | set(CMAKE_HOST_SYSTEM_VERSION "21.3.0") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Darwin-21.3.0") 9 | set(CMAKE_SYSTEM_NAME "Darwin") 10 | set(CMAKE_SYSTEM_VERSION "21.3.0") 11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /python/py_vliang_chinesechess/path.py: -------------------------------------------------------------------------------- 1 | class ChessPath: 2 | def __init__(self, from_x=0, from_y=0, to_x=0, to_y=0, eat=0): 3 | self.from_x = from_x 4 | self.from_y = from_y 5 | self.to_x = to_x 6 | self.to_y = to_y 7 | self.eat = eat 8 | self.value = 0 9 | 10 | def __str__(self): 11 | return "ChessPath { <" + str(self.from_x) + ", " + str(self.from_y) + "> to <" + str(self.to_x) + ", " + str( 12 | self.to_y) + "> eat " + str(self.eat) + "}" 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | project(vliang_chinese_chess) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | add_executable(vliang_chinese_chess main.cpp cpp/include/chessboard.h cpp/include/zobrist_code.h cpp/include/weights.h cpp/source/chessboard.cpp cpp/include/alpha_beta.h cpp/include/tree_search.h cpp/source/tree_search.cpp cpp/include/evaluator.h cpp/include/tree_creator.hpp cpp/source/alpha_beta.cpp 7 | cpp/include/mtdf.h cpp/include/transition_table.hpp cpp/include/quiescence.h cpp/source/quiescence.cpp cpp/source/evaluator.cpp py_interface.cpp cpp/source/mtdf.cpp cpp/include/path_filter.h test/evaluator_so.cpp) 8 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/link.txt: -------------------------------------------------------------------------------- 1 | /Library/Developer/CommandLineTools/usr/bin/c++ -O3 -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/vliang_chinese_chess.dir/main.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o -o vliang_chinese_chess 2 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/Users/zhangrui/Developer/vliang-chinesechess-cpp") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /html/css/zzsc.css: -------------------------------------------------------------------------------- 1 | @charset "gb2312"; 2 | body { 3 | font-size: 12px; 4 | line-height: 150%; 5 | } 6 | .box { 7 | margin:0 auto; 8 | width:460px; 9 | position: relative; 10 | } 11 | .chess_left { 12 | float:left; 13 | text-align:center 14 | } 15 | .chess_right { 16 | float:left; 17 | display:none 18 | } 19 | .move_info { 20 | float:left; 21 | margin-top:20px 22 | } 23 | .bill_box { 24 | height: 320px; 25 | width: 80px; 26 | overflow:auto; 27 | } 28 | .bill_box li { 29 | cursor:pointer; 30 | text-align:left 31 | } 32 | .bill_box li:hover { 33 | cursor:pointer; 34 | background: #C6A577; 35 | } 36 | .bill_box li:active { 37 | cursor:pointer; 38 | background: #fff; 39 | } 40 | #billList { 41 | margin-top:20px 42 | } 43 | .bn_box { 44 | display:none 45 | } -------------------------------------------------------------------------------- /cpp/include/quiescence.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/29. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_QUIESCENCE_H 6 | #define VLIANG_CHINESE_CHESS_QUIESCENCE_H 7 | 8 | #include "tree_search.h" 9 | #include "alpha_beta.h" 10 | 11 | 12 | class Quiescence : public AlphaBeta { 13 | public: 14 | explicit Quiescence(Chessboard &board) : AlphaBeta(board) { 15 | } 16 | 17 | int quiescence(ChessPath &path, int alpha, int beta, int depth, int colorSign); 18 | 19 | int alpha_beta_quiescence_with_memory_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign); 20 | 21 | int eval_path_val(const ChessPath &path, int depth) override; 22 | 23 | int eval_path_val(const ChessPath &path, int depth, int color_sign) override; 24 | }; 25 | 26 | #endif //VLIANG_CHINESE_CHESS_QUIESCENCE_H 27 | -------------------------------------------------------------------------------- /cpp/include/transition_table.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Derek on 2022/5/28. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_TRANSITION_TABLE_HPP 6 | #define VLIANG_CHINESE_CHESS_TRANSITION_TABLE_HPP 7 | 8 | #include 9 | 10 | 11 | template 12 | class TranTable { 13 | 14 | unordered_map> map; 15 | 16 | public: 17 | 18 | inline TableMsg *get_table(int hash, int verify) { 19 | return map[hash][verify]; 20 | } 21 | 22 | inline void add_table(TableMsg *table, int hash, int verify) { 23 | map[hash][verify] = table; 24 | } 25 | 26 | ~TranTable() { 27 | for (auto &i: this->map) { 28 | for (auto &j : i.second) { 29 | delete j.second; 30 | } 31 | } 32 | } 33 | }; 34 | 35 | 36 | 37 | #endif //VLIANG_CHINESE_CHESS_TRANSITION_TABLE_HPP 38 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o" 3 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o" 4 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o" 5 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o" 6 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o" 7 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o" 8 | "CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o" 9 | "CMakeFiles/vliang_chinese_chess.dir/main.cpp.o" 10 | "CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o" 11 | "vliang_chinese_chess" 12 | "vliang_chinese_chess.pdb" 13 | ) 14 | 15 | # Per-language clean rules from dependency scanning. 16 | foreach(lang CXX) 17 | include(CMakeFiles/vliang_chinese_chess.dir/cmake_clean_${lang}.cmake OPTIONAL) 18 | endforeach() 19 | -------------------------------------------------------------------------------- /cpp/include/alpha_beta.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/24. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_ALPHA_BETA_H 6 | #define VLIANG_CHINESE_CHESS_ALPHA_BETA_H 7 | 8 | #include "tree_search.h" 9 | 10 | class AlphaBeta : public TreeSearchBase { 11 | public: 12 | explicit AlphaBeta(Chessboard &chessboard) : TreeSearchBase(chessboard) { 13 | } 14 | 15 | int eval_path_val(const ChessPath &path, int depth) override; 16 | 17 | int eval_path_val(const ChessPath &path, int depth, int color_sign) override; 18 | 19 | int alpha_beta_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign); 20 | }; 21 | 22 | 23 | class AlphaBetaWithMemory : public TreeSearchBase { 24 | public: 25 | explicit AlphaBetaWithMemory(Chessboard &chessboard) : TreeSearchBase(chessboard) { 26 | } 27 | 28 | int eval_path_val(const ChessPath &path, int depth) override; 29 | 30 | int eval_path_val(const ChessPath &path, int depth, int color_sign) override; 31 | 32 | int alpha_beta_with_memory_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign); 33 | }; 34 | 35 | 36 | #endif //VLIANG_CHINESE_CHESS_ALPHA_BETA_H 37 | -------------------------------------------------------------------------------- /cpp/include/tree_creator.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/25. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_TREE_CREATOR_HPP 6 | #define VLIANG_CHINESE_CHESS_TREE_CREATOR_HPP 7 | 8 | #include "alpha_beta.h" 9 | #include "mtdf.h" 10 | #include "quiescence.h" 11 | #include 12 | 13 | 14 | enum TreeType { 15 | ALPHA_BETA, 16 | ALPHA_BETA_WITH_MEMORY, 17 | MTDF, 18 | QUIE, 19 | MTDF_QUIE, 20 | ITER_DEEP 21 | }; 22 | 23 | 24 | class TreeCreator { 25 | public: 26 | 27 | static shared_ptr get_tree(Chessboard board, TreeType treeType) { 28 | switch (treeType) { 29 | 30 | case ALPHA_BETA: 31 | return std::make_shared(board); 32 | 33 | case ALPHA_BETA_WITH_MEMORY: 34 | return std::make_shared(board); 35 | 36 | case MTDF: 37 | return std::make_shared(board); 38 | 39 | case QUIE: 40 | return std::make_shared(board); 41 | 42 | case MTDF_QUIE: 43 | return std::make_shared(board); 44 | 45 | case ITER_DEEP: 46 | return std::make_shared(board); 47 | 48 | default: 49 | return nullptr; 50 | } 51 | } 52 | }; 53 | 54 | #endif //VLIANG_CHINESE_CHESS_TREE_CREATOR_HPP 55 | -------------------------------------------------------------------------------- /cmake-build-release/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /Users/zhangrui/Developer/vliang-chinesechess-cpp 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "/usr/local") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "Release") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Is this installation the result of a crosscompile? 31 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 32 | set(CMAKE_CROSSCOMPILING "FALSE") 33 | endif() 34 | 35 | # Set default install directory permissions. 36 | if(NOT DEFINED CMAKE_OBJDUMP) 37 | set(CMAKE_OBJDUMP "/Library/Developer/CommandLineTools/usr/bin/objdump") 38 | endif() 39 | 40 | if(CMAKE_INSTALL_COMPONENT) 41 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 42 | else() 43 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 44 | endif() 45 | 46 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT 47 | "${CMAKE_INSTALL_MANIFEST_FILES}") 48 | file(WRITE "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/${CMAKE_INSTALL_MANIFEST}" 49 | "${CMAKE_INSTALL_MANIFEST_CONTENT}") 50 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # 微量 - 中国象棋 Vliang - Chinese Chess 2 | 3 | ------ 4 | 👤作者:睿 5 | 6 | 📧邮件:rayZhh@163.com 7 | 8 | ------ 9 | 10 | ![](./pics/vliang-cpp.jpeg) 11 | 12 | ## 简介 13 | 14 | 这个项目是我仓库中使用java实现的 [vlumino-chinese chess] 的c++复现,同时优化了代码的结构,优化了置换表和历史表。 经对比,相同局面新的项目评估速度更快(约3倍的性能)。 15 | 和我仓库中java项目相同:采用多线程加速评估。开局和中盘棋力还不错。开局支持深度为6+8的静态搜索,或者深度为8的mtd(f)搜索。随着后面盘面的简化允许更高的深度。 评估的速度和CPU性能相关。以我的电脑 19 15.4 macbook 16 | pro 为例:CPU型号为 Core i9-9880h @2.3GHz,开局阶段使用深度为8的mtd(f)搜索时间约为3-5秒,这已经是非常不错的成绩了,我相信这得益于c++优良的性能和采用的各种剪枝算法。 17 | 18 | 相比我的java的实现稍有改进,因此我在开局尝试深度为6+10的静态搜索,发现效果很不错。于是在这个版本中我不准备设计开局库了。 19 | 20 | ## 支持的算法 21 | 22 | ·记忆化的alpha-beta搜索(历史表启发,置换表优化) 23 | 24 | ·mtd(f)搜索 25 | 26 | ·静态搜索 27 | 28 | ·所有搜索算法都使用多线程优化,每个线程负责一个候选路径的评估。 29 | 30 | ## 说明 31 | 32 | ·main.cpp中有控制台游戏,直接运行即可。可以尝试不同的搜索算法。 33 | 34 | ·暂时不支持开局库(事实上我发现使用静态搜索进行开局效果还不错)。 35 | 36 | ·核心算法用c++实现,编译后使用python调用exe作为接口,方便快速构建服务端。 37 | 38 | ·我对前端一窍不通,因此前端是抄的,具体逻辑稍微改了下,倒是能玩。 39 | 40 | ## 编译运行(命令行运行) 41 | MacOS 42 | ```shell 43 | g++ -std=c++20 -O3 -o chess main.cpp cpp/source/*.cpp 44 | ./chess 45 | ``` 46 | Linux 47 | ```shell 48 | g++ -std=c++2a -O3 -o chess main.cpp cpp/source/*.cpp -lpthread 49 | ``` 50 | 51 | ## GUI 52 | 53 | 1.运行 [python/web_game.py] 54 | 55 | 2.在浏览器中打开 [web/index.html] 56 | 然后就可以玩了。 在 web_game.py中可以调节搜索方式和搜索深度。一般开局使用深度为8的mtdf搜索[TreeType.MTDF],或深度为6的静态搜索[TreeType.MTDF_QUIE](推荐,目测更强)。 57 | 58 | ## 如何进行评估? 59 | 60 | ```c++ 61 | #include "include/multi_thread_evaluator.h" 62 | 63 | int main() { 64 | Chessboard board; 65 | 66 | board.move_chess(ChessPath(2, 1, 2, 4, 0)); 67 | 68 | board.print_chessboard(); 69 | 70 | // 创建评估器,有这两种方式,目前仅支持多线程评估器 71 | // 如果需要评估 《棋子为正数一方》的最佳路径,传入 TreeSearchBase::MAX_LAYER_SIGN,反之用MIN 72 | MultiThreadEvaluator evaluator(board, 8, TreeType::MTDF /* , TreeSearchBase::MAX_LAYER_SIGN */); 73 | MultiThreadEvalautor evalator_1(board, 6, TreeType::MTDF_QUIE, TreeSearchBase::MAX_LAYER_SIGN ); 74 | 75 | // 评估 76 | auto path = evaluator.get_best_path(); 77 | // 落子 78 | board.move_chess(path); 79 | 80 | return 0; 81 | } 82 | ``` 83 | 84 | ## 一些问题 85 | 86 | 暂时无法避免长将,长抓等问题。不过这些都不涉及核心的算法,比较好解决。 87 | -------------------------------------------------------------------------------- /cpp/include/path_filter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/8/1. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_PATH_FILTER_H 6 | #define VLIANG_CHINESE_CHESS_PATH_FILTER_H 7 | 8 | 9 | class GameRecorder { 10 | 11 | class RecorderTable { 12 | public: 13 | int time = 1; 14 | }; 15 | 16 | public: 17 | 18 | int max_repeat_times; 19 | 20 | GameRecorder() { 21 | max_repeat_times = 5; 22 | } 23 | 24 | unordered_map> record_map{}; 25 | 26 | /** 27 | * 记录当前的棋盘 28 | * @param board 29 | */ 30 | void recode(Chessboard board) { 31 | RecorderTable *rt; 32 | if ((rt = record_map[board.get_hash()][board.get_verify()]) != nullptr) { 33 | rt->time++; 34 | } else { 35 | record_map[board.get_hash()][board.get_verify()] = new RecorderTable(); 36 | } 37 | } 38 | 39 | /** 40 | * 查询在当前 board 下,如果要走path那么出现的盘面次数 41 | * @param board 42 | * @return 43 | */ 44 | int find_same_times(Chessboard board) { 45 | RecorderTable *rt; 46 | if ((rt = record_map[board.get_hash()][board.get_verify()]) != nullptr) { 47 | return rt->time; 48 | } else { 49 | return 0; 50 | } 51 | } 52 | 53 | /** 54 | * 筛选路径。 55 | * 对打过分的路径进行筛选。将路径得分按照从高到低排序,依次查看每个路径落子后的棋盘情况。 56 | * 如果当前落子方法导致棋盘局面重复超过某个次数那么放弃这种走法。否则选择这种走法。 57 | * 58 | * 获得路径后不会记录落子后的盘面情况。 59 | * 60 | * @param board 61 | * @param paths 62 | * @return 63 | */ 64 | ChessPath choose_path(Chessboard board, paths_t &paths) { 65 | for (auto &path : paths) { 66 | int times = find_same_times(board); 67 | if (times > max_repeat_times) { 68 | continue; 69 | } else { 70 | return path; 71 | } 72 | } 73 | } 74 | 75 | ~GameRecorder() { 76 | for (auto &i : record_map) { 77 | for (auto &j : i.second) { 78 | delete j.second; 79 | } 80 | } 81 | } 82 | }; 83 | 84 | #endif //VLIANG_CHINESE_CHESS_PATH_FILTER_H 85 | -------------------------------------------------------------------------------- /cpp/include/mtdf.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/27. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_MTDF_H 6 | #define VLIANG_CHINESE_CHESS_MTDF_H 7 | 8 | #include "tree_search.h" 9 | #include "alpha_beta.h" 10 | #include "quiescence.h" 11 | 12 | 13 | class MTDF_Searching : public AlphaBetaWithMemory { 14 | 15 | public: 16 | /** 17 | * beta变量的初始值,这个值越接近真实值,计算时间越快 18 | */ 19 | int mtdf_init_value = 0; 20 | 21 | /** 22 | * 是否估计beta变量的初始值 23 | */ 24 | bool estimate_MTDF_init_value = true; 25 | 26 | explicit MTDF_Searching(Chessboard &board) : AlphaBetaWithMemory(board) {} 27 | 28 | /** 29 | * 估计beta变量的初始值 30 | * 31 | * 采用的方式是降低深度进行一轮搜索,得到的值作为估计值 32 | * @param chess_path 33 | * @param depth 34 | * @param color_sign 35 | */ 36 | void estimate_init_value(ChessPath &chess_path, int depth, int color_sign); 37 | 38 | int mtdf_eval(ChessPath &chess_path, int beta, int depth, int color_sign); 39 | 40 | int eval_path_val(const ChessPath &path, int depth) override; 41 | 42 | int eval_path_val(const ChessPath &path, int depth, int color_sign) override; 43 | }; 44 | 45 | 46 | class MTDF_Quiescence_Searching : public Quiescence { 47 | 48 | public: 49 | 50 | /** 51 | * beta变量的初始值,这个值越接近真实值,计算时间越快 52 | */ 53 | int mtdf_init_value; 54 | 55 | /** 56 | * 是否估计beta变量的初始值 57 | */ 58 | bool estimate_MTDF_init_value = true; 59 | 60 | explicit MTDF_Quiescence_Searching(Chessboard &board) : Quiescence(board) {} 61 | 62 | /** 63 | * 估计beta变量的初始值 64 | * 65 | * 采用的方式是降低深度进行一轮搜索,得到的值作为估计值 66 | * @param chess_path 67 | * @param depth 68 | * @param color_sign 69 | */ 70 | void estimate_init_value(ChessPath &chess_path, int depth, int color_sign); 71 | 72 | int mtdf_quiescence_eval(ChessPath &chess_path, int beta, int depth, int color_sign); 73 | 74 | int eval_path_val(const ChessPath &path, int depth) override; 75 | 76 | int eval_path_val(const ChessPath &path, int depth, int color_sign) override; 77 | }; 78 | 79 | 80 | class IterDeepening : public MTDF_Searching { 81 | public: 82 | explicit IterDeepening(Chessboard &board) : MTDF_Searching(board) {} 83 | 84 | int iter_deepening_eval(ChessPath &path, int depth, int color_sign); 85 | 86 | int eval_path_val(const ChessPath &path, int depth) override; 87 | }; 88 | 89 | #endif //VLIANG_CHINESE_CHESS_MTDF_H -------------------------------------------------------------------------------- /html/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | vlumino-中国象棋 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 对不起,您的浏览器不支持HTML5,请升级浏览器至IE9、firefox或者谷歌浏览器! 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 |
32 |
33 |
34 |
35 | 37 |
    38 |
39 |
40 |
41 |
42 | 43 | 44 | 45 | 46 | 47 |
48 |
49 | 50 | -------------------------------------------------------------------------------- /cpp/source/tree_search.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/24. 3 | // 4 | 5 | #include "../include/tree_search.h" 6 | 7 | 8 | void TreeSearchBase::update_lo_bound(TableMsg *msg, int lo_bound, int color_sign, int depth, int hash, int ver, ChessPath &path) { 9 | // 如果能找到当前盘面 10 | if (msg != nullptr) { 11 | 12 | // 当前局面搜索更深 13 | if (depth > msg->lo_depth) { 14 | msg->lo_bound = lo_bound; 15 | msg->lo_depth = depth; 16 | msg->best_path = path; 17 | } else if (depth == msg->lo_depth) { 18 | // msg->lo_bound = msg->lo_bound > lo_bound ? msg->lo_bound : lo_bound; 19 | // msg->best_path = path; 20 | if (msg->lo_bound < lo_bound) { 21 | msg->lo_bound = lo_bound; 22 | msg->best_path = path; 23 | } 24 | } 25 | 26 | } else { // 没有找到盘面,新建置换表并进行保存 27 | 28 | auto tmp = new TableMsg(); 29 | tmp->lo_bound = lo_bound; 30 | tmp->lo_depth = depth; 31 | tmp->best_path = path; 32 | 33 | // 保存到对应搜索层的置换表 34 | if (color_sign == MAX_LAYER_SIGN) { 35 | tran_table_max.add_table(tmp, hash, ver); 36 | } else { 37 | tran_table_min.add_table(tmp, hash, ver); 38 | } 39 | } 40 | } 41 | 42 | 43 | void TreeSearchBase::update_up_bound(TableMsg *msg, int up_bound, int color_sign, int depth, int hash, int ver, ChessPath &path) { 44 | 45 | // 如果能找到当前盘面 46 | if (msg != nullptr) { 47 | 48 | // 当前局面搜索更深 49 | if (depth > msg->up_depth) { 50 | msg->up_bound = up_bound; 51 | msg->up_depth = depth; 52 | msg->best_path = path; 53 | } else if (depth == msg->up_depth) { 54 | // msg->up_bound = msg->up_bound > up_bound ? msg->up_bound : up_bound; 55 | // msg->best_path = path; 56 | if (msg->up_bound > up_bound) { 57 | msg->up_bound = up_bound; 58 | msg->best_path = path; 59 | } 60 | } 61 | 62 | } else { // 没有找到盘面,新建置换表并进行保存 63 | auto tmp = new TableMsg(); 64 | tmp->up_bound = up_bound; 65 | tmp->up_depth = depth; 66 | tmp->best_path = path; 67 | 68 | // 保存到对应搜索层的置换表 69 | if (color_sign == MAX_LAYER_SIGN) { 70 | tran_table_max.add_table(tmp, hash, ver); 71 | } else { 72 | tran_table_min.add_table(tmp, hash, ver); 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Consider dependencies only in project. 3 | set(CMAKE_DEPENDS_IN_PROJECT_ONLY OFF) 4 | 5 | # The set of languages for which implicit dependencies are needed: 6 | set(CMAKE_DEPENDS_LANGUAGES 7 | "CXX" 8 | ) 9 | # The set of files for implicit dependencies of each language: 10 | set(CMAKE_DEPENDS_CHECK_CXX 11 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/alpha_beta.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o" 12 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/chessboard.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o" 13 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/evaluator.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o" 14 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/mtdf.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o" 15 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/quiescence.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o" 16 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/tree_search.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o" 17 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/evaluator_so.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o" 18 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/main.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/main.cpp.o" 19 | "/Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp" "/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o" 20 | ) 21 | set(CMAKE_CXX_COMPILER_ID "AppleClang") 22 | 23 | # The include file search paths: 24 | set(CMAKE_CXX_TARGET_INCLUDE_PATH 25 | ) 26 | 27 | # The set of dependency files which are needed: 28 | set(CMAKE_DEPENDS_DEPENDENCY_FILES 29 | ) 30 | 31 | # Targets to which this target links. 32 | set(CMAKE_TARGET_LINKED_INFO_FILES 33 | ) 34 | 35 | # Fortran module output directory. 36 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 37 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/cc") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "AppleClang") 4 | set(CMAKE_C_COMPILER_VERSION "13.0.0.13000029") 5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_C_COMPILER_WRAPPER "") 7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11") 8 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert") 9 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") 10 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") 11 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") 12 | 13 | set(CMAKE_C_PLATFORM_ID "Darwin") 14 | set(CMAKE_C_SIMULATE_ID "") 15 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") 16 | set(CMAKE_C_SIMULATE_VERSION "") 17 | 18 | 19 | 20 | 21 | set(CMAKE_AR "/Library/Developer/CommandLineTools/usr/bin/ar") 22 | set(CMAKE_C_COMPILER_AR "") 23 | set(CMAKE_RANLIB "/Library/Developer/CommandLineTools/usr/bin/ranlib") 24 | set(CMAKE_C_COMPILER_RANLIB "") 25 | set(CMAKE_LINKER "/Library/Developer/CommandLineTools/usr/bin/ld") 26 | set(CMAKE_MT "") 27 | set(CMAKE_COMPILER_IS_GNUCC ) 28 | set(CMAKE_C_COMPILER_LOADED 1) 29 | set(CMAKE_C_COMPILER_WORKS TRUE) 30 | set(CMAKE_C_ABI_COMPILED TRUE) 31 | set(CMAKE_COMPILER_IS_MINGW ) 32 | set(CMAKE_COMPILER_IS_CYGWIN ) 33 | if(CMAKE_COMPILER_IS_CYGWIN) 34 | set(CYGWIN 1) 35 | set(UNIX 1) 36 | endif() 37 | 38 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 39 | 40 | if(CMAKE_COMPILER_IS_MINGW) 41 | set(MINGW 1) 42 | endif() 43 | set(CMAKE_C_COMPILER_ID_RUN 1) 44 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 45 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 46 | set(CMAKE_C_LINKER_PREFERENCE 10) 47 | 48 | # Save compiler ABI information. 49 | set(CMAKE_C_SIZEOF_DATA_PTR "8") 50 | set(CMAKE_C_COMPILER_ABI "") 51 | set(CMAKE_C_BYTE_ORDER "LITTLE_ENDIAN") 52 | set(CMAKE_C_LIBRARY_ARCHITECTURE "") 53 | 54 | if(CMAKE_C_SIZEOF_DATA_PTR) 55 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 56 | endif() 57 | 58 | if(CMAKE_C_COMPILER_ABI) 59 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 60 | endif() 61 | 62 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 63 | set(CMAKE_LIBRARY_ARCHITECTURE "") 64 | endif() 65 | 66 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 67 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 68 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 69 | endif() 70 | 71 | 72 | 73 | 74 | 75 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include;/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include;/Library/Developer/CommandLineTools/usr/include") 76 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") 77 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib") 78 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks") 79 | -------------------------------------------------------------------------------- /python/py_vliang_chinesechess/evaluator.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import time 3 | 4 | from python.py_vliang_chinesechess.chessboard import Chessboard 5 | from python.py_vliang_chinesechess.path import ChessPath 6 | 7 | 8 | class TreeType: 9 | ALPHA_BETA = "ALPHA_BETA" 10 | ALPHA_BETA_WITH_MEMORY = "ALPHA_BETA_WITH_MEMORY" 11 | MTDF = "MTDF" 12 | QUIE = "QUIE" 13 | ITER_DEEP = "ITER_DEEP" 14 | MTDF_QUIE = "MTDF_QUIE" 15 | 16 | 17 | class MultiThreadEvaluator: 18 | """ 19 | --Invoke [vliang_py_interface.exe] as the interface. 20 | --The cpp implementation of [vliang_py_interface.exe] locates at https://github.com/RayZhhh/vliang-chinesechess-cpp. 21 | --Support for multi-threaded evaluation. 22 | """ 23 | 24 | def __init__(self, interface_path, chessboard, tree_type, depth, color_sign, res_path='.res.txt'): 25 | self.interface_path = interface_path 26 | self.chessboard = chessboard 27 | self.tree_type = tree_type 28 | self.depth = depth 29 | self.res_path = res_path 30 | self.color_sign = color_sign 31 | 32 | def get_best_path(self): 33 | board_str = self.chessboard.parse_to_interface_str() 34 | subprocess.run( 35 | [self.interface_path, board_str, self.tree_type, str(self.depth), self.color_sign, self.res_path]) 36 | fin = open(self.res_path, 'r') 37 | path_res = fin.readline() 38 | res_arr = path_res.split(",") 39 | return ChessPath(int(res_arr[0]), int(res_arr[1]), int(res_arr[2]), int(res_arr[3]), int(res_arr[4])) 40 | 41 | 42 | class DeepeningMultiThreadEvaluator(MultiThreadEvaluator): 43 | """ 44 | --The search depth will be automatically added while evaluating 45 | """ 46 | 47 | def __init__(self, interface_path, chessboard, tree_type, depth, color_sign, res_path): 48 | super(DeepeningMultiThreadEvaluator, self).__init__(interface_path, chessboard, tree_type, depth, color_sign, 49 | res_path) 50 | self.time_threshold_in_second = 0.8 51 | 52 | def get_best_path(self): 53 | real_search_depth = self.depth 54 | while True: 55 | beg = time.time() 56 | path = MultiThreadEvaluator.get_best_path(self) 57 | if time.time() - beg > self.time_threshold_in_second or \ 58 | (self.color_sign == Chessboard.MIN_LAYER_SIGN and path.value >= 7000) or \ 59 | (self.color_sign == Chessboard.MAX_LAYER_SIGN and path.value <= -7000): 60 | break 61 | else: 62 | self.depth += 2 63 | self.depth = real_search_depth 64 | return path 65 | 66 | 67 | if __name__ == '__main__': 68 | board = Chessboard() 69 | board.move_chess(ChessPath(2, 1, 2, 4)) 70 | board.print_chessboard() 71 | evaluator = MultiThreadEvaluator("../bin/vliang_py_interface", board, TreeType.MTDF, 8, Chessboard.MAX_LAYER_SIGN, 72 | ".res.txt") 73 | print(evaluator.get_best_path()) 74 | -------------------------------------------------------------------------------- /python/py_vliang_chinesechess/chessboard.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | from .path import ChessPath 4 | 5 | 6 | class Chessboard: 7 | MIN_LAYER_SIGN = "MIN_LAYER_SIGN" 8 | MAX_LAYER_SIGN = "MAX_LAYER_SIGN" 9 | 10 | def __init__(self): 11 | self.board = [ 12 | [-1, -2, -3, -4, -5, -4, -3, -2, -1], 13 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 14 | [0, -6, 0, 0, 0, 0, 0, -6, 0], 15 | [-7, 0, -7, 0, -7, 0, -7, 0, -7], 16 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 17 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 18 | [7, 0, 7, 0, 7, 0, 7, 0, 7], 19 | [0, 6, 0, 0, 0, 0, 0, 6, 0], 20 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 21 | [1, 2, 3, 4, 5, 4, 3, 2, 1]] 22 | 23 | def parse_to_interface_str(self): 24 | ret = "" 25 | for row in self.board: 26 | for i in row: 27 | ret += str(i + 20) 28 | return ret 29 | 30 | def move_chess(self, path: ChessPath): 31 | self.board[path.to_x][path.to_y] = self.board[path.from_x][path.from_y] 32 | self.board[path.from_x][path.from_y] = 0 33 | 34 | def undo_move_chess(self, path: ChessPath): 35 | self.board[path.from_x][path.from_y] = self.board[path.to_x][path.to_y] 36 | self.board[path.to_x][path.to_y] = path.eat 37 | 38 | def print_chessboard(self): 39 | print("%6s" % "", end="") 40 | for i in range(0, 9): 41 | print("%6d" % i, end="") 42 | print("") 43 | print(" --------------------------------------------------------\n") 44 | for i in range(0, 10): 45 | print("%6s" % self.num2char(i), end="") 46 | for j in range(0, 9): 47 | if self.board[i][j] == 0: 48 | print("%6c" % '.', end="") 49 | else: 50 | print("%6d" % self.board[i][j], end="") 51 | print("\n") 52 | print("\n") 53 | 54 | def clear_board(self): 55 | self.board = [ 56 | [-1, -2, -3, -4, -5, -4, -3, -2, -1], 57 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 58 | [0, -6, 0, 0, 0, 0, 0, -6, 0], 59 | [-7, 0, -7, 0, -7, 0, -7, 0, -7], 60 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 61 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 62 | [7, 0, 7, 0, 7, 0, 7, 0, 7], 63 | [0, 6, 0, 0, 0, 0, 0, 6, 0], 64 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 65 | [1, 2, 3, 4, 5, 4, 3, 2, 1]] 66 | 67 | def num2char(self, chess_id: int): 68 | if chess_id == 0: 69 | return "零" 70 | elif chess_id == 1: 71 | return "一" 72 | elif chess_id == 2: 73 | return "二" 74 | elif chess_id == 3: 75 | return "三" 76 | elif chess_id == 4: 77 | return "四" 78 | elif chess_id == 5: 79 | return "五" 80 | elif chess_id == 6: 81 | return "六" 82 | elif chess_id == 7: 83 | return "七" 84 | elif chess_id == 8: 85 | return "八" 86 | elif chess_id == 9: 87 | return "九" 88 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/CXX.includecache: -------------------------------------------------------------------------------- 1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) 2 | 3 | #IncludeRegexScan: ^.*$ 4 | 5 | #IncludeRegexComplain: ^$ 6 | 7 | #IncludeRegexTransform: 8 | 9 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 10 | tree_search.h 11 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 12 | 13 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 14 | iostream 15 | - 16 | vector 17 | - 18 | algorithm 19 | - 20 | sstream 21 | - 22 | weights.h 23 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 24 | zobrist_code.h 25 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 26 | 27 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/evaluator.h 28 | tree_search.h 29 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 30 | tree_creator.hpp 31 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_creator.hpp 32 | thread 33 | - 34 | ctime 35 | - 36 | iomanip 37 | - 38 | path_filter.h 39 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/path_filter.h 40 | 41 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 42 | tree_search.h 43 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 44 | alpha_beta.h 45 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 46 | quiescence.h 47 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 48 | 49 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/path_filter.h 50 | 51 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 52 | tree_search.h 53 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 54 | alpha_beta.h 55 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 56 | 57 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 58 | unordered_map 59 | - 60 | 61 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_creator.hpp 62 | alpha_beta.h 63 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 64 | mtdf.h 65 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 66 | quiescence.h 67 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 68 | memory 69 | - 70 | 71 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 72 | chessboard.h 73 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 74 | transition_table.hpp 75 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 76 | 77 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 78 | 79 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 80 | 81 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp 82 | fstream 83 | - 84 | iostream 85 | - 86 | cpp/include/evaluator.h 87 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/evaluator.h 88 | 89 | -------------------------------------------------------------------------------- /python/web_game.py: -------------------------------------------------------------------------------- 1 | from http.server import BaseHTTPRequestHandler, HTTPServer 2 | import logging 3 | import json 4 | from py_vliang_chinesechess.evaluator import * 5 | from py_vliang_chinesechess.chessboard import Chessboard 6 | from sys import argv 7 | 8 | 9 | class VliangServer(BaseHTTPRequestHandler): 10 | 11 | # def do_GET(self): 12 | # self.send_response(200) 13 | # self.send_header('Content-type', 'text/html;charset=UTF-8') 14 | # self.end_headers() 15 | # f = open('../html/index.html', 'r') 16 | # output = f.read() 17 | # print(output) 18 | # output = bytes(output, 'UTF-8') 19 | # self.wfile.write(output) 20 | 21 | def do_POST(self): 22 | # get the size of data 23 | content_length = int(self.headers['Content-Length']) 24 | post_data = self.rfile.read(content_length).decode('utf-8') 25 | 26 | json_dict = json.loads(post_data) 27 | # print(json_dict["chessboard"]) 28 | board_str = json_dict["chessboard"] 29 | board_arr = board_str.split(";") 30 | 31 | # eval 32 | eval_board = Chessboard() 33 | pos = 0 34 | for i in range(0, 10): 35 | for j in range(0, 9): 36 | eval_board.board[i][j] = int(board_arr[pos]) 37 | pos += 1 38 | 39 | eval_board.print_chessboard() 40 | evaluator = DeepeningMultiThreadEvaluator(interface_path='./bin/vliang_py_interface', 41 | chessboard=eval_board, 42 | tree_type=TreeType.MTDF_QUIE, 43 | depth=6, 44 | color_sign=Chessboard.MAX_LAYER_SIGN, 45 | res_path='./.res.txt') 46 | path = evaluator.get_best_path() 47 | resp_msg = str(path.from_x) + ";" + str(path.from_y) + ";" + str(path.to_x) + ";" + str(path.to_y) 48 | # print(resp_msg) 49 | self.send_response(200) 50 | self.send_header('Content-type', 'text/html;charset=UTF-8') 51 | self.send_header("Access-Control-Allow-Origin", "*") 52 | self.send_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT") 53 | self.send_header("Access-Control-Max-Age", "3600") 54 | self.send_header("Access-Control-Allow-Headers", "Content-Type, Access-Token, Authorization, ybg") 55 | self.end_headers() 56 | self.wfile.write(resp_msg.encode('utf-8')) 57 | 58 | 59 | def run(server_class=HTTPServer, handler_class=VliangServer, port=8080): 60 | logging.basicConfig(level=logging.INFO) 61 | server_address = ('', port) 62 | httpd = server_class(server_address, handler_class) 63 | logging.info('VLIANG-Chinese-Chess server starts.\n') 64 | try: 65 | httpd.serve_forever() 66 | except KeyboardInterrupt: 67 | pass 68 | httpd.server_close() 69 | print("httpd.server_close()") 70 | logging.info('Stopping httpd...\n') 71 | 72 | 73 | if __name__ == '__main__': 74 | run(port=8080) 75 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/depend.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o: \ 5 | ../cpp/include/alpha_beta.h \ 6 | ../cpp/include/chessboard.h \ 7 | ../cpp/include/transition_table.hpp \ 8 | ../cpp/include/tree_search.h \ 9 | ../cpp/include/weights.h \ 10 | ../cpp/include/zobrist_code.h \ 11 | ../cpp/source/alpha_beta.cpp 12 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o: \ 13 | ../cpp/include/chessboard.h \ 14 | ../cpp/include/weights.h \ 15 | ../cpp/include/zobrist_code.h \ 16 | ../cpp/source/chessboard.cpp 17 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o: \ 18 | ../cpp/include/alpha_beta.h \ 19 | ../cpp/include/chessboard.h \ 20 | ../cpp/include/evaluator.h \ 21 | ../cpp/include/mtdf.h \ 22 | ../cpp/include/path_filter.h \ 23 | ../cpp/include/quiescence.h \ 24 | ../cpp/include/transition_table.hpp \ 25 | ../cpp/include/tree_creator.hpp \ 26 | ../cpp/include/tree_search.h \ 27 | ../cpp/include/weights.h \ 28 | ../cpp/include/zobrist_code.h \ 29 | ../cpp/source/evaluator.cpp 30 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o: \ 31 | ../cpp/include/alpha_beta.h \ 32 | ../cpp/include/chessboard.h \ 33 | ../cpp/include/mtdf.h \ 34 | ../cpp/include/quiescence.h \ 35 | ../cpp/include/transition_table.hpp \ 36 | ../cpp/include/tree_search.h \ 37 | ../cpp/include/weights.h \ 38 | ../cpp/include/zobrist_code.h \ 39 | ../cpp/source/mtdf.cpp 40 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o: \ 41 | ../cpp/include/alpha_beta.h \ 42 | ../cpp/include/chessboard.h \ 43 | ../cpp/include/quiescence.h \ 44 | ../cpp/include/transition_table.hpp \ 45 | ../cpp/include/tree_search.h \ 46 | ../cpp/include/weights.h \ 47 | ../cpp/include/zobrist_code.h \ 48 | ../cpp/source/quiescence.cpp 49 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o: \ 50 | ../cpp/include/chessboard.h \ 51 | ../cpp/include/transition_table.hpp \ 52 | ../cpp/include/tree_search.h \ 53 | ../cpp/include/weights.h \ 54 | ../cpp/include/zobrist_code.h \ 55 | ../cpp/source/tree_search.cpp 56 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o: \ 57 | ../cpp/include/alpha_beta.h \ 58 | ../cpp/include/chessboard.h \ 59 | ../cpp/include/evaluator.h \ 60 | ../cpp/include/mtdf.h \ 61 | ../cpp/include/path_filter.h \ 62 | ../cpp/include/quiescence.h \ 63 | ../cpp/include/transition_table.hpp \ 64 | ../cpp/include/tree_creator.hpp \ 65 | ../cpp/include/tree_search.h \ 66 | ../cpp/include/weights.h \ 67 | ../cpp/include/zobrist_code.h \ 68 | ../evaluator_so.cpp 69 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.o: \ 70 | ../main.cpp 71 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o: \ 72 | ../cpp/include/alpha_beta.h \ 73 | ../cpp/include/chessboard.h \ 74 | ../cpp/include/evaluator.h \ 75 | ../cpp/include/mtdf.h \ 76 | ../cpp/include/path_filter.h \ 77 | ../cpp/include/quiescence.h \ 78 | ../cpp/include/transition_table.hpp \ 79 | ../cpp/include/tree_creator.hpp \ 80 | ../cpp/include/tree_search.h \ 81 | ../cpp/include/weights.h \ 82 | ../cpp/include/zobrist_code.h \ 83 | ../py_interface.cpp 84 | -------------------------------------------------------------------------------- /py_interface.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/6/4. 3 | // 4 | #include 5 | #include 6 | #include "cpp/include/evaluator.h" 7 | 8 | #define COMPILE_PY_INTERFACE 9 | 10 | #ifdef COMPILE_PY_INTERFACE 11 | 12 | class ArgParser { 13 | public: 14 | 15 | Chessboard board; 16 | TreeType tree_type; 17 | int depth{}; 18 | int color_sign; 19 | 20 | void parse_chessboard(const string &str) { 21 | chessboard_t chessboard; 22 | 23 | for (int i = 0; i < 90; i++) { 24 | string id_str = string(str.begin() + i * 2, str.begin() + i * 2 + 2); 25 | int id = stoi(id_str); 26 | int chess_id = id - 20; 27 | chessboard[i % 9][i - i % 9 * 9] = chess_id; 28 | } 29 | 30 | Chessboard ret; 31 | ret.copy(chessboard); 32 | this->board = ret; 33 | } 34 | 35 | void parse_tree_type(const string &tree_type_str) { 36 | if ("ALPHA_BETA" == tree_type_str) 37 | tree_type = ALPHA_BETA; 38 | if ("ALPHA_BETA_WITH_MEMORY" == tree_type_str) 39 | tree_type = ALPHA_BETA_WITH_MEMORY; 40 | if ("MTDF" == tree_type_str) 41 | tree_type = MTDF; 42 | if ("QUIE" == tree_type_str) 43 | tree_type = QUIE; 44 | if ("ITER_DEEP" == tree_type_str) 45 | tree_type = ITER_DEEP; 46 | if ("MTDF_QUIE" == tree_type_str) 47 | tree_type = MTDF_QUIE; 48 | 49 | } 50 | 51 | void parse_depth(const string &depth_str) { 52 | this->depth = std::stoi(depth_str); 53 | } 54 | 55 | void parse_color_sign(const string &color_str) { 56 | if ("MAX_LAYER_SIGN" == color_str) { 57 | this->color_sign = TreeSearchBase::MAX_LAYER_SIGN; 58 | } else { 59 | this->color_sign = TreeSearchBase::MIN_LAYER_SIGN; 60 | } 61 | } 62 | }; 63 | 64 | 65 | void py_parse(const char **argv) { 66 | 67 | if (argv[1] == nullptr || argv[2] == nullptr || argv[3] == nullptr || argv[4] == nullptr || argv[5] == nullptr) { 68 | cerr << "Required parameters:" << endl; 69 | cerr << "argv[0]: the sequence of the chessboard." << endl; 70 | cerr << "argv[1]: the type of the searching tree (or searching algorithm)." << endl; 71 | cerr << "argv[2]: the search depth." << endl; 72 | cerr << "argv[3]: the target chess color." << endl; 73 | cerr << "argv[4]: the path of the file which stores the evaluate results." << endl; 74 | return; 75 | } 76 | 77 | ArgParser parser; 78 | parser.parse_chessboard(argv[1]); 79 | parser.parse_tree_type(argv[2]); 80 | parser.parse_depth(argv[3]); 81 | parser.parse_color_sign(argv[4]); 82 | 83 | MultiThreadEvaluator evaluator(parser.board, parser.depth, parser.tree_type, parser.color_sign); 84 | auto best_path = evaluator.get_best_path(); 85 | evaluator.print_res = false; 86 | 87 | string path = argv[5]; 88 | ofstream out(path, ios::out); 89 | out << best_path.from_x << "," << best_path.from_y << "," << best_path.to_x << "," << best_path.to_y << "," 90 | << best_path.eat; 91 | } 92 | 93 | 94 | int main(int argc, const char **argv) { 95 | py_parse(argv); 96 | return 0; 97 | } 98 | 99 | 100 | #endif -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/Makefile.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # The generator used is: 5 | set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") 6 | 7 | # The top level Makefile was generated from the following files: 8 | set(CMAKE_MAKEFILE_DEPENDS 9 | "CMakeCache.txt" 10 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeCInformation.cmake" 11 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeCXXInformation.cmake" 12 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeCommonLanguageInclude.cmake" 13 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake" 14 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeFindCodeBlocks.cmake" 15 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeGenericSystem.cmake" 16 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeInitializeConfigs.cmake" 17 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeLanguageInformation.cmake" 18 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeSystemSpecificInformation.cmake" 19 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeSystemSpecificInitialize.cmake" 20 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Compiler/AppleClang-C.cmake" 21 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Compiler/AppleClang-CXX.cmake" 22 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Compiler/CMakeCommonCompilerMacros.cmake" 23 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Compiler/Clang.cmake" 24 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Compiler/GNU.cmake" 25 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Apple-AppleClang-C.cmake" 26 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Apple-AppleClang-CXX.cmake" 27 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Apple-Clang-C.cmake" 28 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Apple-Clang-CXX.cmake" 29 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Apple-Clang.cmake" 30 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Darwin-Initialize.cmake" 31 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/Darwin.cmake" 32 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/Platform/UnixPaths.cmake" 33 | "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/ProcessorCount.cmake" 34 | "../CMakeLists.txt" 35 | "CMakeFiles/3.23.2/CMakeCCompiler.cmake" 36 | "CMakeFiles/3.23.2/CMakeCXXCompiler.cmake" 37 | "CMakeFiles/3.23.2/CMakeSystem.cmake" 38 | ) 39 | 40 | # The corresponding makefile is: 41 | set(CMAKE_MAKEFILE_OUTPUTS 42 | "Makefile" 43 | "CMakeFiles/cmake.check_cache" 44 | ) 45 | 46 | # Byproducts of CMake generate step: 47 | set(CMAKE_MAKEFILE_PRODUCTS 48 | "CMakeFiles/CMakeDirectoryInformation.cmake" 49 | ) 50 | 51 | # Dependency information for all targets: 52 | set(CMAKE_DEPEND_INFO_FILES 53 | "CMakeFiles/vliang_chinese_chess.dir/DependInfo.cmake" 54 | ) 55 | -------------------------------------------------------------------------------- /cpp/include/evaluator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/25. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_EVALUATOR_H 6 | #define VLIANG_CHINESE_CHESS_EVALUATOR_H 7 | 8 | #include "tree_search.h" 9 | #include "tree_creator.hpp" 10 | #include 11 | #include 12 | #include 13 | #include "path_filter.h" 14 | 15 | 16 | //class SingleThreadEvaluator { 17 | //public: 18 | // 19 | // TreeType tree_type; 20 | // Chessboard board; 21 | // int depth; 22 | // int color_sign; 23 | // bool print_res = true; 24 | // 25 | // int alpha = TreeSearchBase::ALPHA_INIT_VAL; 26 | // int beta = TreeSearchBase::BETA_INIT_VAL; 27 | // 28 | // SingleThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type) { 29 | // this->board = chessboard; 30 | // this->depth = depth; 31 | // this->tree_type = tree_type; 32 | // this->color_sign = TreeSearchBase::MAX_LAYER_SIGN; 33 | // } 34 | // 35 | // SingleThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type, int color_sign) { 36 | // this->board = chessboard; 37 | // this->depth = depth; 38 | // this->tree_type = tree_type; 39 | // this->color_sign = color_sign; 40 | // } 41 | // 42 | // virtual ChessPath get_best_path() = 0; 43 | //}; 44 | 45 | 46 | class MultiThreadEvaluator { 47 | public: 48 | 49 | /** 50 | * 采用的搜索树的类型 51 | */ 52 | TreeType tree_type; 53 | 54 | /** 55 | * 需要搜索的棋盘 56 | */ 57 | Chessboard board; 58 | 59 | /** 60 | * 搜索深度 61 | */ 62 | int depth; 63 | 64 | /** 65 | * 搜索的棋子颜色 66 | */ 67 | int color_sign; 68 | 69 | /** 70 | * 是否打印结果 71 | */ 72 | bool print_res = true; 73 | 74 | /** 75 | * 在控制台打印的结果数量(最大数量) 76 | * 如果 print_res 为 true,那么这个变量有效 77 | */ 78 | int print_res_num = 14; 79 | 80 | MultiThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type) { 81 | this->board = chessboard; 82 | this->depth = depth; 83 | this->tree_type = tree_type; 84 | this->color_sign = TreeSearchBase::MAX_LAYER_SIGN; 85 | } 86 | 87 | MultiThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type, int color_sign) { 88 | this->board = chessboard; 89 | this->depth = depth; 90 | this->tree_type = tree_type; 91 | this->color_sign = color_sign; 92 | } 93 | 94 | virtual ChessPath get_best_path(); 95 | 96 | virtual paths_t get_all_evaluated_path(); 97 | 98 | protected: 99 | paths_t all_paths; 100 | 101 | virtual void evaluate_all_path(); 102 | }; 103 | 104 | 105 | class DeepeningMultiThreadEvaluator : public MultiThreadEvaluator { 106 | public: 107 | DeepeningMultiThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type) 108 | : MultiThreadEvaluator(chessboard, depth, tree_type) {} 109 | 110 | DeepeningMultiThreadEvaluator(Chessboard chessboard, int depth, TreeType tree_type, int color_sign) 111 | : MultiThreadEvaluator(chessboard, depth, tree_type, color_sign) {} 112 | 113 | /** 114 | * 如果在当前深度下评估时长小于这个值,那么每次深度+2 115 | * 增加深度后会再进行一次评估,直到超过了时间要求 116 | * 117 | * 每个设备都应该调整合适的 time_threshold_in_second 118 | * 这个值太小会导致中后盘评估深度不太够,太大可能会导致每次评估都进行深度增加,导致非常耗时 119 | * 我的CPU型号为:Core i9-9880h @2.3GHz,这个值在0.8左右还不错 120 | */ 121 | float time_threshold_in_second = 0.8f; 122 | 123 | ChessPath get_best_path() override; 124 | 125 | paths_t get_all_evaluated_path() override; 126 | 127 | protected: 128 | void evaluate_all_path() override; 129 | }; 130 | 131 | 132 | #endif //VLIANG_CHINESE_CHESS_EVALUATOR_H 133 | -------------------------------------------------------------------------------- /cpp/source/mtdf.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/7/27. 3 | // 4 | 5 | #include "../include/mtdf.h" 6 | 7 | int MTDF_Searching::mtdf_eval(ChessPath &chess_path, int beta, int depth, int color_sign) { 8 | if (this->estimate_MTDF_init_value) { 9 | estimate_init_value(chess_path, depth, color_sign); 10 | } 11 | 12 | int val = this->mtdf_init_value; 13 | 14 | int upperBound = MAX_EVAL_VAL; 15 | int lowerBound = MIN_EVAL_VAL; 16 | 17 | while (lowerBound < upperBound) { 18 | if (val == lowerBound) { 19 | beta = val + 1; 20 | } else { 21 | beta = val; 22 | } 23 | // 进行一个以 [beta - 1, beta] 为零窗口的记忆化搜索 24 | val = alpha_beta_with_memory_eval(chess_path, beta - 1, beta, depth, color_sign); 25 | if (val < beta) { 26 | upperBound = val; 27 | } else { 28 | lowerBound = val; 29 | } 30 | } 31 | 32 | return val; 33 | } 34 | 35 | int MTDF_Searching::eval_path_val(const ChessPath &path, int depth) { 36 | this->search_depth = depth; 37 | return this->mtdf_eval(const_cast(path), 0, depth, MIN_LAYER_SIGN); 38 | } 39 | 40 | int MTDF_Searching::eval_path_val(const ChessPath &path, int depth, int color_sign) { 41 | this->search_depth = depth; 42 | return this->mtdf_eval(const_cast(path), 0, depth, color_sign); 43 | } 44 | 45 | void MTDF_Searching::estimate_init_value(ChessPath &chess_path, int depth, int color_sign) { 46 | this->mtdf_init_value = alpha_beta_with_memory_eval(chess_path, ALPHA_INIT_VAL, BETA_INIT_VAL, depth - 2, 47 | color_sign); 48 | } 49 | 50 | 51 | // ========================================= MTDF_Quiescence_Searching 实现 ========================================= 52 | 53 | 54 | int MTDF_Quiescence_Searching::mtdf_quiescence_eval(ChessPath &chess_path, int beta, int depth, int color_sign) { 55 | if (this->estimate_MTDF_init_value) { 56 | estimate_init_value(chess_path, depth, color_sign); 57 | } 58 | 59 | // 获取 beta 的初始值 60 | int val = MTDF_Quiescence_Searching::mtdf_init_value; 61 | 62 | int upperBound = MAX_EVAL_VAL; 63 | int lowerBound = MIN_EVAL_VAL; 64 | 65 | while (lowerBound < upperBound) { 66 | if (val == lowerBound) { 67 | beta = val + 1; 68 | } else { 69 | beta = val; 70 | } 71 | // 进行一个以 [beta - 1, beta] 为零窗口的记忆化搜索 72 | val = alpha_beta_quiescence_with_memory_eval(chess_path, beta - 1, beta, depth, color_sign); 73 | if (val < beta) { 74 | upperBound = val; 75 | } else { 76 | lowerBound = val; 77 | } 78 | } 79 | 80 | return val; 81 | } 82 | 83 | int MTDF_Quiescence_Searching::eval_path_val(const ChessPath &path, int depth) { 84 | this->search_depth = depth; 85 | return this->mtdf_quiescence_eval(const_cast(path), 0, depth, MIN_LAYER_SIGN); 86 | } 87 | 88 | int MTDF_Quiescence_Searching::eval_path_val(const ChessPath &path, int depth, int color_sign) { 89 | this->search_depth = depth; 90 | return this->mtdf_quiescence_eval(const_cast(path), 0, depth, color_sign); 91 | } 92 | 93 | void MTDF_Quiescence_Searching::estimate_init_value(ChessPath &chess_path, int depth, int color_sign) { 94 | this->mtdf_init_value = alpha_beta_eval(chess_path, ALPHA_INIT_VAL, BETA_INIT_VAL, 95 | depth - 2, color_sign); 96 | } 97 | 98 | int IterDeepening::iter_deepening_eval(ChessPath &path, int depth, int color_sign) { 99 | int beta_init_val = 0; 100 | this->estimate_MTDF_init_value = false; 101 | for (int i = 2; i < depth; i++) { 102 | beta_init_val = this->mtdf_eval(path, beta_init_val, i, color_sign); 103 | } 104 | return beta_init_val; 105 | } 106 | 107 | int IterDeepening::eval_path_val(const ChessPath &path, int depth) { 108 | return iter_deepening_eval(const_cast(path), depth, MIN_LAYER_SIGN); 109 | } 110 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/Makefile2: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | .PHONY : default_target 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | # Disable VCS-based implicit rules. 15 | % : %,v 16 | 17 | # Disable VCS-based implicit rules. 18 | % : RCS/% 19 | 20 | # Disable VCS-based implicit rules. 21 | % : RCS/%,v 22 | 23 | # Disable VCS-based implicit rules. 24 | % : SCCS/s.% 25 | 26 | # Disable VCS-based implicit rules. 27 | % : s.% 28 | 29 | .SUFFIXES: .hpux_make_needs_suffix_list 30 | 31 | # Command-line flag to silence nested $(MAKE). 32 | $(VERBOSE)MAKESILENT = -s 33 | 34 | #Suppress display of executed commands. 35 | $(VERBOSE).SILENT: 36 | 37 | # A target that is always out of date. 38 | cmake_force: 39 | .PHONY : cmake_force 40 | 41 | #============================================================================= 42 | # Set environment variables for the build. 43 | 44 | # The shell in which to execute make rules. 45 | SHELL = /bin/sh 46 | 47 | # The CMake executable. 48 | CMAKE_COMMAND = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake 49 | 50 | # The command to remove a file. 51 | RM = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E rm -f 52 | 53 | # Escaping for special characters. 54 | EQUALS = = 55 | 56 | # The top-level source directory on which CMake was run. 57 | CMAKE_SOURCE_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp 58 | 59 | # The top-level build directory on which CMake was run. 60 | CMAKE_BINARY_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release 61 | 62 | #============================================================================= 63 | # Directory level rules for the build root directory 64 | 65 | # The main recursive "all" target. 66 | all: CMakeFiles/vliang_chinese_chess.dir/all 67 | .PHONY : all 68 | 69 | # The main recursive "preinstall" target. 70 | preinstall: 71 | .PHONY : preinstall 72 | 73 | # The main recursive "clean" target. 74 | clean: CMakeFiles/vliang_chinese_chess.dir/clean 75 | .PHONY : clean 76 | 77 | #============================================================================= 78 | # Target rules for target CMakeFiles/vliang_chinese_chess.dir 79 | 80 | # All Build rule for target. 81 | CMakeFiles/vliang_chinese_chess.dir/all: 82 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/depend 83 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/build 84 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=1,2,3,4,5,6,7,8,9,10 "Built target vliang_chinese_chess" 85 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/all 86 | 87 | # Build rule for subdir invocation for target. 88 | CMakeFiles/vliang_chinese_chess.dir/rule: cmake_check_build_system 89 | $(CMAKE_COMMAND) -E cmake_progress_start /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles 10 90 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 CMakeFiles/vliang_chinese_chess.dir/all 91 | $(CMAKE_COMMAND) -E cmake_progress_start /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles 0 92 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/rule 93 | 94 | # Convenience name for target. 95 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/rule 96 | .PHONY : vliang_chinese_chess 97 | 98 | # clean rule for target. 99 | CMakeFiles/vliang_chinese_chess.dir/clean: 100 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/clean 101 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/clean 102 | 103 | #============================================================================= 104 | # Special targets to cleanup operation of make. 105 | 106 | # Special rule to run CMake to check the build system integrity. 107 | # No rule that depends on this can have commands that come from listfiles 108 | # because they might be regenerated. 109 | cmake_check_build_system: 110 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 111 | .PHONY : cmake_check_build_system 112 | 113 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //#include "cpp/include/evaluator.h" 2 | // 3 | // 4 | //#include 5 | // 6 | //using namespace std; 7 | // 8 | //class ConsoleGame { 9 | //public: 10 | // 11 | // static ChessPath convertPath(string path) { 12 | // int fx = path[0] - '0'; 13 | // int fy = path[1] - '0'; 14 | // int tx = path[2] - '0'; 15 | // int ty = path[3] - '0'; 16 | // int eat = path[4] - '0'; 17 | // return {fx, fy, tx, ty, eat}; 18 | // } 19 | // 20 | // static void runCChessGame() { 21 | // stack stack; 22 | // 23 | // Chessboard cChessboard; 24 | // cChessboard.print_chessboard(); 25 | // 26 | // while (true) { 27 | // 28 | // cout << "input: 21240 ---- move the chess at <2, 1> to <2, 4> without eating any chess" << endl; 29 | // cout << "input: 21242 ---- move the chess at <2, 1> to <2, 4> and eat the chess labeled 2" << endl; 30 | // cout << "input: regret ---- regret" << endl; 31 | // cout << "input: exit ---- exit console game" << endl; 32 | // 33 | // // player 34 | // string path; 35 | // cin >> path; 36 | // 37 | // if ("exit" == path) { 38 | // break; 39 | // } 40 | // 41 | // if ("regret" == path) { 42 | // if (!stack.empty()) { 43 | // auto p = stack.top(); 44 | // cChessboard.undo_move_chess(p); 45 | // stack.pop(); 46 | // 47 | // p = stack.top(); 48 | // cChessboard.undo_move_chess(p); 49 | // stack.pop(); 50 | // 51 | // cChessboard.print_chessboard(); 52 | // } else { 53 | // cout << "It is the initial state of the chessboard." << endl; 54 | // } 55 | // continue; 56 | // } 57 | // 58 | // if ("print" == path) { 59 | // for (auto &i: cChessboard.board) { 60 | // for (auto &j: i) { 61 | // cout << j; 62 | // } 63 | // } 64 | // cout << endl; 65 | // continue; 66 | // } 67 | // 68 | // auto chess_path = convertPath(path); 69 | // stack.push(chess_path); 70 | // cChessboard.move_chess(chess_path); 71 | // cChessboard.print_chessboard(); 72 | // 73 | // // ai 74 | // MultiThreadEvaluator evaluator(cChessboard, 8, TreeType::MTDF); 75 | // ChessPath best = evaluator.get_best_path(); 76 | // cChessboard.move_chess(best); 77 | // stack.push(best); 78 | // cChessboard.print_chessboard(); 79 | // } 80 | // } 81 | //}; 82 | // 83 | // 84 | //class AISelfMatch { 85 | //public: 86 | // Chessboard cChessboard; 87 | // 88 | // int step = 0; 89 | // 90 | // void startSelfMatch() { 91 | // 92 | // cChessboard.print_chessboard(); 93 | // 94 | //// cChessboard.move_chess(ChessPath(2, 1, 2, 4, 0)); 95 | //// cChessboard.move_chess(ChessPath(3,2,4,2,0)); 96 | // cChessboard.print_chessboard(); 97 | // 98 | // while (true) { 99 | // if (step++ == 60) { 100 | // cout << "和棋" << endl; 101 | // break; 102 | // } 103 | // // 104 | // ChessPath best_1 = MultiThreadEvaluator(cChessboard, 6, TreeType::MTDF_QUIE, 105 | // TreeSearchBase::MAX_LAYER_SIGN).get_best_path(); 106 | // cChessboard.move_chess(best_1); 107 | // cout << "min 落子:" << best_1 << endl; 108 | // 109 | // cChessboard.print_chessboard(); 110 | // if (best_1.eat == -5) { 111 | // cout << "min 赢" << endl; 112 | // break; 113 | // } 114 | // 115 | // // 116 | // ChessPath best_2 = MultiThreadEvaluator(cChessboard, 8, TreeType::MTDF, 117 | // TreeSearchBase::MIN_LAYER_SIGN).get_best_path(); 118 | // cChessboard.move_chess(best_2); 119 | // cout << "max 落子:" << best_2 << endl; 120 | // cChessboard.print_chessboard(); 121 | // if (best_2.eat == 5) { 122 | // cout << "max 赢" << endl; 123 | // break; 124 | // } 125 | // } 126 | // } 127 | //}; 128 | // 129 | // 130 | //int main(int argc, const char **argv) { 131 | //// AISelfMatch().startSelfMatch(); 132 | // ConsoleGame::runCChessGame(); 133 | //} 134 | // 135 | // 136 | -------------------------------------------------------------------------------- /cpp/source/evaluator.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/31. 3 | // 4 | 5 | #include "../include/evaluator.h" 6 | 7 | #define PROCESS_BAR_CHAR '>' 8 | 9 | void 10 | calculate_each_path(Chessboard board, ChessPath &path, int depth, TreeType type, bool print_porcess, int color_sign) { 11 | auto tree = TreeCreator::get_tree(board, type); 12 | path.value = tree->eval_path_val(path, depth, color_sign); 13 | if (print_porcess) { 14 | cout << ">" << flush; 15 | } 16 | cout.flush(); 17 | } 18 | 19 | string tree_to_string(TreeType type) { 20 | switch (type) { 21 | case ALPHA_BETA: 22 | return "ALPHA_BETA"; 23 | 24 | case ALPHA_BETA_WITH_MEMORY: 25 | return "ALPHA_BETA_WITH_MEMORY"; 26 | 27 | case MTDF: 28 | return "MTDF"; 29 | 30 | case QUIE: 31 | return "QUIE"; 32 | 33 | case MTDF_QUIE: 34 | return "MTDF_QUIE"; 35 | 36 | case ITER_DEEP: 37 | return "ITER_DEEP"; 38 | 39 | default: 40 | return ""; 41 | } 42 | } 43 | 44 | ChessPath MultiThreadEvaluator::get_best_path() { 45 | this->evaluate_all_path(); 46 | return this->all_paths[0]; 47 | } 48 | 49 | void MultiThreadEvaluator::evaluate_all_path() { 50 | auto start_time = chrono::steady_clock::now(); 51 | 52 | paths_t &paths = this->all_paths; 53 | this->board.get_all_paths(-this->color_sign, paths); 54 | 55 | if (print_res) { 56 | // print process bar 57 | cout << "evaluating: 0"; 58 | for (auto &i: paths) { 59 | cout << ">"; 60 | } 61 | cout << "100" << endl; 62 | cout << "evaluating: "; 63 | } 64 | 65 | // 创建线程 66 | vector threads; 67 | for (ChessPath &path: paths) { 68 | threads.emplace_back( 69 | thread(calculate_each_path, this->board, std::ref(path), this->depth, this->tree_type, this->print_res, 70 | -this->color_sign)); 71 | } 72 | 73 | // 让线程合并到主线程 74 | for (auto &t: threads) { 75 | t.join(); 76 | } 77 | 78 | // 如果最大层,那么将价值从大到小排序,反之从小到大排序 79 | if (color_sign == TreeSearchBase::MAX_LAYER_SIGN) { 80 | sort(paths.begin(), paths.end(), [](auto l, auto r) { return l.value > r.value; }); 81 | } else { 82 | sort(paths.begin(), paths.end(), [](auto l, auto r) { return l.value < r.value; }); 83 | } 84 | 85 | // 打印评估结果 86 | if (print_res) { 87 | 88 | cout << endl; 89 | 90 | string hline = "====================================================================================="; 91 | string top_line = "===================================Evaluate Result==================================="; 92 | cout << top_line << endl; 93 | 94 | for (int i = 0; i < print_res_num && i < paths.size(); i += 2) { 95 | cout << "| "; 96 | printf("%-39s", paths[i].to_string().c_str()); 97 | cout << " | "; 98 | printf("%-39s", i + 1 < print_res_num && i + 1 < paths.size() ? paths[i + 1].to_string().c_str() : ""); 99 | cout << " |" << endl; 100 | cout << hline << endl; 101 | } 102 | 103 | string best_msg = "Best Path: " + paths[0].to_string(); 104 | printf("| %-82s|\n", best_msg.c_str()); 105 | cout << hline << endl; 106 | string time_msg = "Thread Time=" + std::to_string((float) (chrono::duration_cast( 107 | chrono::steady_clock::now() - start_time).count()) / 1000) + "s"; 108 | string tree_msg = 109 | "Tree Type=" + tree_to_string(tree_type) + " Base Search Depth=" + to_string(depth) + " " + time_msg; 110 | printf("| %-82s|\n", tree_msg.c_str()); 111 | cout << hline << endl << endl; 112 | } 113 | } 114 | 115 | paths_t MultiThreadEvaluator::get_all_evaluated_path() { 116 | this->evaluate_all_path(); 117 | return this->all_paths; 118 | } 119 | 120 | ChessPath DeepeningMultiThreadEvaluator::get_best_path() { 121 | evaluate_all_path(); 122 | return this->all_paths[0]; 123 | } 124 | 125 | paths_t DeepeningMultiThreadEvaluator::get_all_evaluated_path() { 126 | evaluate_all_path(); 127 | return this->all_paths; 128 | } 129 | 130 | void DeepeningMultiThreadEvaluator::evaluate_all_path() { 131 | int real_search_depth = this->depth; 132 | 133 | while (true) { 134 | 135 | auto start_time = chrono::steady_clock::now(); 136 | 137 | // 进行评估 138 | MultiThreadEvaluator::evaluate_all_path(); 139 | 140 | float eval_time = (float) (chrono::duration_cast( 141 | chrono::steady_clock::now() - start_time).count()) / 1000; 142 | 143 | // 如果评估时间大于规定时间那么结束搜索,否则进行更深层的搜索 144 | if (eval_time > this->time_threshold_in_second) { 145 | break; 146 | } else { 147 | this->depth += 2; 148 | } 149 | } 150 | 151 | // 恢复保存的深度 152 | this->depth = real_search_depth; 153 | } 154 | -------------------------------------------------------------------------------- /cpp/include/tree_search.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/24. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_TREE_SEARCH_H 6 | #define VLIANG_CHINESE_CHESS_TREE_SEARCH_H 7 | 8 | #include "chessboard.h" 9 | #include "transition_table.hpp" 10 | 11 | class TableMsg; 12 | 13 | class TreeSearchBase; 14 | 15 | 16 | class TreeSearchBase { 17 | public: 18 | /** 19 | * ALPHA 和 BETA 变量的初始值。 20 | * 21 | * 这两个值仅在常规的alpha-beta搜索中会被使用,使用 mtd(f) 方法进行零窗口搜索时 beta = alpha + 1, 22 | * 且 beta 和 alpha 的初始值可以为任意值。 23 | */ 24 | const static int ALPHA_INIT_VAL = -9999; 25 | const static int BETA_INIT_VAL = 9999; 26 | 27 | /** 28 | * 盘面的最大值和最小值。 29 | * 30 | * 如果正数方将被吃,那么将停止搜索,并返回 MAX_EVAL_VALUE 31 | * 如果负数方将被吃,那么将停止搜索,并返回 MIN_EVAL_VALUE 32 | * 在一次搜索过程中,评估值在区间 [MIN_EVAL_VAL, MAX_EVAL_VALUE] 上 33 | */ 34 | const static int MAX_EVAL_VAL = 8888; 35 | const static int MIN_EVAL_VAL = -8888; 36 | 37 | /** 38 | * 最大层和最小层的标识。用于在进行极大极小搜索时表明当前层的类型。 39 | * 40 | * MIN_LAYER_SIGN: 极小层,如果当前搜索到极小层,那么返回所有搜索结果中评估值最小的那个。 41 | * MAX_LAYER_SIGN: 极大层,如果当前搜索到极大层,那么返回所有搜索结果中评估值最大的那个。 42 | */ 43 | const static int MIN_LAYER_SIGN = 1; 44 | const static int MAX_LAYER_SIGN = -1; 45 | 46 | /** 47 | * 搜索深度。 48 | * 49 | * 搜索在到达这个深度时将会进行棋盘价值评估并返回评估值。 50 | */ 51 | int search_depth{}; 52 | 53 | /** 54 | * 静态搜索中限制的最大深度。 55 | * 56 | * 当达到 search_depth 的常规搜索深度时,如果需要静态搜索且达到静态搜索条件(正在发生吃子),那么将出发静态搜索, 57 | * 这个变量表示静态搜索附加的额外搜索深度。即实际最大搜索深度为:search_depth + QUIESCENCE_MAX_DEPTH。 58 | */ 59 | const static int QUIESCENCE_MAX_DEPTH = 9; 60 | 61 | /** 62 | * 棋盘。 63 | * 64 | * 为了方便多线程的进行,每个 TreeSearchBase 对象中含有一个内置棋盘, 65 | * 对于不同线程负责的搜索不同路径的任务,在进行模拟落子时互相不会干扰。 66 | */ 67 | Chessboard chessboard; 68 | 69 | explicit TreeSearchBase(Chessboard &chessboard) { 70 | for (int i = 0; i < CHESSBOARD_ROWS; i++) { 71 | for (int j = 0; j < CHESSBOARD_COLS; ++j) { 72 | this->chessboard.board[i][j] = chessboard.board[i][j]; 73 | } 74 | } 75 | } 76 | 77 | /** 78 | * 评估某个路径的价值。棋子颜色默认为 TreeSearchBase.MAX_LAYER_SIGN。在搜索时会为棋盘是正数的一方搜索价值。 79 | * @param path 路径 80 | * @param depth 搜索深度 81 | * @return 这个路径 path 的价值 82 | */ 83 | virtual int eval_path_val(const ChessPath &path, int depth) { return 0; } 84 | 85 | /** 86 | * 评估某个路径的价值。可以指定棋子颜色。 87 | * @param path 路径 88 | * @param depth 搜索深度 89 | * @param color_sign 棋子颜色,一般传入 TreeSearchBase.MAX_LAYER_SIGN 或 TreeSearchBase.MIN_LAYER_SIGN 90 | * @return 这个路径 path 的价值 91 | */ 92 | virtual int eval_path_val(const ChessPath &path, int depth, int color_sign) { return 0; } 93 | 94 | /** 95 | * 为不同层准备的置换表。 96 | * 97 | * tran_table_max: MAX_LAYER 进行搜索时会查询。 98 | * tran_table_min: MIN_LAYER 进行搜索时会查询。 99 | */ 100 | TranTable tran_table_max; 101 | TranTable tran_table_min; 102 | 103 | /** 104 | * 更新当前置换表的下界。 105 | * 在触发了某些剪枝条件时会更新当前盘面评估值的下界。缩短下界值和上界值会加快搜索到真实值的速度。 106 | * 107 | * @param msg 置换表的指针 108 | * @param lo_bound 下界值 109 | * @param color_sign 颜色,TreeSearchBase.MAX_LAYER_SIGN 或 TreeSearchBase.MIN_LAYER_SIGN 110 | * @param depth 当前搜索深度 111 | * @param hash 哈希值 112 | * @param ver 校验值 113 | * @param path 导致下界变换的路径,下次找到这个置换表后优先搜索这个路径。 114 | */ 115 | void update_lo_bound(TableMsg *msg, int lo_bound, int color_sign, int depth, int hash, int ver, ChessPath &path); 116 | 117 | /** 118 | * 更新当前置换表的上界。 119 | * 在触发了某些剪枝条件时会更新当前盘面评估值的上界。缩短下界值和上界值会加快搜索到真实值的速度。 120 | * 121 | * @param msg 置换表的指针 122 | * @param up_bound 上界值 123 | * @param color_sign 颜色,TreeSearchBase.MAX_LAYER_SIGN 或 TreeSearchBase.MIN_LAYER_SIGN 124 | * @param depth 当前搜索深度 125 | * @param hash 哈希值 126 | * @param ver 校验值 127 | * @param path 导致下界变换的路径,下次找到这个置换表后优先搜索这个路径。 128 | */ 129 | void update_up_bound(TableMsg *msg, int up_bound, int color_sign, int depth, int hash, int ver, ChessPath &path); 130 | }; 131 | 132 | 133 | class TableMsg { 134 | public: 135 | TableMsg() : up_bound(TreeSearchBase::BETA_INIT_VAL), lo_bound(TreeSearchBase::ALPHA_INIT_VAL), up_depth(0), 136 | lo_depth(0) { 137 | } 138 | 139 | /** 140 | * 当前局面的上界值和下界值。 141 | * 142 | * 如果在进行 alpha-beta 搜索时发生 alpha-beta 剪枝,那么将更新这两个值。 143 | * 在进行每一步的搜索时先查询置换表,如果查询到表项,那么更新 alpha 和 beta 的值。 144 | * 145 | * 由于在进行零窗口搜索时,beta = alpha + 1,因此需要保存棋盘的上下界,而不是保存当前深度下决策的最好值。 146 | */ 147 | int up_bound; 148 | int lo_bound; 149 | 150 | /** 151 | * up_depth: 最后一次更新当前局面上界值时的搜索深度。 152 | * lo_depth: 最后一次更新当前局面下界值时的搜索深度。 153 | * 154 | * 查询到表项,更新 alpha 和 beta 的值的时候,如果置换表中的上界值和下界值的深度 >= 当前搜索深度, 155 | * 那么进行更新,否则不进行更新。 156 | */ 157 | int up_depth; 158 | int lo_depth; 159 | 160 | /** 161 | * 引发更新的路径。 162 | * 163 | * 如果在搜索中查询到 164 | */ 165 | ChessPath best_path; 166 | }; 167 | 168 | 169 | #endif //VLIANG_CHINESE_CHESS_TREE_SEARCH_H 170 | -------------------------------------------------------------------------------- /cpp/include/chessboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/17. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_CHESSBOARD_H 6 | #define VLIANG_CHINESE_CHESS_CHESSBOARD_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "weights.h" 13 | #include "zobrist_code.h" 14 | 15 | using namespace std; 16 | 17 | 18 | #define CHESSBOARD_ROWS 10 19 | #define CHESSBOARD_COLS 9 20 | 21 | 22 | class Chess; 23 | 24 | class ChessPath; 25 | 26 | class Chessboard; 27 | 28 | 29 | typedef int chessboard_t[CHESSBOARD_ROWS][CHESSBOARD_COLS]; 30 | typedef vector paths_t; 31 | 32 | 33 | class Chess { 34 | public: 35 | const static int JU = 1; 36 | const static int MA = 2; 37 | const static int XIANG = 3; 38 | const static int SHI = 4; 39 | const static int JIANG = 5; 40 | const static int PAO = 6; 41 | const static int ZU = 7; 42 | }; 43 | 44 | 45 | class ChessPath { 46 | friend ostream &operator<<(ostream &out, const ChessPath &a); 47 | 48 | public: 49 | /** 50 | * 初始点:(from_x, from_y) 51 | */ 52 | int from_x; 53 | int from_y; 54 | 55 | /** 56 | * 落子点:(to_x, to_y) 57 | */ 58 | int to_x; 59 | int to_y; 60 | 61 | /** 62 | * 吃的子 63 | */ 64 | int eat; 65 | 66 | /** 67 | * 当前走法的价值 68 | */ 69 | int value; 70 | 71 | /** 72 | * 用于打印当前路径的信息 73 | * @return 路径信息 74 | * 75 | * 用法: 76 | * ChessPath path; std::cout << path.to_string() << std::endl; 77 | */ 78 | string to_string(); 79 | 80 | ChessPath() {} 81 | 82 | ChessPath(int from_x, int from_y, int to_x, int to_y, int eat) : 83 | from_x(from_x), from_y(from_y), to_x(to_x), to_y(to_y), eat(eat) { 84 | } 85 | 86 | ChessPath(int from_x, int from_y, int to_x, int to_y) : 87 | from_x(from_x), from_y(from_y), to_x(to_x), to_y(to_y), eat(0) { 88 | } 89 | }; 90 | 91 | 92 | class Chessboard { 93 | public: 94 | /** 95 | * 内置的棋盘对象。 96 | * typedef int chessboard_t[10][9] 97 | */ 98 | chessboard_t board; 99 | 100 | private: 101 | /** 102 | * 获得车的所有走法。 103 | * @param x 车的坐标x 104 | * @param y 车的坐标y 105 | * @param ret 路径将存储到这个数组中 106 | */ 107 | void get_path_of_1(int x, int y, paths_t &ret); 108 | 109 | /** 110 | * 获得马的所有走法。 111 | * @param x 马的坐标x 112 | * @param y 马的坐标y 113 | * @param ret 路径将存储到这个数组中 114 | */ 115 | void get_path_of_2(int x, int y, paths_t &ret); 116 | 117 | /** 118 | * 获得象的所有走法。 119 | * @param x 象的坐标x 120 | * @param y 象的坐标y 121 | * @param ret 路径将存储到这个数组中 122 | */ 123 | void get_path_of_3(int x, int y, paths_t &ret); 124 | 125 | /** 126 | * 获得士的所有走法。 127 | * @param x 士的坐标x 128 | * @param y 士的坐标y 129 | * @param ret 路径将存储到这个数组中 130 | */ 131 | void get_path_of_4(int x, int y, paths_t &ret); 132 | 133 | /** 134 | * 获得将的所有走法。 135 | * @param x 将的坐标x 136 | * @param y 将的坐标y 137 | * @param ret 路径将存储到这个数组中 138 | */ 139 | void get_path_of_5(int x, int y, paths_t &ret); 140 | 141 | /** 142 | * 获得炮的所有走法。 143 | * @param x 炮的坐标x 144 | * @param y 炮的坐标y 145 | * @param ret 路径将存储到这个数组中 146 | */ 147 | void get_path_of_6(int x, int y, paths_t &ret); 148 | 149 | /** 150 | * 获得兵的所有走法。 151 | * @param x 兵的坐标x 152 | * @param y 兵的坐标y 153 | * @param ret 路径将存储到这个数组中 154 | */ 155 | void get_path_of_7(int x, int y, paths_t &ret); 156 | 157 | public: 158 | Chessboard() { 159 | this->init_chessboard(); 160 | } 161 | 162 | /** 163 | * 复制棋盘 164 | * @param chessboard 165 | */ 166 | void copy(Chessboard &chessboard); 167 | 168 | /** 169 | * 复制棋盘 170 | * @param board 171 | */ 172 | void copy(chessboard_t board); 173 | 174 | /** 175 | * 获得当前棋子的所有路径。 176 | * @param x 当前棋子的坐标x 177 | * @param y 当前棋子的坐标y 178 | * @param ret 路径将保存到这个数组中 179 | */ 180 | void get_chess_path_of_id(int x, int y, paths_t &ret); 181 | 182 | /** 183 | * 获得某一方的棋子的所有可能路径。 184 | * @param color_sign 棋子颜色 1:正数方 2:负数方 185 | * @param ret 路径将保存到这个数组中 186 | */ 187 | void get_all_paths(int color_sign, paths_t &ret); 188 | 189 | /** 190 | * 判断是否发生对将。 191 | * @return true:发生对将 false:没有发生对将 192 | */ 193 | bool is_general_face2face(); 194 | 195 | /** 196 | * 某一方是否正在被将军。 197 | * @param color_sign 棋子颜色 1:正数方 2:负数方 198 | * @return true:某一方正在被将军 false:当前没有被将军 199 | */ 200 | bool is_checked(int color_sign); 201 | 202 | /** 203 | * 初始化棋盘,恢复成初始棋盘。 204 | */ 205 | void init_chessboard(); 206 | 207 | /** 208 | * 落子。 209 | * @param path 棋子的路径 210 | */ 211 | void move_chess(const ChessPath &path); 212 | 213 | /** 214 | * 恢复走棋。 215 | * 主要用于在进行搜索时需要恢复棋盘。 216 | * @param path 要恢复的路径 217 | */ 218 | void undo_move_chess(const ChessPath &path); 219 | 220 | /** 221 | * 获得当前盘面的打分。 222 | * @return 当前盘面的得分值 223 | */ 224 | int get_on_board_val(); 225 | 226 | /** 227 | * 打印棋盘 228 | */ 229 | void print_chessboard(); 230 | 231 | /** 232 | * 获得棋盘的哈希值。 233 | * 使用 zobrist 哈希码作为哈希方法。 234 | * @return 棋盘的哈希值 235 | */ 236 | int get_hash(); 237 | 238 | /** 239 | * 获得棋盘的校验哈希值。 240 | * 由于单哈希会导致冲突,因此需要补充校验码。校验码同样通过 zobrist 方法获得。 241 | * @return 242 | */ 243 | int get_verify(); 244 | 245 | /** 246 | * 判断棋盘是否相等。 247 | * @param chessboard 另一个棋盘 248 | * @return 是否是相同的棋盘 249 | */ 250 | bool operator==(const Chessboard &chessboard) const; 251 | }; 252 | 253 | 254 | #endif //VLIANG_CHINESE_CHESS_CHESSBOARD_H 255 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/3.20.2/CMakeCXXCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++") 2 | set(CMAKE_CXX_COMPILER_ARG1 "") 3 | set(CMAKE_CXX_COMPILER_ID "AppleClang") 4 | set(CMAKE_CXX_COMPILER_VERSION "13.0.0.13000029") 5 | set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_CXX_COMPILER_WRAPPER "") 7 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "98") 8 | set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") 9 | set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") 10 | set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") 11 | set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") 12 | set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") 13 | set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") 14 | set(CMAKE_CXX23_COMPILE_FEATURES "") 15 | 16 | set(CMAKE_CXX_PLATFORM_ID "Darwin") 17 | set(CMAKE_CXX_SIMULATE_ID "") 18 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") 19 | set(CMAKE_CXX_SIMULATE_VERSION "") 20 | 21 | 22 | 23 | 24 | set(CMAKE_AR "/Library/Developer/CommandLineTools/usr/bin/ar") 25 | set(CMAKE_CXX_COMPILER_AR "") 26 | set(CMAKE_RANLIB "/Library/Developer/CommandLineTools/usr/bin/ranlib") 27 | set(CMAKE_CXX_COMPILER_RANLIB "") 28 | set(CMAKE_LINKER "/Library/Developer/CommandLineTools/usr/bin/ld") 29 | set(CMAKE_MT "") 30 | set(CMAKE_COMPILER_IS_GNUCXX ) 31 | set(CMAKE_CXX_COMPILER_LOADED 1) 32 | set(CMAKE_CXX_COMPILER_WORKS TRUE) 33 | set(CMAKE_CXX_ABI_COMPILED TRUE) 34 | set(CMAKE_COMPILER_IS_MINGW ) 35 | set(CMAKE_COMPILER_IS_CYGWIN ) 36 | if(CMAKE_COMPILER_IS_CYGWIN) 37 | set(CYGWIN 1) 38 | set(UNIX 1) 39 | endif() 40 | 41 | set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") 42 | 43 | if(CMAKE_COMPILER_IS_MINGW) 44 | set(MINGW 1) 45 | endif() 46 | set(CMAKE_CXX_COMPILER_ID_RUN 1) 47 | set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;mpp;CPP) 48 | set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) 49 | 50 | foreach (lang C OBJC OBJCXX) 51 | if (CMAKE_${lang}_COMPILER_ID_RUN) 52 | foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) 53 | list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) 54 | endforeach() 55 | endif() 56 | endforeach() 57 | 58 | set(CMAKE_CXX_LINKER_PREFERENCE 30) 59 | set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) 60 | 61 | # Save compiler ABI information. 62 | set(CMAKE_CXX_SIZEOF_DATA_PTR "8") 63 | set(CMAKE_CXX_COMPILER_ABI "") 64 | set(CMAKE_CXX_BYTE_ORDER "LITTLE_ENDIAN") 65 | set(CMAKE_CXX_LIBRARY_ARCHITECTURE "") 66 | 67 | if(CMAKE_CXX_SIZEOF_DATA_PTR) 68 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") 69 | endif() 70 | 71 | if(CMAKE_CXX_COMPILER_ABI) 72 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") 73 | endif() 74 | 75 | if(CMAKE_CXX_LIBRARY_ARCHITECTURE) 76 | set(CMAKE_LIBRARY_ARCHITECTURE "") 77 | endif() 78 | 79 | set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "") 80 | if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) 81 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") 82 | endif() 83 | 84 | 85 | 86 | 87 | 88 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1;/Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include;/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include;/Library/Developer/CommandLineTools/usr/include") 89 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "c++") 90 | set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib") 91 | set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks") 92 | -------------------------------------------------------------------------------- /cpp/include/weights.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/20. 3 | // 4 | 5 | #ifndef VLIANG_CHINESE_CHESS_WEIGHTS_H 6 | #define VLIANG_CHINESE_CHESS_WEIGHTS_H 7 | 8 | const static int weights[8][10][9] = { 9 | // 0 10 | { 11 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 12 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 13 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 14 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 15 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 16 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 17 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 18 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 19 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 20 | {0, 0, 0, 0, 0, 0, 0, 0, 0} 21 | }, 22 | 23 | // 1 24 | { 25 | {206, 208, 207, 213, 214, 213, 207, 208, 206}, 26 | {206, 212, 209, 216, 233, 216, 209, 212, 206}, 27 | {206, 208, 207, 214, 216, 214, 207, 208, 206}, 28 | {206, 213, 213, 216, 216, 216, 213, 213, 206}, 29 | {208, 211, 211, 214, 215, 214, 211, 211, 208}, 30 | {208, 212, 212, 214, 215, 214, 212, 212, 208}, 31 | {204, 209, 204, 212, 214, 212, 204, 209, 204}, 32 | {198, 208, 204, 212, 212, 212, 204, 208, 198}, 33 | {200, 208, 206, 212, 200, 212, 206, 208, 200}, 34 | {194, 206, 204, 212, 200, 212, 204, 206, 194} 35 | }, 36 | 37 | // 2 38 | { 39 | {90, 90, 90, 96, 90, 96, 90, 90, 90}, 40 | {90, 96, 103, 97, 94, 97, 103, 96, 90}, 41 | {92, 98, 99, 103, 99, 103, 99, 98, 92}, 42 | {93, 108, 100, 107, 100, 107, 100, 108, 93}, 43 | {90, 100, 99, 103, 104, 103, 99, 100, 90}, 44 | {90, 98, 101, 102, 103, 102, 101, 98, 90}, 45 | {92, 94, 98, 95, 98, 95, 98, 94, 92}, 46 | {93, 92, 94, 95, 92, 95, 94, 92, 93}, 47 | {85, 90, 92, 93, 78, 93, 92, 90, 85}, 48 | {88, 85, 90, 88, 90, 88, 90, 85, 88} 49 | }, 50 | 51 | // 3 52 | { 53 | {0, 0, 20, 0, 0, 0, 20, 0, 0}, 54 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 55 | {0, 0, 0, 0, 23, 0, 0, 0, 0}, 56 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 57 | {0, 0, 20, 0, 0, 0, 20, 0, 0}, 58 | {0, 0, 20, 0, 0, 0, 20, 0, 0}, 59 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 60 | {18, 0, 0, 0, 23, 0, 0, 0, 18}, 61 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 62 | {0, 0, 20, 0, 0, 0, 20, 0, 0} 63 | }, 64 | 65 | // 4 66 | { 67 | {0, 0, 0, 20, 0, 20, 0, 0, 0}, 68 | {0, 0, 0, 0, 23, 0, 0, 0, 0}, 69 | {0, 0, 0, 20, 0, 20, 0, 0, 0}, 70 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 71 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 72 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 73 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 74 | {0, 0, 0, 20, 0, 20, 0, 0, 0}, 75 | {0, 0, 0, 0, 23, 0, 0, 0, 0}, 76 | {0, 0, 0, 20, 0, 20, 0, 0, 0} 77 | }, 78 | 79 | // 5 80 | { 81 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}, 82 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}, 83 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}, 84 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 85 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 86 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 87 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 88 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}, 89 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}, 90 | {0, 0, 0, 8888, 8888, 8888, 0, 0, 0} 91 | }, 92 | 93 | // 6 94 | { 95 | {100, 100, 96, 91, 90, 91, 96, 100, 100}, 96 | {98, 98, 96, 92, 89, 92, 96, 98, 98}, 97 | {97, 97, 96, 91, 92, 91, 96, 97, 97}, 98 | {96, 99, 99, 98, 100, 98, 99, 99, 96}, 99 | {96, 96, 96, 96, 100, 96, 96, 96, 96}, 100 | {95, 96, 99, 96, 100, 96, 99, 96, 95}, 101 | {96, 96, 96, 96, 96, 96, 96, 96, 96}, 102 | {97, 96, 100, 99, 101, 99, 100, 96, 97}, 103 | {96, 97, 98, 98, 98, 98, 98, 97, 96}, 104 | {96, 96, 97, 99, 99, 99, 97, 96, 96} 105 | }, 106 | 107 | // 7 108 | { 109 | {9, 9, 9, 11, 13, 11, 9, 9, 9}, 110 | {19, 24, 34, 42, 44, 42, 34, 24, 19}, 111 | {19, 24, 32, 37, 37, 37, 32, 24, 19}, 112 | {19, 23, 27, 29, 30, 29, 27, 23, 19}, 113 | {14, 18, 20, 27, 29, 27, 20, 18, 14}, 114 | {7, 0, 13, 0, 16, 0, 13, 0, 7}, 115 | {7, 0, 7, 0, 15, 0, 7, 0, 7}, 116 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 117 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 118 | {0, 0, 0, 0, 0, 0, 0, 0, 0} 119 | } 120 | }; 121 | 122 | 123 | inline int get_pos_val(int id, int x, int y) { 124 | if (id == 0) { 125 | return 0; 126 | } 127 | return (id > 0) ? weights[id][x][y] : -weights[-id][9 - x][8 - y]; 128 | } 129 | 130 | 131 | #endif //VLIANG_CHINESE_CHESS_WEIGHTS_H 132 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/depend.internal: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o 5 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 6 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 7 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 8 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 9 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 10 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 11 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/alpha_beta.cpp 12 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o 13 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 14 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 15 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 16 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/chessboard.cpp 17 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o 18 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 19 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 20 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/evaluator.h 21 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 22 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/path_filter.h 23 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 24 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 25 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_creator.hpp 26 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 27 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 28 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 29 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/evaluator.cpp 30 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o 31 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 32 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 33 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 34 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 35 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 36 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 37 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 38 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 39 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/mtdf.cpp 40 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o 41 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 42 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 43 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 44 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 45 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 46 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 47 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 48 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/quiescence.cpp 49 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o 50 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 51 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 52 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 53 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 54 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 55 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/tree_search.cpp 56 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o 57 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 58 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 59 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/evaluator.h 60 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 61 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/path_filter.h 62 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 63 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 64 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_creator.hpp 65 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 66 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 67 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 68 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/evaluator_so.cpp 69 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.o 70 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/main.cpp 71 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o 72 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/alpha_beta.h 73 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/chessboard.h 74 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/evaluator.h 75 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/mtdf.h 76 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/path_filter.h 77 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/quiescence.h 78 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/transition_table.hpp 79 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_creator.hpp 80 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/tree_search.h 81 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/weights.h 82 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/include/zobrist_code.h 83 | /Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp 84 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/CMakeError.log: -------------------------------------------------------------------------------- 1 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 2 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 3 | Build flags: 4 | Id flags: 5 | 6 | The output was: 7 | 1 8 | ld: library not found for -lSystem 9 | clang: error: linker command failed with exit code 1 (use -v to see invocation) 10 | 11 | 12 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 13 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 14 | Build flags: 15 | Id flags: 16 | 17 | The output was: 18 | 1 19 | ld: library not found for -lc++ 20 | clang: error: linker command failed with exit code 1 (use -v to see invocation) 21 | 22 | 23 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 24 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 25 | Build flags: 26 | Id flags: 27 | 28 | The output was: 29 | No such file or directory 30 | 31 | 32 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 33 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 34 | Build flags: 35 | Id flags: -c 36 | 37 | The output was: 38 | No such file or directory 39 | 40 | 41 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 42 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 43 | Build flags: 44 | Id flags: -Aa 45 | 46 | The output was: 47 | No such file or directory 48 | 49 | 50 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 51 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 52 | Build flags: 53 | Id flags: -D__CLASSIC_C__ 54 | 55 | The output was: 56 | No such file or directory 57 | 58 | 59 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 60 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 61 | Build flags: 62 | Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3 63 | 64 | The output was: 65 | No such file or directory 66 | 67 | 68 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 69 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 70 | Build flags: 71 | Id flags: -c;-I__does_not_exist__ 72 | 73 | The output was: 74 | No such file or directory 75 | 76 | 77 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 78 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 79 | Build flags: 80 | Id flags: 81 | 82 | The output was: 83 | No such file or directory 84 | 85 | 86 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 87 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 88 | Build flags: 89 | Id flags: -c 90 | 91 | The output was: 92 | No such file or directory 93 | 94 | 95 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 96 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 97 | Build flags: 98 | Id flags: -Aa 99 | 100 | The output was: 101 | No such file or directory 102 | 103 | 104 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 105 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 106 | Build flags: 107 | Id flags: -D__CLASSIC_C__ 108 | 109 | The output was: 110 | No such file or directory 111 | 112 | 113 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 114 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 115 | Build flags: 116 | Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3 117 | 118 | The output was: 119 | No such file or directory 120 | 121 | 122 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 123 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 124 | Build flags: 125 | Id flags: -c;-I__does_not_exist__ 126 | 127 | The output was: 128 | No such file or directory 129 | 130 | 131 | Checking whether the C compiler is IAR using "" did not match "IAR .+ Compiler": 132 | Checking whether the C compiler is IAR using "" did not match "IAR .+ Compiler": 133 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 134 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 135 | Build flags: 136 | Id flags: 137 | 138 | The output was: 139 | No such file or directory 140 | 141 | 142 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 143 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 144 | Build flags: 145 | Id flags: -c 146 | 147 | The output was: 148 | No such file or directory 149 | 150 | 151 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 152 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 153 | Build flags: 154 | Id flags: --c++ 155 | 156 | The output was: 157 | No such file or directory 158 | 159 | 160 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 161 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 162 | Build flags: 163 | Id flags: --ec++ 164 | 165 | The output was: 166 | No such file or directory 167 | 168 | 169 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 170 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 171 | Build flags: 172 | Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3 173 | 174 | The output was: 175 | No such file or directory 176 | 177 | 178 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 179 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 180 | Build flags: 181 | Id flags: -c;-I__does_not_exist__ 182 | 183 | The output was: 184 | No such file or directory 185 | 186 | 187 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 188 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 189 | Build flags: 190 | Id flags: 191 | 192 | The output was: 193 | No such file or directory 194 | 195 | 196 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 197 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 198 | Build flags: 199 | Id flags: -c 200 | 201 | The output was: 202 | No such file or directory 203 | 204 | 205 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 206 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 207 | Build flags: 208 | Id flags: --c++ 209 | 210 | The output was: 211 | No such file or directory 212 | 213 | 214 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 215 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 216 | Build flags: 217 | Id flags: --ec++ 218 | 219 | The output was: 220 | No such file or directory 221 | 222 | 223 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 224 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 225 | Build flags: 226 | Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3 227 | 228 | The output was: 229 | No such file or directory 230 | 231 | 232 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 233 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 234 | Build flags: 235 | Id flags: -c;-I__does_not_exist__ 236 | 237 | The output was: 238 | No such file or directory 239 | 240 | 241 | Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler": 242 | Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler": 243 | Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. 244 | Compiler: /Library/Developer/CommandLineTools/usr/bin/cc 245 | Build flags: 246 | Id flags: 247 | 248 | The output was: 249 | 1 250 | ld: library not found for -lSystem 251 | clang: error: linker command failed with exit code 1 (use -v to see invocation) 252 | 253 | 254 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 255 | Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 256 | Build flags: 257 | Id flags: 258 | 259 | The output was: 260 | 1 261 | ld: library not found for -lc++ 262 | clang: error: linker command failed with exit code 1 (use -v to see invocation) 263 | 264 | 265 | -------------------------------------------------------------------------------- /cmake-build-release/vliang_chinese_chess.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 147 | 148 | -------------------------------------------------------------------------------- /cpp/source/alpha_beta.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/25. 3 | // 4 | 5 | #include "../include/alpha_beta.h" 6 | 7 | 8 | int AlphaBeta::alpha_beta_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign) { 9 | // 判断生死 10 | if (path.eat == -5) { 11 | return MAX_EVAL_VAL; 12 | } else if (path.eat == 5) { 13 | return MIN_EVAL_VAL; 14 | } 15 | 16 | // 到达深度 17 | if (depth == 1) { 18 | chessboard.move_chess(path); 19 | int val = chessboard.get_on_board_val(); 20 | chessboard.undo_move_chess(path); 21 | return val; 22 | } 23 | 24 | // 落子 25 | chessboard.move_chess(path); 26 | // 落子后先判断是否有对将情况 27 | if (chessboard.is_general_face2face()) { 28 | if (colorSign == MAX_LAYER_SIGN) { 29 | chessboard.undo_move_chess(path); 30 | return MAX_EVAL_VAL + depth; 31 | } else { 32 | chessboard.undo_move_chess(path); 33 | return MIN_EVAL_VAL - depth; 34 | } 35 | } 36 | 37 | // max层 38 | if (colorSign == MAX_LAYER_SIGN) { 39 | int maxEval = MIN_EVAL_VAL; 40 | 41 | // 对手搜索我方可能的路径 42 | paths_t possible_paths; 43 | chessboard.get_all_paths(MIN_LAYER_SIGN, possible_paths); 44 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 45 | return p2.value < p1.value; 46 | }); 47 | 48 | for (ChessPath &chess_path: possible_paths) { 49 | int eval = alpha_beta_eval(chess_path, alpha, beta, depth - 1, MIN_LAYER_SIGN); 50 | maxEval = maxEval > eval ? maxEval : eval; 51 | alpha = alpha > eval ? alpha : eval; 52 | if (beta <= alpha) { 53 | break; 54 | } 55 | } 56 | 57 | // 恢复棋盘 58 | chessboard.undo_move_chess(path); 59 | return maxEval; 60 | 61 | } else { // min层 62 | int minEval = MAX_EVAL_VAL; 63 | 64 | // 搜索对手的可能路径 65 | paths_t possible_paths; 66 | chessboard.get_all_paths(MAX_LAYER_SIGN, possible_paths); 67 | 68 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 69 | return p2.value > p1.value; 70 | }); 71 | 72 | for (ChessPath &chessPath: possible_paths) { 73 | int eval = alpha_beta_eval(chessPath, alpha, beta, depth - 1, MAX_LAYER_SIGN); 74 | minEval = minEval < eval ? minEval : eval; 75 | beta = beta < eval ? beta : eval; 76 | if (beta <= alpha) { 77 | break; 78 | } 79 | } 80 | 81 | // 恢复棋盘 82 | chessboard.undo_move_chess(path); 83 | return minEval; 84 | } 85 | } 86 | 87 | int AlphaBeta::eval_path_val(const ChessPath &path, int depth) { 88 | this->search_depth = depth; 89 | return this->alpha_beta_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, this->search_depth, 90 | MIN_LAYER_SIGN); 91 | } 92 | 93 | int AlphaBeta::eval_path_val(const ChessPath &path, int depth, int color_sign) { 94 | this->search_depth = depth; 95 | return this->alpha_beta_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, this->search_depth, 96 | color_sign); 97 | } 98 | 99 | int AlphaBetaWithMemory::alpha_beta_with_memory_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign) { 100 | 101 | // 判断生死 102 | if (path.eat == -5) { 103 | return MAX_EVAL_VAL; 104 | } else if (path.eat == 5) { 105 | return MIN_EVAL_VAL; 106 | } 107 | 108 | // 到达深度 109 | if (depth == 1) { 110 | chessboard.move_chess(path); 111 | int val = chessboard.get_on_board_val(); 112 | chessboard.undo_move_chess(path); 113 | return val; 114 | } 115 | 116 | // 落子 117 | chessboard.move_chess(path); 118 | 119 | // 落子后先判断是否有对将情况 120 | if (chessboard.is_general_face2face()) { 121 | if (colorSign == MAX_LAYER_SIGN) { 122 | chessboard.undo_move_chess(path); 123 | return MAX_EVAL_VAL + depth; 124 | } else { 125 | chessboard.undo_move_chess(path); 126 | return MIN_EVAL_VAL - depth; 127 | } 128 | } 129 | 130 | // -------------------- 查询置换表 --------------------------------------------------- 131 | int ch_hash = chessboard.get_hash(); 132 | int ch_ver = chessboard.get_verify(); 133 | TableMsg *tableMsg; 134 | 135 | if (colorSign == MAX_LAYER_SIGN) { 136 | tableMsg = tran_table_max.get_table(ch_hash, ch_ver); 137 | } else { 138 | tableMsg = tran_table_min.get_table(ch_hash, ch_ver); 139 | } 140 | 141 | // 要求能查询到当前局面,且置换表中的深度要大于当前深度时才使用置换表 142 | if (tableMsg != nullptr) { 143 | if (tableMsg->lo_depth >= depth) { 144 | if (tableMsg->lo_bound >= beta) { 145 | chessboard.undo_move_chess(path); 146 | return tableMsg->lo_bound; 147 | } 148 | alpha = alpha > tableMsg->lo_bound ? alpha : tableMsg->lo_bound; 149 | } 150 | if (tableMsg->up_depth >= depth) { 151 | if (tableMsg->up_bound <= alpha) { 152 | chessboard.undo_move_chess(path); 153 | return tableMsg->up_bound; 154 | } 155 | beta = beta < tableMsg->up_bound ? beta : tableMsg->up_bound; 156 | } 157 | } 158 | // -------------------- 查询置换表 --------------------------------------------------- 159 | 160 | // max层 161 | if (colorSign == MAX_LAYER_SIGN) { 162 | 163 | // 对手搜索我方可能的路径 164 | paths_t possible_paths; 165 | if (tableMsg != nullptr) { 166 | possible_paths.push_back(tableMsg->best_path); 167 | chessboard.get_all_paths(MIN_LAYER_SIGN, possible_paths); 168 | std::sort(possible_paths.begin() + 1, possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 169 | return p2.value < p1.value; 170 | }); 171 | } else { 172 | chessboard.get_all_paths(MIN_LAYER_SIGN, possible_paths); 173 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 174 | return p2.value < p1.value; 175 | }); 176 | } 177 | 178 | int al = alpha; 179 | int maxEval = MIN_EVAL_VAL; 180 | ChessPath cur_best = possible_paths[0]; 181 | 182 | for (ChessPath &chess_path: possible_paths) { 183 | int eval = alpha_beta_with_memory_eval(chess_path, al, beta, depth - 1, MIN_LAYER_SIGN); 184 | if (eval > maxEval) { 185 | maxEval = eval; 186 | cur_best = chess_path; 187 | } 188 | al = al > eval ? al : eval; 189 | if (beta <= al) { 190 | break; 191 | } 192 | } 193 | 194 | // 将可能的情况保存到置换表 195 | if (maxEval <= alpha) { 196 | update_up_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 197 | } 198 | if (alpha < maxEval && maxEval < beta) { 199 | update_lo_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 200 | update_up_bound(tableMsg, maxEval + 1, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 201 | } 202 | if (maxEval >= beta) { 203 | update_lo_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 204 | } 205 | chessboard.undo_move_chess(path); 206 | return maxEval; 207 | 208 | } else { // min层 209 | 210 | // 搜索对手的可能路径 211 | paths_t possible_paths; 212 | if (tableMsg != nullptr) { 213 | possible_paths.push_back(tableMsg->best_path); 214 | chessboard.get_all_paths(MAX_LAYER_SIGN, possible_paths); 215 | std::sort(possible_paths.begin() + 1, possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 216 | return p2.value > p1.value; 217 | }); 218 | } else { 219 | chessboard.get_all_paths(MAX_LAYER_SIGN, possible_paths); 220 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 221 | return p2.value > p1.value; 222 | }); 223 | } 224 | 225 | int be = beta; 226 | int minEval = MAX_EVAL_VAL; 227 | ChessPath cur_best = possible_paths[0]; 228 | 229 | for (ChessPath &chessPath: possible_paths) { 230 | int eval = alpha_beta_with_memory_eval(chessPath, alpha, be, depth - 1, MAX_LAYER_SIGN); 231 | if (eval < minEval) { 232 | minEval = eval; 233 | cur_best = chessPath; 234 | } 235 | be = be < eval ? be : eval; 236 | if (be <= alpha) { 237 | break; 238 | } 239 | } 240 | 241 | // 将可能的情况保存到置换表 242 | if (minEval <= alpha) { 243 | update_up_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 244 | } 245 | if (alpha < minEval && minEval < beta) { 246 | update_lo_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 247 | update_up_bound(tableMsg, minEval + 1, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 248 | } 249 | if (minEval >= beta) { 250 | update_lo_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 251 | } 252 | 253 | // 恢复棋盘 254 | chessboard.undo_move_chess(path); 255 | return minEval; 256 | } 257 | } 258 | 259 | int AlphaBetaWithMemory::eval_path_val(const ChessPath &path, int depth) { 260 | this->search_depth = depth; 261 | return this->alpha_beta_with_memory_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, 262 | this->search_depth, MIN_LAYER_SIGN); 263 | } 264 | 265 | int AlphaBetaWithMemory::eval_path_val(const ChessPath &path, int depth, int color_sign) { 266 | this->search_depth = depth; 267 | return this->alpha_beta_with_memory_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, 268 | this->search_depth, color_sign); 269 | } -------------------------------------------------------------------------------- /html/js/play.js: -------------------------------------------------------------------------------- 1 | /*! 一叶孤舟 | qq:28701884 | 欢迎指教 */ 2 | 3 | var play = play || {}; 4 | 5 | play.init = function () { 6 | 7 | play.my = 1; //玩家方 8 | play.map = com.arr2Clone(com.initMap); //初始化棋盘 9 | play.nowManKey = false; //现在要操作的棋子 10 | play.pace = []; //记录每一步 11 | play.isPlay = true; //是否能走棋 12 | play.mans = com.mans; 13 | play.bylaw = com.bylaw; 14 | play.show = com.show; 15 | play.showPane = com.showPane; 16 | play.isOffensive = true; //是否先手 17 | play.depth = play.depth || 3; //搜索深度 18 | 19 | play.isFoul = false; //是否犯规长将 20 | 21 | 22 | com.pane.isShow = false; //隐藏方块 23 | 24 | //初始化棋子 25 | for (var i = 0; i < play.map.length; i++) { 26 | for (var n = 0; n < play.map[i].length; n++) { 27 | var key = play.map[i][n]; 28 | if (key) { 29 | com.mans[key].x = n; 30 | com.mans[key].y = i; 31 | com.mans[key].isShow = true; 32 | } 33 | } 34 | } 35 | play.show(); 36 | 37 | //绑定点击事件 38 | com.canvas.addEventListener("click", play.clickCanvas) 39 | 40 | 41 | com.get("regretBn").addEventListener("click", function (e) { 42 | play.regret(); 43 | }) 44 | } 45 | 46 | 47 | //悔棋 48 | play.regret = function () { 49 | var map = com.arr2Clone(com.initMap); 50 | //初始化所有棋子 51 | for (var i = 0; i < map.length; i++) { 52 | for (var n = 0; n < map[i].length; n++) { 53 | var key = map[i][n]; 54 | if (key) { 55 | com.mans[key].x = n; 56 | com.mans[key].y = i; 57 | com.mans[key].isShow = true; 58 | } 59 | } 60 | } 61 | var pace = play.pace; 62 | pace.pop(); 63 | pace.pop(); 64 | 65 | for (var i = 0; i < pace.length; i++) { 66 | var p = pace[i].split("") 67 | var x = parseInt(p[0], 10); 68 | var y = parseInt(p[1], 10); 69 | var newX = parseInt(p[2], 10); 70 | var newY = parseInt(p[3], 10); 71 | var key = map[y][x]; 72 | //try{ 73 | 74 | var cMan = map[newY][newX]; 75 | if (cMan) com.mans[map[newY][newX]].isShow = false; 76 | com.mans[key].x = newX; 77 | com.mans[key].y = newY; 78 | map[newY][newX] = key; 79 | delete map[y][x]; 80 | if (i == pace.length - 1) { 81 | com.showPane(newX, newY, x, y) 82 | } 83 | //} catch (e){ 84 | // com.show() 85 | // z([key,p,pace,map]) 86 | 87 | // } 88 | } 89 | play.map = map; 90 | play.my = 1; 91 | play.isPlay = true; 92 | com.show(); 93 | } 94 | 95 | 96 | //点击棋盘事件 97 | play.clickCanvas = function (e) { 98 | if (!play.isPlay) return false; 99 | var key = play.getClickMan(e); 100 | var point = play.getClickPoint(e); 101 | 102 | var x = point.x; 103 | var y = point.y; 104 | 105 | if (key) { 106 | play.clickMan(key, x, y); 107 | } else { 108 | play.clickPoint(x, y); 109 | } 110 | play.isFoul = play.checkFoul();//检测是不是长将 111 | } 112 | 113 | 114 | //点击棋子,两种情况,选中或者吃子 115 | play.clickMan = function (key, x, y) { 116 | var man = com.mans[key]; 117 | //吃子 118 | if (play.nowManKey && play.nowManKey != key && man.my != com.mans[play.nowManKey].my) { 119 | //man为被吃掉的棋子 120 | if (play.indexOfPs(com.mans[play.nowManKey].ps, [x, y])) { 121 | man.isShow = false; 122 | var pace = com.mans[play.nowManKey].x + "" + com.mans[play.nowManKey].y 123 | //z(bill.createMove(play.map,man.x,man.y,x,y)) 124 | delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x]; 125 | play.map[y][x] = play.nowManKey; 126 | com.showPane(com.mans[play.nowManKey].x, com.mans[play.nowManKey].y, x, y) 127 | com.mans[play.nowManKey].x = x; 128 | com.mans[play.nowManKey].y = y; 129 | com.mans[play.nowManKey].alpha = 1 130 | 131 | play.pace.push(pace + x + y); 132 | play.nowManKey = false; 133 | com.pane.isShow = false; 134 | com.dot.dots = []; 135 | com.show() 136 | com.get("clickAudio").play(); 137 | setTimeout("play.AIPlay()", 500); 138 | if (key == "j0") play.showWin(-1); 139 | if (key == "J0") play.showWin(1); 140 | } 141 | // 选中棋子 142 | } else { 143 | if (man.my === 1) { 144 | if (com.mans[play.nowManKey]) com.mans[play.nowManKey].alpha = 1; 145 | man.alpha = 0.6; 146 | com.pane.isShow = false; 147 | play.nowManKey = key; 148 | com.mans[key].ps = com.mans[key].bl(); //获得所有能着点 149 | com.dot.dots = com.mans[key].ps 150 | com.show(); 151 | //com.get("selectAudio").start(0); 152 | com.get("selectAudio").play(); 153 | } 154 | } 155 | } 156 | 157 | //点击着点 158 | play.clickPoint = function (x, y) { 159 | var key = play.nowManKey; 160 | var man = com.mans[key]; 161 | if (play.nowManKey) { 162 | if (play.indexOfPs(com.mans[key].ps, [x, y])) { 163 | var pace = man.x + "" + man.y 164 | //z(bill.createMove(play.map,man.x,man.y,x,y)) 165 | delete play.map[man.y][man.x]; 166 | play.map[y][x] = key; 167 | com.showPane(man.x, man.y, x, y) 168 | man.x = x; 169 | man.y = y; 170 | man.alpha = 1; 171 | play.pace.push(pace + x + y); 172 | play.nowManKey = false; 173 | com.dot.dots = []; 174 | com.show(); 175 | com.get("clickAudio").play(); 176 | setTimeout("play.AIPlay()", 500); 177 | } else { 178 | //alert("不能这么走哦!") 179 | } 180 | } 181 | } 182 | 183 | 184 | //Ai自动走棋 185 | play.AIPlay = function () { 186 | //return 187 | // TODO ziri----将棋盘信息发送到本地服务器 188 | // 189 | play.my = -1; 190 | //var pace = AI.init(play.pace.join("")) 191 | var pace = []; 192 | // [ '1' , '0' , '2' , '2 '] 193 | // 服务器的对应坐标是 0,1,2,2,解析的时候需要注意 194 | // ---------------------------------------------------------------- 195 | // 棋盘信息,发送给服务器 196 | let chessboardMessage = ''; 197 | var tmap = com.arr2Clone(play.map); 198 | for (let i = 0; i < 10; i++) { 199 | for (let j = 0; j < 9; j++) { 200 | tmap[i][j] = play.map[9 - i][8 - j]; 201 | } 202 | } 203 | for (let i = 0; i < 10; i++) { 204 | for (let j = 0; j < 9; j++) { 205 | if (tmap[i][j] == 'c0' || tmap[i][j] == 'c1') { 206 | chessboardMessage += '-1'; 207 | } else if (tmap[i][j] == 'C0' || tmap[i][j] == 'C1') { 208 | chessboardMessage += '1'; 209 | } else if (tmap[i][j] == 'm0' || tmap[i][j] == 'm1') { 210 | chessboardMessage += '-2'; 211 | } else if (tmap[i][j] == 'M0' || tmap[i][j] == 'M1') { 212 | chessboardMessage += '2'; 213 | } else if (tmap[i][j] == 'x0' || tmap[i][j] == 'x1') { 214 | chessboardMessage += '-3'; 215 | } else if (tmap[i][j] == 'X0' || tmap[i][j] == 'X1') { 216 | chessboardMessage += '3'; 217 | } else if (tmap[i][j] == 's0' || tmap[i][j] == 's1') { 218 | chessboardMessage += '-4'; 219 | } else if (tmap[i][j] == 'S0' || tmap[i][j] == 'S1') { 220 | chessboardMessage += '4'; 221 | } else if (tmap[i][j] == 'j0') { 222 | chessboardMessage += '-5'; 223 | } else if (tmap[i][j] == 'J0') { 224 | chessboardMessage += '5'; 225 | } else if (tmap[i][j] == 'p0' || tmap[i][j] == 'p1') { 226 | chessboardMessage += '-6'; 227 | } else if (tmap[i][j] == 'P0' || tmap[i][j] == 'P1') { 228 | chessboardMessage += '6'; 229 | } else if (tmap[i][j] == 'z0' || tmap[i][j] == 'z1' || tmap[i][j] == 'z2' || tmap[i][j] == 'z3' || tmap[i][j] == 'z4') { 230 | chessboardMessage += '-7'; 231 | } else if (tmap[i][j] == 'Z0' || tmap[i][j] == 'Z1' || tmap[i][j] == 'Z2' || tmap[i][j] == 'Z3' || tmap[i][j] == 'Z4') { 232 | chessboardMessage += '7'; 233 | } else { 234 | chessboardMessage += '0'; 235 | } 236 | if (i != 9 || j != 8) { 237 | chessboardMessage += ';'; 238 | } 239 | } 240 | } 241 | console.log(chessboardMessage); 242 | // 发送http请求到服务器 243 | let url = "http://127.0.0.1:8080"; 244 | var request = new XMLHttpRequest(); 245 | request.open('POST', url, true); 246 | request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 247 | // request.send("chessboard=" + chessboardMessage); 248 | let json = "{ \"" + "chessboard" + "\":\"" + chessboardMessage + "\"}"; 249 | console.log(json) 250 | request.send(json); 251 | 252 | // 获取服务器响应 253 | var responseResult = ""; 254 | request.onreadystatechange = function () { 255 | if (request.readyState === 4) { 256 | if (request.status === 200) { 257 | responseResult = request.responseText; 258 | console.log('response result: ' + responseResult); 259 | // 解析棋盘信息 260 | var respArr = responseResult.split(";"); 261 | let fromX = 8 - respArr[1]; 262 | let fromY = 9 - respArr[0]; 263 | let toX = 8 - respArr[3]; 264 | let toY = 9 - respArr[2]; 265 | var pace = [fromX, fromY, toX, toY]; 266 | console.log(pace) 267 | if (!pace) { 268 | play.showWin(1); 269 | return; 270 | } 271 | play.pace.push(pace.join("")); 272 | var key = play.map[pace[1]][pace[0]] 273 | play.nowManKey = key; 274 | 275 | var key = play.map[pace[3]][pace[2]]; 276 | if (key) { 277 | play.AIclickMan(key, pace[2], pace[3]); 278 | } else { 279 | play.AIclickPoint(pace[2], pace[3]); 280 | } 281 | //com.get("clickAudio").play(); 282 | } 283 | } 284 | } 285 | // ---------------------------------------------------------------- 286 | } 287 | 288 | 289 | //检查是否长将 290 | play.checkFoul = function () { 291 | var p = play.pace; 292 | var len = parseInt(p.length, 10); 293 | if (len > 11 && p[len - 1] == p[len - 5] && p[len - 5] == p[len - 9]) { 294 | return p[len - 4].split(""); 295 | } 296 | return false; 297 | } 298 | 299 | 300 | play.AIclickMan = function (key, x, y) { 301 | var man = com.mans[key]; 302 | //吃子 303 | man.isShow = false; 304 | delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x]; 305 | play.map[y][x] = play.nowManKey; 306 | play.showPane(com.mans[play.nowManKey].x, com.mans[play.nowManKey].y, x, y) 307 | 308 | com.mans[play.nowManKey].x = x; 309 | com.mans[play.nowManKey].y = y; 310 | play.nowManKey = false; 311 | 312 | com.show() 313 | if (key == "j0") play.showWin(-1); 314 | if (key == "J0") play.showWin(1); 315 | } 316 | 317 | play.AIclickPoint = function (x, y) { 318 | var key = play.nowManKey; 319 | var man = com.mans[key]; 320 | if (play.nowManKey) { 321 | delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x]; 322 | play.map[y][x] = key; 323 | 324 | com.showPane(man.x, man.y, x, y) 325 | 326 | 327 | man.x = x; 328 | man.y = y; 329 | play.nowManKey = false; 330 | 331 | } 332 | com.show(); 333 | } 334 | 335 | 336 | play.indexOfPs = function (ps, xy) { 337 | for (var i = 0; i < ps.length; i++) { 338 | if (ps[i][0] == xy[0] && ps[i][1] == xy[1]) return true; 339 | } 340 | return false; 341 | 342 | } 343 | 344 | //获得点击的着点 345 | play.getClickPoint = function (e) { 346 | var domXY = com.getDomXY(com.canvas); 347 | var x = Math.round((e.pageX - domXY.x - com.pointStartX - 20) / com.spaceX) 348 | var y = Math.round((e.pageY - domXY.y - com.pointStartY - 20) / com.spaceY) 349 | return {"x": x, "y": y} 350 | } 351 | 352 | //获得棋子 353 | play.getClickMan = function (e) { 354 | var clickXY = play.getClickPoint(e); 355 | var x = clickXY.x; 356 | var y = clickXY.y; 357 | if (x < 0 || x > 8 || y < 0 || y > 9) return false; 358 | return (play.map[y][x] && play.map[y][x] != "0") ? play.map[y][x] : false; 359 | } 360 | 361 | play.showWin = function (my) { 362 | play.isPlay = false; 363 | if (my === 1) { 364 | alert("恭喜你,你赢了!"); 365 | } else { 366 | alert("很遗憾,你输了!"); 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /cpp/source/quiescence.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 张睿 on 2022/5/29. 3 | // 4 | 5 | #include "../include/quiescence.h" 6 | 7 | int Quiescence::quiescence(ChessPath &path, int alpha, int beta, int maxDepth, int colorSign) { 8 | 9 | // 判断生死 10 | if (path.eat == 5) { 11 | return MIN_EVAL_VAL; 12 | } 13 | if (path.eat == -5) { 14 | return MAX_EVAL_VAL; 15 | } 16 | 17 | // 到达搜索深度 18 | if (maxDepth == 1) { 19 | chessboard.move_chess(path); 20 | int val = chessboard.get_on_board_val(); 21 | chessboard.undo_move_chess(path); 22 | return val; 23 | } 24 | 25 | // 下棋 26 | chessboard.move_chess(path); 27 | 28 | // 落子后先判断是否有对将情况 29 | if (chessboard.is_general_face2face()) { 30 | if (colorSign == MAX_LAYER_SIGN) { 31 | chessboard.undo_move_chess(path); 32 | return MAX_EVAL_VAL; 33 | } else { 34 | chessboard.undo_move_chess(path); 35 | return MIN_EVAL_VAL; 36 | } 37 | } 38 | 39 | // max 40 | if (colorSign == MAX_LAYER_SIGN) { 41 | paths_t chessPaths; 42 | chessboard.get_all_paths(MIN_LAYER_SIGN, chessPaths); 43 | 44 | // 如果结果为空,返回当前棋盘的价值 45 | if (chessPaths.empty()) { 46 | int val = chessboard.get_on_board_val(); 47 | chessboard.undo_move_chess(path); 48 | return val; 49 | } 50 | 51 | // 如果没有被将军,只生成吃子的路径,并使用mvv/lva启发 52 | if (!chessboard.is_checked(MIN_LAYER_SIGN)) { 53 | paths_t eat_paths; 54 | for (auto &p: chessPaths) { 55 | if (p.eat != 0) { 56 | eat_paths.emplace_back(p); 57 | } 58 | } 59 | 60 | // 如果结果为空,返回当前棋盘的价值 61 | if (eat_paths.empty()) { 62 | int val = chessboard.get_on_board_val(); 63 | chessboard.undo_move_chess(path); 64 | return val; 65 | } 66 | 67 | // 启发 68 | sort(eat_paths.begin(), eat_paths.end(), [](ChessPath &l, ChessPath &r) { 69 | #ifndef MVV_LVA 70 | return l.value > r.value; 71 | #else 72 | if (get_pos_val(l.to_x, l.to_y, l.eat) != get_pos_val(r.to_x, r.to_y, r.eat)) { 73 | return get_pos_val(l.to_x, l.to_y, l.eat) < get_pos_val(r.to_x, r.to_y, r.eat); 74 | } else { 75 | return get_pos_val(l.from_x, l.from_y, chessboard.board[l.from_x][l.from_y]) < 76 | get_pos_val(r.from_x, r.from_y, chessboard.board[r.from_x][r.from_y]); 77 | } 78 | #endif 79 | }); 80 | 81 | int maxEval = MIN_EVAL_VAL; 82 | for (ChessPath chessPath: eat_paths) { 83 | int eval = quiescence(chessPath, alpha, beta, maxDepth - 1, MIN_LAYER_SIGN); 84 | maxEval = maxEval > eval ? maxEval : eval; 85 | alpha = alpha > maxEval ? alpha : maxEval; 86 | if (beta <= alpha) { 87 | break; 88 | } 89 | } 90 | chessboard.undo_move_chess(path); 91 | return maxEval; 92 | 93 | } else { 94 | 95 | sort(chessPaths.begin(), chessPaths.end(), [](ChessPath &l, ChessPath &r) { 96 | return l.value > r.value; 97 | }); 98 | 99 | int maxEval = MIN_EVAL_VAL; 100 | for (ChessPath chessPath: chessPaths) { 101 | int eval = quiescence(chessPath, alpha, beta, maxDepth - 1, MIN_LAYER_SIGN); 102 | maxEval = maxEval > eval ? maxEval : eval; 103 | alpha = alpha > maxEval ? alpha : maxEval; 104 | if (beta <= alpha) { 105 | break; 106 | } 107 | } 108 | chessboard.undo_move_chess(path); 109 | return maxEval; 110 | } 111 | 112 | } else { 113 | paths_t chessPaths; 114 | chessboard.get_all_paths(MAX_LAYER_SIGN, chessPaths); 115 | 116 | // 如果结果为空,返回当前棋盘的价值 117 | if (chessPaths.empty()) { 118 | int val = chessboard.get_on_board_val(); 119 | chessboard.undo_move_chess(path); 120 | return val; 121 | } 122 | 123 | // 如果没有被将军,只生成吃子的路径,并使用mvv/lva启发 124 | if (!chessboard.is_checked(MAX_LAYER_SIGN)) { 125 | paths_t eat_paths; 126 | for (auto &p: chessPaths) { 127 | if (p.eat != 0) { 128 | eat_paths.emplace_back(p); 129 | } 130 | } 131 | 132 | // 如果结果为空,返回当前棋盘的价值 133 | if (eat_paths.empty()) { 134 | int val = chessboard.get_on_board_val(); 135 | chessboard.undo_move_chess(path); 136 | return val; 137 | } 138 | 139 | // 启发 140 | sort(eat_paths.begin(), eat_paths.end(), [](ChessPath &l, ChessPath &r) { 141 | #ifndef MVV_LVA 142 | return l.value < r.value; 143 | #else 144 | if (get_pos_val(l.to_x, l.to_y, l.eat) != get_pos_val(r.to_x, r.to_y, r.eat)) { 145 | return get_pos_val(l.to_x, l.to_y, l.eat) > get_pos_val(r.to_x, r.to_y, r.eat); 146 | } else { 147 | return get_pos_val(l.from_x, l.from_y, chessboard.board[l.from_x][l.from_y]) > 148 | get_pos_val(r.from_x, r.from_y, chessboard.board[r.from_x][r.from_y]); 149 | } 150 | #endif 151 | }); 152 | 153 | int minEval = MAX_EVAL_VAL; 154 | for (ChessPath &chessPath: eat_paths) { 155 | int eval = quiescence(chessPath, alpha, beta, maxDepth - 1, MAX_LAYER_SIGN); 156 | minEval = minEval < eval ? minEval : eval; 157 | beta = beta < eval ? beta : eval; 158 | if (beta <= alpha) { 159 | break; 160 | } 161 | } 162 | 163 | // 恢复棋盘 164 | chessboard.undo_move_chess(path); 165 | return minEval; 166 | } else { 167 | 168 | sort(chessPaths.begin(), chessPaths.end(), [](ChessPath &l, ChessPath &r) { 169 | return l.value < r.value; 170 | }); 171 | 172 | int minEval = MAX_EVAL_VAL; 173 | for (ChessPath chessPath: chessPaths) { 174 | int eval = quiescence(chessPath, alpha, beta, maxDepth - 1, MAX_LAYER_SIGN); 175 | minEval = minEval < eval ? minEval : eval; 176 | beta = beta < eval ? beta : eval; 177 | if (beta <= alpha) { 178 | break; 179 | } 180 | } 181 | chessboard.undo_move_chess(path); 182 | return minEval; 183 | } 184 | } 185 | } 186 | 187 | 188 | int Quiescence::alpha_beta_quiescence_with_memory_eval(ChessPath &path, int alpha, int beta, int depth, int colorSign) { 189 | 190 | // 判断生死 191 | if (path.eat == -5) { 192 | return MAX_EVAL_VAL; 193 | } else if (path.eat == 5) { 194 | return MIN_EVAL_VAL; 195 | } 196 | 197 | // 落子 198 | chessboard.move_chess(path); 199 | 200 | // 落子后先判断是否有对将情况 201 | if (chessboard.is_general_face2face()) { 202 | if (colorSign == MAX_LAYER_SIGN) { 203 | chessboard.undo_move_chess(path); 204 | return MAX_EVAL_VAL + depth; 205 | } else { 206 | chessboard.undo_move_chess(path); 207 | return MIN_EVAL_VAL - depth; 208 | } 209 | } 210 | 211 | // -------------------- 查询置换表 --------------------------------------------------- 212 | int ch_hash = chessboard.get_hash(); 213 | int ch_ver = chessboard.get_verify(); 214 | TableMsg *tableMsg; 215 | 216 | if (colorSign == MAX_LAYER_SIGN) { 217 | tableMsg = tran_table_max.get_table(ch_hash, ch_ver); 218 | } else { 219 | tableMsg = tran_table_min.get_table(ch_hash, ch_ver); 220 | } 221 | 222 | // 要求能查询到当前局面,且置换表中的深度要大于当前深度时才使用置换表 223 | if (tableMsg != nullptr) { 224 | if (tableMsg->lo_depth <= depth) { 225 | if (tableMsg->lo_bound >= beta) { 226 | chessboard.undo_move_chess(path); 227 | return tableMsg->lo_bound; 228 | } 229 | alpha = alpha > tableMsg->lo_bound ? alpha : tableMsg->lo_bound; 230 | } 231 | if (tableMsg->up_depth <= depth) { 232 | if (tableMsg->up_bound <= alpha) { 233 | chessboard.undo_move_chess(path); 234 | return tableMsg->up_bound; 235 | } 236 | beta = beta < tableMsg->up_bound ? beta : tableMsg->up_bound; 237 | } 238 | } 239 | // -------------------- 查询置换表 --------------------------------------------------- 240 | 241 | // max层 242 | if (colorSign == MAX_LAYER_SIGN) { 243 | 244 | // 处理叶子节点 245 | if (depth == 1) { 246 | if (path.eat != 0) { // 如果正在发生吃子,进行静态搜索 247 | chessboard.undo_move_chess(path); 248 | // 这里要调用 MAX_LAYER_SIGN,因为静态搜索要帮助当前层完成搜索 249 | return quiescence(path, alpha, beta, QUIESCENCE_MAX_DEPTH, MAX_LAYER_SIGN); 250 | } else { // 如果没有上述两种局面,评估并返回结果 251 | int val = chessboard.get_on_board_val(); 252 | chessboard.undo_move_chess(path); 253 | return val; 254 | } 255 | } 256 | 257 | // 对手搜索我方可能的路径 258 | paths_t possible_paths; 259 | if (tableMsg != nullptr) { 260 | possible_paths.push_back(tableMsg->best_path); 261 | chessboard.get_all_paths(MIN_LAYER_SIGN, possible_paths); 262 | std::sort(possible_paths.begin() + 1, possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 263 | return p2.value < p1.value; 264 | }); 265 | } else { 266 | chessboard.get_all_paths(MIN_LAYER_SIGN, possible_paths); 267 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 268 | return p2.value < p1.value; 269 | }); 270 | } 271 | 272 | int al = alpha; 273 | int maxEval = MIN_EVAL_VAL; 274 | ChessPath cur_best = possible_paths[0]; 275 | 276 | for (ChessPath &chess_path: possible_paths) { 277 | int eval = alpha_beta_quiescence_with_memory_eval(chess_path, al, beta, depth - 1, MIN_LAYER_SIGN); 278 | if (eval > maxEval) { 279 | maxEval = eval; 280 | cur_best = chess_path; 281 | } 282 | al = al > eval ? al : eval; 283 | if (beta <= al) { 284 | break; 285 | } 286 | } 287 | 288 | // 将可能的情况保存到置换表 289 | if (maxEval <= alpha) { 290 | update_up_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 291 | } 292 | if (alpha < maxEval && maxEval < beta) { 293 | update_lo_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 294 | update_up_bound(tableMsg, maxEval + 1, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 295 | } 296 | if (maxEval >= beta) { 297 | update_lo_bound(tableMsg, maxEval, MAX_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 298 | } 299 | chessboard.undo_move_chess(path); 300 | return maxEval; 301 | 302 | } else { // min层 303 | 304 | // 处理叶子节点 305 | if (depth == 1) { 306 | if (path.eat != 0) { // 如果正在发生吃子,进行静态搜索 307 | chessboard.undo_move_chess(path); 308 | // 这里要调用 MIN_LAYER_SIGN,因为静态搜索要帮助当前层完成搜索 309 | return quiescence(path, alpha, beta, QUIESCENCE_MAX_DEPTH, MIN_LAYER_SIGN); 310 | } else { // 如果没有上述两种局面,评估并返回结果 311 | int val = chessboard.get_on_board_val(); 312 | chessboard.undo_move_chess(path); 313 | return val; 314 | } 315 | } 316 | 317 | // 搜索对手的可能路径 318 | paths_t possible_paths; 319 | if (tableMsg != nullptr) { 320 | possible_paths.push_back(tableMsg->best_path); 321 | chessboard.get_all_paths(MAX_LAYER_SIGN, possible_paths); 322 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 323 | return p2.value > p1.value; 324 | }); 325 | } else { 326 | chessboard.get_all_paths(MAX_LAYER_SIGN, possible_paths); 327 | std::sort(possible_paths.begin(), possible_paths.end(), [](ChessPath &p1, ChessPath &p2) { 328 | return p2.value > p1.value; 329 | }); 330 | } 331 | 332 | int be = beta; 333 | int minEval = MAX_EVAL_VAL; 334 | ChessPath cur_best = possible_paths[0]; 335 | 336 | for (ChessPath &chessPath: possible_paths) { 337 | int eval = alpha_beta_quiescence_with_memory_eval(chessPath, alpha, be, depth - 1, MAX_LAYER_SIGN); 338 | if (eval < minEval) { 339 | minEval = eval; 340 | cur_best = chessPath; 341 | } 342 | be = be < eval ? be : eval; 343 | if (be <= alpha) { 344 | break; 345 | } 346 | } 347 | 348 | // 将可能的情况保存到置换表 349 | if (minEval <= alpha) { 350 | update_up_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 351 | } 352 | if (alpha < minEval && minEval < beta) { 353 | update_lo_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 354 | update_up_bound(tableMsg, minEval + 1, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 355 | } 356 | if (minEval >= beta) { 357 | update_lo_bound(tableMsg, minEval, MIN_LAYER_SIGN, depth, ch_hash, ch_ver, cur_best); 358 | } 359 | 360 | // 恢复棋盘 361 | chessboard.undo_move_chess(path); 362 | return minEval; 363 | } 364 | } 365 | 366 | 367 | int Quiescence::eval_path_val(const ChessPath &path, int depth) { 368 | this->search_depth = depth; 369 | return alpha_beta_quiescence_with_memory_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, depth, 370 | MIN_LAYER_SIGN); 371 | } 372 | 373 | 374 | int Quiescence::eval_path_val(const ChessPath &path, int depth, int color_sign) { 375 | this->search_depth = depth; 376 | return alpha_beta_quiescence_with_memory_eval(const_cast(path), ALPHA_INIT_VAL, BETA_INIT_VAL, depth, 377 | color_sign); 378 | } 379 | -------------------------------------------------------------------------------- /cmake-build-release/Makefile: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | .PHONY : default_target 7 | 8 | # Allow only one "make -f Makefile2" at a time, but pass parallelism. 9 | .NOTPARALLEL: 10 | 11 | #============================================================================= 12 | # Special targets provided by cmake. 13 | 14 | # Disable implicit rules so canonical targets will work. 15 | .SUFFIXES: 16 | 17 | # Disable VCS-based implicit rules. 18 | % : %,v 19 | 20 | # Disable VCS-based implicit rules. 21 | % : RCS/% 22 | 23 | # Disable VCS-based implicit rules. 24 | % : RCS/%,v 25 | 26 | # Disable VCS-based implicit rules. 27 | % : SCCS/s.% 28 | 29 | # Disable VCS-based implicit rules. 30 | % : s.% 31 | 32 | .SUFFIXES: .hpux_make_needs_suffix_list 33 | 34 | # Command-line flag to silence nested $(MAKE). 35 | $(VERBOSE)MAKESILENT = -s 36 | 37 | #Suppress display of executed commands. 38 | $(VERBOSE).SILENT: 39 | 40 | # A target that is always out of date. 41 | cmake_force: 42 | .PHONY : cmake_force 43 | 44 | #============================================================================= 45 | # Set environment variables for the build. 46 | 47 | # The shell in which to execute make rules. 48 | SHELL = /bin/sh 49 | 50 | # The CMake executable. 51 | CMAKE_COMMAND = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake 52 | 53 | # The command to remove a file. 54 | RM = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E rm -f 55 | 56 | # Escaping for special characters. 57 | EQUALS = = 58 | 59 | # The top-level source directory on which CMake was run. 60 | CMAKE_SOURCE_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp 61 | 62 | # The top-level build directory on which CMake was run. 63 | CMAKE_BINARY_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release 64 | 65 | #============================================================================= 66 | # Targets provided globally by CMake. 67 | 68 | # Special rule for the target edit_cache 69 | edit_cache: 70 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." 71 | /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. 72 | .PHONY : edit_cache 73 | 74 | # Special rule for the target edit_cache 75 | edit_cache/fast: edit_cache 76 | .PHONY : edit_cache/fast 77 | 78 | # Special rule for the target rebuild_cache 79 | rebuild_cache: 80 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." 81 | /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 82 | .PHONY : rebuild_cache 83 | 84 | # Special rule for the target rebuild_cache 85 | rebuild_cache/fast: rebuild_cache 86 | .PHONY : rebuild_cache/fast 87 | 88 | # The main all target 89 | all: cmake_check_build_system 90 | $(CMAKE_COMMAND) -E cmake_progress_start /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release//CMakeFiles/progress.marks 91 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all 92 | $(CMAKE_COMMAND) -E cmake_progress_start /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles 0 93 | .PHONY : all 94 | 95 | # The main clean target 96 | clean: 97 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean 98 | .PHONY : clean 99 | 100 | # The main clean target 101 | clean/fast: clean 102 | .PHONY : clean/fast 103 | 104 | # Prepare targets for installation. 105 | preinstall: all 106 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall 107 | .PHONY : preinstall 108 | 109 | # Prepare targets for installation. 110 | preinstall/fast: 111 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall 112 | .PHONY : preinstall/fast 113 | 114 | # clear depends 115 | depend: 116 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 117 | .PHONY : depend 118 | 119 | #============================================================================= 120 | # Target rules for targets named vliang_chinese_chess 121 | 122 | # Build rule for target. 123 | vliang_chinese_chess: cmake_check_build_system 124 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 vliang_chinese_chess 125 | .PHONY : vliang_chinese_chess 126 | 127 | # fast build rule for target. 128 | vliang_chinese_chess/fast: 129 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/build 130 | .PHONY : vliang_chinese_chess/fast 131 | 132 | cpp/source/alpha_beta.o: cpp/source/alpha_beta.cpp.o 133 | .PHONY : cpp/source/alpha_beta.o 134 | 135 | # target to build an object file 136 | cpp/source/alpha_beta.cpp.o: 137 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o 138 | .PHONY : cpp/source/alpha_beta.cpp.o 139 | 140 | cpp/source/alpha_beta.i: cpp/source/alpha_beta.cpp.i 141 | .PHONY : cpp/source/alpha_beta.i 142 | 143 | # target to preprocess a source file 144 | cpp/source/alpha_beta.cpp.i: 145 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.i 146 | .PHONY : cpp/source/alpha_beta.cpp.i 147 | 148 | cpp/source/alpha_beta.s: cpp/source/alpha_beta.cpp.s 149 | .PHONY : cpp/source/alpha_beta.s 150 | 151 | # target to generate assembly for a file 152 | cpp/source/alpha_beta.cpp.s: 153 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.s 154 | .PHONY : cpp/source/alpha_beta.cpp.s 155 | 156 | cpp/source/chessboard.o: cpp/source/chessboard.cpp.o 157 | .PHONY : cpp/source/chessboard.o 158 | 159 | # target to build an object file 160 | cpp/source/chessboard.cpp.o: 161 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o 162 | .PHONY : cpp/source/chessboard.cpp.o 163 | 164 | cpp/source/chessboard.i: cpp/source/chessboard.cpp.i 165 | .PHONY : cpp/source/chessboard.i 166 | 167 | # target to preprocess a source file 168 | cpp/source/chessboard.cpp.i: 169 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.i 170 | .PHONY : cpp/source/chessboard.cpp.i 171 | 172 | cpp/source/chessboard.s: cpp/source/chessboard.cpp.s 173 | .PHONY : cpp/source/chessboard.s 174 | 175 | # target to generate assembly for a file 176 | cpp/source/chessboard.cpp.s: 177 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.s 178 | .PHONY : cpp/source/chessboard.cpp.s 179 | 180 | cpp/source/evaluator.o: cpp/source/evaluator.cpp.o 181 | .PHONY : cpp/source/evaluator.o 182 | 183 | # target to build an object file 184 | cpp/source/evaluator.cpp.o: 185 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o 186 | .PHONY : cpp/source/evaluator.cpp.o 187 | 188 | cpp/source/evaluator.i: cpp/source/evaluator.cpp.i 189 | .PHONY : cpp/source/evaluator.i 190 | 191 | # target to preprocess a source file 192 | cpp/source/evaluator.cpp.i: 193 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.i 194 | .PHONY : cpp/source/evaluator.cpp.i 195 | 196 | cpp/source/evaluator.s: cpp/source/evaluator.cpp.s 197 | .PHONY : cpp/source/evaluator.s 198 | 199 | # target to generate assembly for a file 200 | cpp/source/evaluator.cpp.s: 201 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.s 202 | .PHONY : cpp/source/evaluator.cpp.s 203 | 204 | cpp/source/mtdf.o: cpp/source/mtdf.cpp.o 205 | .PHONY : cpp/source/mtdf.o 206 | 207 | # target to build an object file 208 | cpp/source/mtdf.cpp.o: 209 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o 210 | .PHONY : cpp/source/mtdf.cpp.o 211 | 212 | cpp/source/mtdf.i: cpp/source/mtdf.cpp.i 213 | .PHONY : cpp/source/mtdf.i 214 | 215 | # target to preprocess a source file 216 | cpp/source/mtdf.cpp.i: 217 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.i 218 | .PHONY : cpp/source/mtdf.cpp.i 219 | 220 | cpp/source/mtdf.s: cpp/source/mtdf.cpp.s 221 | .PHONY : cpp/source/mtdf.s 222 | 223 | # target to generate assembly for a file 224 | cpp/source/mtdf.cpp.s: 225 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.s 226 | .PHONY : cpp/source/mtdf.cpp.s 227 | 228 | cpp/source/quiescence.o: cpp/source/quiescence.cpp.o 229 | .PHONY : cpp/source/quiescence.o 230 | 231 | # target to build an object file 232 | cpp/source/quiescence.cpp.o: 233 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o 234 | .PHONY : cpp/source/quiescence.cpp.o 235 | 236 | cpp/source/quiescence.i: cpp/source/quiescence.cpp.i 237 | .PHONY : cpp/source/quiescence.i 238 | 239 | # target to preprocess a source file 240 | cpp/source/quiescence.cpp.i: 241 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.i 242 | .PHONY : cpp/source/quiescence.cpp.i 243 | 244 | cpp/source/quiescence.s: cpp/source/quiescence.cpp.s 245 | .PHONY : cpp/source/quiescence.s 246 | 247 | # target to generate assembly for a file 248 | cpp/source/quiescence.cpp.s: 249 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.s 250 | .PHONY : cpp/source/quiescence.cpp.s 251 | 252 | cpp/source/tree_search.o: cpp/source/tree_search.cpp.o 253 | .PHONY : cpp/source/tree_search.o 254 | 255 | # target to build an object file 256 | cpp/source/tree_search.cpp.o: 257 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o 258 | .PHONY : cpp/source/tree_search.cpp.o 259 | 260 | cpp/source/tree_search.i: cpp/source/tree_search.cpp.i 261 | .PHONY : cpp/source/tree_search.i 262 | 263 | # target to preprocess a source file 264 | cpp/source/tree_search.cpp.i: 265 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.i 266 | .PHONY : cpp/source/tree_search.cpp.i 267 | 268 | cpp/source/tree_search.s: cpp/source/tree_search.cpp.s 269 | .PHONY : cpp/source/tree_search.s 270 | 271 | # target to generate assembly for a file 272 | cpp/source/tree_search.cpp.s: 273 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.s 274 | .PHONY : cpp/source/tree_search.cpp.s 275 | 276 | evaluator_so.o: evaluator_so.cpp.o 277 | .PHONY : evaluator_so.o 278 | 279 | # target to build an object file 280 | evaluator_so.cpp.o: 281 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o 282 | .PHONY : evaluator_so.cpp.o 283 | 284 | evaluator_so.i: evaluator_so.cpp.i 285 | .PHONY : evaluator_so.i 286 | 287 | # target to preprocess a source file 288 | evaluator_so.cpp.i: 289 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.i 290 | .PHONY : evaluator_so.cpp.i 291 | 292 | evaluator_so.s: evaluator_so.cpp.s 293 | .PHONY : evaluator_so.s 294 | 295 | # target to generate assembly for a file 296 | evaluator_so.cpp.s: 297 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.s 298 | .PHONY : evaluator_so.cpp.s 299 | 300 | main.o: main.cpp.o 301 | .PHONY : main.o 302 | 303 | # target to build an object file 304 | main.cpp.o: 305 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/main.cpp.o 306 | .PHONY : main.cpp.o 307 | 308 | main.i: main.cpp.i 309 | .PHONY : main.i 310 | 311 | # target to preprocess a source file 312 | main.cpp.i: 313 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/main.cpp.i 314 | .PHONY : main.cpp.i 315 | 316 | main.s: main.cpp.s 317 | .PHONY : main.s 318 | 319 | # target to generate assembly for a file 320 | main.cpp.s: 321 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/main.cpp.s 322 | .PHONY : main.cpp.s 323 | 324 | py_interface.o: py_interface.cpp.o 325 | .PHONY : py_interface.o 326 | 327 | # target to build an object file 328 | py_interface.cpp.o: 329 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o 330 | .PHONY : py_interface.cpp.o 331 | 332 | py_interface.i: py_interface.cpp.i 333 | .PHONY : py_interface.i 334 | 335 | # target to preprocess a source file 336 | py_interface.cpp.i: 337 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.i 338 | .PHONY : py_interface.cpp.i 339 | 340 | py_interface.s: py_interface.cpp.s 341 | .PHONY : py_interface.s 342 | 343 | # target to generate assembly for a file 344 | py_interface.cpp.s: 345 | $(MAKE) $(MAKESILENT) -f CMakeFiles/vliang_chinese_chess.dir/build.make CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.s 346 | .PHONY : py_interface.cpp.s 347 | 348 | # Help Target 349 | help: 350 | @echo "The following are some of the valid targets for this Makefile:" 351 | @echo "... all (the default if no target is provided)" 352 | @echo "... clean" 353 | @echo "... depend" 354 | @echo "... edit_cache" 355 | @echo "... rebuild_cache" 356 | @echo "... vliang_chinese_chess" 357 | @echo "... cpp/source/alpha_beta.o" 358 | @echo "... cpp/source/alpha_beta.i" 359 | @echo "... cpp/source/alpha_beta.s" 360 | @echo "... cpp/source/chessboard.o" 361 | @echo "... cpp/source/chessboard.i" 362 | @echo "... cpp/source/chessboard.s" 363 | @echo "... cpp/source/evaluator.o" 364 | @echo "... cpp/source/evaluator.i" 365 | @echo "... cpp/source/evaluator.s" 366 | @echo "... cpp/source/mtdf.o" 367 | @echo "... cpp/source/mtdf.i" 368 | @echo "... cpp/source/mtdf.s" 369 | @echo "... cpp/source/quiescence.o" 370 | @echo "... cpp/source/quiescence.i" 371 | @echo "... cpp/source/quiescence.s" 372 | @echo "... cpp/source/tree_search.o" 373 | @echo "... cpp/source/tree_search.i" 374 | @echo "... cpp/source/tree_search.s" 375 | @echo "... evaluator_so.o" 376 | @echo "... evaluator_so.i" 377 | @echo "... evaluator_so.s" 378 | @echo "... main.o" 379 | @echo "... main.i" 380 | @echo "... main.s" 381 | @echo "... py_interface.o" 382 | @echo "... py_interface.i" 383 | @echo "... py_interface.s" 384 | .PHONY : help 385 | 386 | 387 | 388 | #============================================================================= 389 | # Special targets to cleanup operation of make. 390 | 391 | # Special rule to run CMake to check the build system integrity. 392 | # No rule that depends on this can have commands that come from listfiles 393 | # because they might be regenerated. 394 | cmake_check_build_system: 395 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 396 | .PHONY : cmake_check_build_system 397 | 398 | -------------------------------------------------------------------------------- /cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.23 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | #============================================================================= 8 | # Special targets provided by cmake. 9 | 10 | # Disable implicit rules so canonical targets will work. 11 | .SUFFIXES: 12 | 13 | # Disable VCS-based implicit rules. 14 | % : %,v 15 | 16 | # Disable VCS-based implicit rules. 17 | % : RCS/% 18 | 19 | # Disable VCS-based implicit rules. 20 | % : RCS/%,v 21 | 22 | # Disable VCS-based implicit rules. 23 | % : SCCS/s.% 24 | 25 | # Disable VCS-based implicit rules. 26 | % : s.% 27 | 28 | .SUFFIXES: .hpux_make_needs_suffix_list 29 | 30 | # Command-line flag to silence nested $(MAKE). 31 | $(VERBOSE)MAKESILENT = -s 32 | 33 | #Suppress display of executed commands. 34 | $(VERBOSE).SILENT: 35 | 36 | # A target that is always out of date. 37 | cmake_force: 38 | .PHONY : cmake_force 39 | 40 | #============================================================================= 41 | # Set environment variables for the build. 42 | 43 | # The shell in which to execute make rules. 44 | SHELL = /bin/sh 45 | 46 | # The CMake executable. 47 | CMAKE_COMMAND = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake 48 | 49 | # The command to remove a file. 50 | RM = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E rm -f 51 | 52 | # Escaping for special characters. 53 | EQUALS = = 54 | 55 | # The top-level source directory on which CMake was run. 56 | CMAKE_SOURCE_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp 57 | 58 | # The top-level build directory on which CMake was run. 59 | CMAKE_BINARY_DIR = /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release 60 | 61 | # Include any dependencies generated for this target. 62 | include CMakeFiles/vliang_chinese_chess.dir/depend.make 63 | # Include the progress variables for this target. 64 | include CMakeFiles/vliang_chinese_chess.dir/progress.make 65 | 66 | # Include the compile flags for this target's objects. 67 | include CMakeFiles/vliang_chinese_chess.dir/flags.make 68 | 69 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 70 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.o: ../main.cpp 71 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/main.cpp.o" 72 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/main.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/main.cpp 73 | 74 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.i: cmake_force 75 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/main.cpp.i" 76 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/main.cpp > CMakeFiles/vliang_chinese_chess.dir/main.cpp.i 77 | 78 | CMakeFiles/vliang_chinese_chess.dir/main.cpp.s: cmake_force 79 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/main.cpp.s" 80 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/main.cpp -o CMakeFiles/vliang_chinese_chess.dir/main.cpp.s 81 | 82 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 83 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o: ../cpp/source/chessboard.cpp 84 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o" 85 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/chessboard.cpp 86 | 87 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.i: cmake_force 88 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.i" 89 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/chessboard.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.i 90 | 91 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.s: cmake_force 92 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.s" 93 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/chessboard.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.s 94 | 95 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 96 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o: ../cpp/source/tree_search.cpp 97 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o" 98 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/tree_search.cpp 99 | 100 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.i: cmake_force 101 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.i" 102 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/tree_search.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.i 103 | 104 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.s: cmake_force 105 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.s" 106 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/tree_search.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.s 107 | 108 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 109 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o: ../cpp/source/alpha_beta.cpp 110 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_4) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o" 111 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/alpha_beta.cpp 112 | 113 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.i: cmake_force 114 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.i" 115 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/alpha_beta.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.i 116 | 117 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.s: cmake_force 118 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.s" 119 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/alpha_beta.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.s 120 | 121 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 122 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o: ../cpp/source/quiescence.cpp 123 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_5) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o" 124 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/quiescence.cpp 125 | 126 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.i: cmake_force 127 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.i" 128 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/quiescence.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.i 129 | 130 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.s: cmake_force 131 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.s" 132 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/quiescence.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.s 133 | 134 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 135 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o: ../cpp/source/evaluator.cpp 136 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_6) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o" 137 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/evaluator.cpp 138 | 139 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.i: cmake_force 140 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.i" 141 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/evaluator.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.i 142 | 143 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.s: cmake_force 144 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.s" 145 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/evaluator.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.s 146 | 147 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 148 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o: ../py_interface.cpp 149 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_7) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o" 150 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp 151 | 152 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.i: cmake_force 153 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.i" 154 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp > CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.i 155 | 156 | CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.s: cmake_force 157 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.s" 158 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/py_interface.cpp -o CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.s 159 | 160 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 161 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o: ../cpp/source/mtdf.cpp 162 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_8) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o" 163 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/mtdf.cpp 164 | 165 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.i: cmake_force 166 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.i" 167 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/mtdf.cpp > CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.i 168 | 169 | CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.s: cmake_force 170 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.s" 171 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/cpp/source/mtdf.cpp -o CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.s 172 | 173 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o: CMakeFiles/vliang_chinese_chess.dir/flags.make 174 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o: ../evaluator_so.cpp 175 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_9) "Building CXX object CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o" 176 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o -c /Users/zhangrui/Developer/vliang-chinesechess-cpp/evaluator_so.cpp 177 | 178 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.i: cmake_force 179 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.i" 180 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /Users/zhangrui/Developer/vliang-chinesechess-cpp/evaluator_so.cpp > CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.i 181 | 182 | CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.s: cmake_force 183 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.s" 184 | /Library/Developer/CommandLineTools/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /Users/zhangrui/Developer/vliang-chinesechess-cpp/evaluator_so.cpp -o CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.s 185 | 186 | # Object files for target vliang_chinese_chess 187 | vliang_chinese_chess_OBJECTS = \ 188 | "CMakeFiles/vliang_chinese_chess.dir/main.cpp.o" \ 189 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o" \ 190 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o" \ 191 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o" \ 192 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o" \ 193 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o" \ 194 | "CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o" \ 195 | "CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o" \ 196 | "CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o" 197 | 198 | # External object files for target vliang_chinese_chess 199 | vliang_chinese_chess_EXTERNAL_OBJECTS = 200 | 201 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/main.cpp.o 202 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/chessboard.cpp.o 203 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/tree_search.cpp.o 204 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/alpha_beta.cpp.o 205 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/quiescence.cpp.o 206 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/evaluator.cpp.o 207 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/py_interface.cpp.o 208 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/cpp/source/mtdf.cpp.o 209 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/evaluator_so.cpp.o 210 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/build.make 211 | vliang_chinese_chess: CMakeFiles/vliang_chinese_chess.dir/link.txt 212 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles --progress-num=$(CMAKE_PROGRESS_10) "Linking CXX executable vliang_chinese_chess" 213 | $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/vliang_chinese_chess.dir/link.txt --verbose=$(VERBOSE) 214 | 215 | # Rule to build all files generated by this target. 216 | CMakeFiles/vliang_chinese_chess.dir/build: vliang_chinese_chess 217 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/build 218 | 219 | CMakeFiles/vliang_chinese_chess.dir/clean: 220 | $(CMAKE_COMMAND) -P CMakeFiles/vliang_chinese_chess.dir/cmake_clean.cmake 221 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/clean 222 | 223 | CMakeFiles/vliang_chinese_chess.dir/depend: 224 | cd /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /Users/zhangrui/Developer/vliang-chinesechess-cpp /Users/zhangrui/Developer/vliang-chinesechess-cpp /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release /Users/zhangrui/Developer/vliang-chinesechess-cpp/cmake-build-release/CMakeFiles/vliang_chinese_chess.dir/DependInfo.cmake --color=$(COLOR) 225 | .PHONY : CMakeFiles/vliang_chinese_chess.dir/depend 226 | 227 | --------------------------------------------------------------------------------