#include "chessAI.h"
#include <stdio.h>
//USING_NS_CC;
chessAI::chessAI()
{
InitData();
InitWeight();
}
void chessAI::clear()
{
InitData();
InitWeight();
}
void chessAI::setChessData(int x, int y, ChessType_t chessType)
{
if (m_chessData[x][y] == ChessType_t::None && chessType != ChessType_t::None)
{
m_chessNum = m_chessNum + 1;
}
if (m_chessData[x][y] != ChessType_t::None && chessType == ChessType_t::None)
{
m_chessNum = m_chessNum - 1;
}
m_chessData[x][y] = chessType;
if (chessType != ChessType_t::None)
{
last_x2 = last_x;
last_y2 = last_y;
last_x = x;
last_y = y;
}
}
ChessType_t chessAI::getChessData(int x, int y)
{
return m_chessData[x][y];
}
int chessAI::getChessNum()
{
return m_chessNum;
}
bool chessAI::getPointVectorWin(int x, int y, ChessType_t chess_type, VectorType_t vector_type)
{
int num = 0;
for (int i = 1; i < SIX; i++)
{
if (vector_type == VectorType_t::Across)
{
if (m_chessData[x + i][y] == chess_type && (x + i) < GRID_NUM)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Vertical)
{
if (m_chessData[x][y + i] == chess_type && (y + i) < GRID_NUM)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Slant_Negative)
{
if (m_chessData[x + i][y - i] == chess_type && (x + i) < GRID_NUM && (y - i) >= 0)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Slant_Positive)
{
if (m_chessData[x + i][y + i] == chess_type && (x + i) < GRID_NUM && (y + i) < GRID_NUM)
{
num = num + 1;
continue;
}
break;
}
}
for (int i = 1; i < SIX; i++)
{
if (vector_type == VectorType_t::Across)
{
if (m_chessData[x - i][y] == chess_type && (x - i) >= 0)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Vertical)
{
if (m_chessData[x][y - i] == chess_type && (y - i) >= 0)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Slant_Negative)
{
if (m_chessData[x - i][y + i] == chess_type && (x - i) >= 0 && (y + i) < GRID_NUM)
{
num = num + 1;
continue;
}
break;
}
if (vector_type == VectorType_t::Slant_Positive)
{
if (m_chessData[x - i][y - i] == chess_type && (x - i) >= 0 && (y - i) >= 0)
{
num = num + 1;
continue;
}
break;
}
}
if (num >= 5)
{
return true;
}
else
{
return false;
}
}
void chessAI::InitData()
{
for (int i = 0; i < GRID_NUM; i++)
{
for (int j = 0; j < GRID_NUM; j++)
{
m_chessData[i][j] = ChessType_t::None;
//m_weightWhite[i][j] = 0;
//m_weightBlack[i][j] = 0;
}
}
m_chessNum = 0;
last_x = -1;
last_y = -1;
}
void chessAI::InitWeight()
{
for (int i = 0; i < GRID_NUM; i++)
{
for (int j = 0; j < GRID_NUM; j++)
{
//m_chessData[i][j] = ChessType_t::None;
m_weightWhite[i][j] = 0;
m_weightBlack[i][j] = 0;
}
}
}
bool chessAI::getOneInfo(const ChessType_t data, const ChessType_t chess_type, const int i, int& link_num, int& empty_num, int& end_num)
{
if (data == chess_type)
{
link_num = link_num + 1;
}
else if (data == ChessType_t::None)
{
if (empty_num == 0)
{
empty_num = i;
}
else
{
end_num = i;
return true;
}
}
else
{
return true;
}
return false;
}
void chessAI::addWeight(int x, int y, ChessType_t chess_type, int score)
{
if (chess_type == ChessType_t::White)
{
m_weightWhite[x][y] = m_weightWhite[x][y] + score;
}
if (chess_type == ChessType_t::Black)
{
m_weightBlack[x][y] = m_weightBlack[x][y] + score;
}
}
void chessAI::getWeight(int x, int y, ChessType_t chess_type,
int link_num1, int empty_num1, int end_num1,
int link_num2, int empty_num2, int end_num2)
{
bool Left = false, Right = false;
if (end_num1 == 0 && end_num2 == 0)
{
int m = 0;
if (empty_num1 != 0)
{
m = m + 1;
}
if (empty_num2 != 0)
{
m = m + 1;
}
if (link_num1 + link_num2 + m < FIVE)
{
return ;
}
}
/*****************************************************************/
if (link_num1 >= FIVE && (empty_num1 > FIVE ))
{
addWeight(x, y, chess_type, RUSH_FIVE);
Left = true;
}
if (link_num2 >= FOUR && (empty_num2 > FOUR))
{
addWeight(x, y, chess_type, RUSH_FIVE);
Right = true;
}
if (link_num1 >= FOUR && (empty_num1 > FOUR || empty_num1 > 0))
{
addWeight(x, y, chess_type, LIVE_FOUR);
Left = true;
}
if (link_num2 >= FOUR && (empty_num2 > FOUR || empty_num2 > 0))
{
addWeight(x, y, chess_type, LIVE_FOUR);
Right = true;
}
if (link_num1 >= FOUR && (empty_num1 > FOUR || empty_num1 == 0))
{
addWeight(x, y, chess_type, RUSH_FOUR);
Left = true;
}
if (link_num2 >= FOUR && (empty_num2 > FOUR || empty_num2 == 0))
{
addWeight(x, y, chess_type, RUSH_FOUR);
Right = true;
}
if (link_num1 < FOUR && link_num2 < FOUR && link_num1 + link_num2 >= FOUR)
{
if (empty_num1 == 0 && empty_num2 == 0)
{
if (link_num1 + link_num2 >= FOUR)
{
addWeight(x, y, chess_type, RUSH_FOUR);
return;
}
}
if (empty_num1 != 0 && empty_num2 == 0)
{
if (empty_num1 + link_num2 >= FOUR)
{
addWeight(x, y, chess_type, RUSH_FOUR);
return;
}
}
if (empty_num1 == 0 && empty_num2 != 0)
{
if (link_num1 + empty_num2 >= FOUR)
{
addWeight(x, y, chess_type, RUSH_FOUR);
return;
}
}
if (empty_num1 != 0 && empty_num2 != 0)
{
if (empty_num1 + empty_num2 >= FOUR)
{
addWeight(x, y, chess_type, RUSH_FOUR);
return;
}
}
}
/*****************************************************************/
if (link_num1 == THREE && !Left)
{
if (empty_num2 == 1 && empty_num1 > link_num1)
{
addWeight(x, y, chess_type, LIVE_THREE);
}
else
{
addWeight(x, y, chess_type, RUSH_THREE);
}
Left = true;
}
if (link_num2 == THREE && !Right)
{
if (empty_num1 == 1 && empty_num2 > link_num2)
{
addWeight(x, y, chess_type, LIVE_THREE);
}
else
{
addWeight(x, y, chess_type, RUSH_THREE);
}
Right = true;
}
if (link_num1 > 0 && link_num2 > 0 && link_num1 + link_num2 == THREE)
{
if (empty_num1 > link_num1 && empty_num2 > link_num2)
{
addWeight(x, y, chess_type, LIVE_THREE);
return;
}
if (!(empty_num1 <= link_num1 && empty_num2 <= link_num2))
{
addWeight(x, y, chess_type, RUSH_THREE);
return;
}
}
/*****************************************************************/
if (link_num1 == TWO && !Left)
{
if (empty_num2 == 1)
{
if (empty_num1 > link_num1)
{
addWeight(x, y, chess_type, LIVE_TWO);
Left = true;
}
else if (empty_num1 > 0 && end_num1 >= link_num1 + 2)
{
addWeight(x, y, chess_type, LIVE_TWO);
Left = true;
}
else
{
addWeight(x, y, chess_type, RUSH_TWO);
Left = true;
}
}
else
{
addWeight(x, y, chess_type,RUSH_TWO);
Left = true;
}
}
/*
else
{
addWeight(x, y, chess_type, RUSH_TWO);
Left = true;
}*/
if (link_num2 == TWO && !Right)
{
if (empty_num1 == 1)
{
if (empty_num2 > link_num2)
{
addWeight(x, y, chess_type, LIVE_TWO);
Right = true;
}
else if (empty_num2 > 0 && end_num2 >= link_num2 + 2)
{
addWeight(x, y, chess_type, LIVE_TWO);
Right = true;
}
else
{
addWeight(x, y, chess_type, RUSH_TWO);
Right = true;
}
}
else
{
addWeight(x, y, chess_type, RUSH_TWO);
Right = true;
}
}
/*
else
{
addWeight(x, y, chess_type, RUSH_TWO);
Right = true;
}
*/
if (link_num1 == 1 && link_num2 == 1)
{
/*
if (empty_num1 == 2 && empty_num2 >= link_num2)
{
addWeight(x, y, chess_type, LIVE_TWO);
return;
没有合适的资源?快使用搜索试试~ 我知道了~
sixcode.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共5个文件
h:3个
cpp:2个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 22 浏览量
2024-05-13
22:33:51
上传
评论
收藏 8KB ZIP 举报
温馨提示
sixcode.zip
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 5 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
qq_34269519
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)