Skip to content

Commit 89afd22

Browse files
author
guokla
committed
first commit
0 parents  commit 89afd22

9 files changed

+2859
-0
lines changed

chessboard.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "widget.h"
2+

chessboard.h

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndef CHESSBOARD_H
2+
#define CHESSBOARD_H
3+
4+
#include "include.h"
5+
6+
struct Pos{
7+
int x, y, val;
8+
};
9+
10+
class ChessBoard
11+
{
12+
public:
13+
// 常量定义
14+
const int BLACK = 1;
15+
const int WHITE = 2;
16+
int size = 15;
17+
const int Kernel = 2;
18+
19+
const int R_INF = 1000;
20+
const int HASH_EXACT = 1;
21+
const int HASH_ALPHA = 2;
22+
const int HASH_BETA = 3;
23+
uint64_t HASH_TABLE_SIZE = 20;
24+
const int FLAGS_CONDESE = 1;
25+
const int FLAGS_RELEASE = 2;
26+
27+
// 眠二,眠三,活二,跳活三,直活三,冲四
28+
// 双活三,冲四活三,双冲四(活四),五连
29+
int CHESS_VALUE[10]={1,2,3,3,5,5,50,80,120,200};
30+
int CHESS_PRIOR[4]={1,2,100,10000};
31+
32+
// 方向矢量
33+
const int vx[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
34+
const int vy[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
35+
36+
int chess[20][20]; // 棋盘数组
37+
uint64_t Z[3][20][20]; // 散列表
38+
uint64_t hash = 0; // 散列哈希值
39+
int vis[20][20]; // 棋子能量分布
40+
int hold = 1; // 当前走棋方
41+
int order = 0; // 棋子数量
42+
bool runing = false; // 运算状态
43+
QVector<Pos> path; // 走棋路径
44+
45+
public:
46+
ChessBoard(); // 私有构造函数
47+
ChessBoard(ChessBoard &obj);
48+
ChessBoard& operator=(const ChessBoard&);
49+
static ChessBoard* pChess;
50+
static QMutex m_hash; // 读写锁
51+
static QMutex m_move; // 落子锁
52+
53+
public:
54+
~ChessBoard();
55+
// 单例模式
56+
static ChessBoard *_getInstance();
57+
58+
// 常用函数
59+
bool _makeMove(int x, int y);
60+
bool _reMakeMove();
61+
62+
// 越界判断函数
63+
bool inline _inside(int x, int y);
64+
65+
// 局面计算函数
66+
int _valueChess(int x, int y, int key, int &piority);
67+
int _evaluate(int key);
68+
void _powerOperation(int x, int y, int flag, int key);
69+
70+
// 哈希表操作
71+
uint64_t _rand64();
72+
bool _lookup(int depth, int alpha, int beta, Pos& ret);
73+
bool _store(int hashf, long long hashIndex, const Pos ret, int deep);
74+
};
75+
76+
ChessBoard* ChessBoard::pChess = nullptr;
77+
QMutex ChessBoard::m_hash; // 读写锁
78+
QMutex ChessBoard::m_move; // 落子锁
79+
80+
#endif // CHESSBOARD_H

main.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "widget.h"
2+
#include <iostream>
3+
#include <QApplication>
4+
5+
int main(int argc, char *argv[])
6+
{
7+
QApplication a(argc, argv);
8+
9+
Widget w;
10+
w.show();
11+
12+
return a.exec();
13+
}

readme.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello, welcome to this repostory.
2+
3+
Sometimes I will try interesting ideas, like "why I am not use nerual network to improve my algoritm?".
4+
5+
The version is designed for this idea.

renju_py.pro

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2020-04-19T15:41:03
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = renju_py
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
SOURCES += \
26+
main.cpp \
27+
widget.cpp
28+
29+
HEADERS += \
30+
widget.h
31+
32+
FORMS += \
33+
widget.ui

renju_py.pro.user

+1,299
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)