Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

哦哦原来要pull requests 交第一次作业啦 #24

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Experiment/FiveInARow/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Experiment/FiveInARow/.idea/FiveInARow.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Experiment/FiveInARow/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Experiment/FiveInARow/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Experiment/FiveInARow/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Experiment/FiveInARow/Board/Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by mux on 2021-04-07.
//

#include "Board.h"
#include "../randomc/randomc.h"
#include <ctime>

#define RANDOM_MAX 1000

Board::Board(int current, char *name) {
this->m_name = name;
// this->m_map = map; 暂时不支持下残局
this->m_current_player = current;
// 初始化棋局
for (int row = 1; row < 16; ++row) {
for (int con = 1; con < 16; ++con) {
this->m_map[row][con].key = -1;
}
}

// 初始化Zobrist表
int seed = (int) time(nullptr); // 随机数生成种子
CRandomMersenne RanGen(seed);
for (int row = 1; row < 16; ++row) {
for (int con = 1; con < 16; ++con) {
this->m_map[row][con].Black_Zobrist = RanGen.IRandom(0, RANDOM_MAX);
this->m_map[row][con].White_Zobrist = RanGen.IRandom(0, RANDOM_MAX);
}
}
// 初始化Zobrist值
this->Current_Zobrist = RanGen.IRandom(0, RANDOM_MAX);
}



int Board::put_piece(int row, int con, int player) {
return 0;
}

48 changes: 48 additions & 0 deletions Experiment/FiveInARow/Board/Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Created by mux on 2021-04-07.
//
/**
* 这个文件中定义与棋局有关的东西。。。
*/
#include<vector>

using namespace std;
#ifndef FIVEINAROW_BOARD_H
#define FIVEINAROW_BOARD_H

typedef struct {// 棋盘上的一个点
int row;
int con;
int key; // 点上的棋子状态
int White_Zobrist;
int Black_Zobrist;
} Point;


enum Player { // 人0 系统1
user, system
};

class Board {
public: // 公共变量定义
char *m_name; // 玩家姓名 unused
Point m_map[16][16]; // 地图数组指针 二维数组 大小:15*15 会多出来一行一列的数据
int m_current_player; // 记录现在是谁在操作
vector<Point> m_user_operations; // 记录用户操作的向量 <[row,con]>
vector<Point> m_sys_operations; // 记录系统操作的向量 <[row,con]>
int Current_Zobrist; // 记录现在的Zobrist值
public: // 公共方法声明
Board(int current, char *name = nullptr); // 构造方法
/**
* 下棋操作
* @param row
* @param con
* @param player
* @return
*/
int put_piece(int row, int con, int player);
//TODO:悔棋
};


#endif //FIVEINAROW_BOARD_H
7 changes: 7 additions & 0 deletions Experiment/FiveInARow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.17)
project(FiveInARow)

set(CMAKE_CXX_STANDARD 14)

add_executable(FiveInARow
main.cpp Board/Board.cpp Board/Board.h Game/Game.cpp Game/Game.h Interaction/Console.cpp Interaction/Console.h)
5 changes: 5 additions & 0 deletions Experiment/FiveInARow/Game/Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by mux on 2021-04-07.
//

#include "Game.h"
39 changes: 39 additions & 0 deletions Experiment/FiveInARow/Game/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Created by mux on 2021-04-07.
//
#ifndef FIVEINAROW_GAME_H
#define FIVEINAROW_GAME_H
#include "../Board/Board.h"
#include <vector>
/**
* 寻找可能的可以落子的点,去除明显不需要思考的点 即在这一层可能的落子位置
* 其实是决策树的每一层
* @param board
* @return
*/
vector<Point>* find_possible_solutions(Board *board);

/**
* 估计AI胜利概率(全局)
* @param board
* @return 0~1的float
*/
float estimate_winning_possibility_to_system(Board *board);

/**
* 计算一个落子操作的得分(针对一个点)
* @param board
* @param point
* @return
*/
int score_of_a_point(Board *board,Point point);

/**
* 寻找此时AI赢面最大的地儿
* @param board
* @return
*/
Point find_best_point(Board *board);


#endif //FIVEINAROW_GAME_H
5 changes: 5 additions & 0 deletions Experiment/FiveInARow/Interaction/Console.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by mux on 2021-04-07.
//

#include "Console.h"
16 changes: 16 additions & 0 deletions Experiment/FiveInARow/Interaction/Console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by mux on 2021-04-07.
//

#ifndef FIVEINAROW_CONSOLE_H
#define FIVEINAROW_CONSOLE_H

#include "../Board/Board.h"

void Print_Board_to_Console();

int Input_parser(int row,int con);



#endif //FIVEINAROW_CONSOLE_H
Loading