📄 connect6.cpp
字号:
if(newMove.StonePos[0].x+newMove.StonePos[0].y > 18 && newMove.StonePos[0].x < newMove.StonePos[0].y)
{
m_cmBestMove.StonePos[0].x = 9-1;
m_cmBestMove.StonePos[0].y = 9-1;
m_cmBestMove.StonePos[1].x = 9+1;
m_cmBestMove.StonePos[1].y = 9-1;
}
if(newMove.StonePos[0].x+newMove.StonePos[0].y<=18 && newMove.StonePos[0].x < newMove.StonePos[0].y)
{
m_cmBestMove.StonePos[0].x = 9 + 1;
m_cmBestMove.StonePos[0].y = 9-1;
m_cmBestMove.StonePos[1].x = 9+1;
m_cmBestMove.StonePos[1].y = 9+1;
}
if(newMove.StonePos[0].x+newMove.StonePos[0].y>18 && newMove.StonePos[0].x >= newMove.StonePos[0].y)
{
m_cmBestMove.StonePos[0].x = 9 - 1;
m_cmBestMove.StonePos[0].y = 9 - 1;
m_cmBestMove.StonePos[1].x = 9-1;
m_cmBestMove.StonePos[1].y = 9 +1;
}
FirststepFlag = 0;
position[m_cmBestMove.StonePos[0].x][m_cmBestMove.StonePos[0].y] = myStr.KnowType();
position[m_cmBestMove.StonePos[1].x][m_cmBestMove.StonePos[1].y] = myStr.KnowType();
myStr.UpDate(myList, m_cmBestMove );
adverStr.UpDate(adverList,m_cmBestMove);
return true;
}
}
//找五,如果在棋盘上找到我方的五的话,则填入一颗子,另一颗子随便放,获胜
myStr.SearchFive(searchResult,count);
if(count>0)
{
id = searchResult[0];
myList.GetCoor(id,strxy);
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1)
i++;
m_cmBestMove.StonePos[0].x = strxy[i][0];
m_cmBestMove.StonePos[0].y = strxy[i][1];
for(i = 0; i < 19; i++)
for(j = 0; j < 19; j++)
if(position[i][j] == -1)
{
m_cmBestMove.StonePos[1].x = i;
m_cmBestMove.StonePos[1].y = j;
}
return true;
}
//找四,如果在棋盘上找到我方的四的话,填入我方的两颗子,获胜
myStr.SearchFour(searchResult,count);
if(count>0)
{
id = searchResult[0];
myList.GetCoor(id,strxy);
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //找到第一个空位置
i++;
m_cmBestMove.StonePos[0].x = strxy[i][0]; //确定在第一个空位置放入一个子
m_cmBestMove.StonePos[0].y = strxy[i][1];
i++; //从第一个空位置的下一个位置开始找
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //找到第二个空位置
i++;
m_cmBestMove.StonePos[1].x = strxy[i][0];
m_cmBestMove.StonePos[1].y = strxy[i][1];
return true;
}
//目前没有能够必杀的棋,考虑防守了,更新敌人和自己的活棋表
int order = 1;
put1 = put2 = false; //两颗子都标记为没放入
adverStr.SearchFive(searchResult,count);//找敌人的五线
if(count>0) //敌人存在5线,我们被迫防守。守点唯一
{
id = searchResult[0];
adverList.GetCoor(id,strxy);
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1)
i++;
m_cmBestMove.StonePos[0].x = strxy[i][0];
m_cmBestMove.StonePos[0].y = strxy[i][1];
put1 = true; //标记第一颗棋子的状态
}
//在在棋盘上找到敌人的四,然后选择一个对我们权值较高的位置,堵之
if( !put1)
{
adverStr.SearchFour(searchResult,countFor);
if(countFor>0)
{
Initialize_value();
id = searchResult[0]; //第一个四的id编号
adverList.GetCoor(id,strxy); //获取这id对应的六个点的坐标
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //找到第一个空位置
i++;
atemPos1.x = strxy[i][0];
atemPos1.y = strxy[i][1]; //试探性的放入一个子在第一个空位
Value(atemPos1, myInc, adverDec, myList, adverList, myStr, adverStr); //试探性的放入一个子后, 获得第一个试探性走法的权值
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0; k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
i++;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //继续找第二个空位置
i++;
atemPos2.x = strxy[i][0]; //试探性的把子放入第二个空置位上
atemPos2.y = strxy[i][1];
Value(atemPos2, myInc, adverDec, myList, adverList, myStr, adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0; k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos2;
}
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
if(!put1) //如果第一颗子还没放下(对手没有四)
{ //在我们的棋盘上找活三,或者三的交点且具有另外的一个三
myStr.SearchThree(searchResult,countFor);
if( countFor>= 3)
{
Initialize_value();
for(i=0; i<countFor; i++) //循环找所有的空位置,从中找最好的
{
id = searchResult[i];
myList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1) //找到一个空位置
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if( best_myInc[3] >= 2 && countFor >= 3 ){
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在自己的棋盘上找活二
myStr.SearchTwo(searchResult,countFor);
if( countFor>= 3 )
{
Initialize_value();
for(i=0; i<countFor; i++) //循环找所有的空位置,从中找最好的
{
id = searchResult[i];
myList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1) //找到一个空位置
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1, myInc, adverDec, myList, adverList, myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if (best_myInc[2] >= 3)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在对手的棋盘上找三的交点,兼间接杀棋
adverStr.SearchThree(searchResult,countFor);
if(countFor>=3)
{
Initialize_value();
for(i=0; i<countFor; i++)
{
id = searchResult[i];
adverList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1)
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1, myInc, adverDec, myList, adverList, myStr, adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if (best_adverDec[2] >= 2 && countFor >= 3 )
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在自己的棋盘上找活一
myStr.SearchOne(searchResult,countFor);
if(countFor>=3)
{
Initialize_value();
for(i=0; i<countFor; i++) //循环找所有的空位置,从中找最好的
{
id = searchResult[i];
myList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1) //找到一个空位置
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if(best_myInc[1] >= 3){
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在对方的棋盘上找活二
adverStr.SearchTwo(searchResult,countFor);
if(countFor>=2)
{
Initialize_value();
for(i=0; i<countFor; i++)
{
id = searchResult[i];
adverList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1)
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if (best_adverDec[1] >= 2)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1) //如果第一颗子还没放下(对手没有四)
{
//在我们的棋盘上找三的交点
myStr.SearchThree(searchResult,countFor);
if(countFor>=2)
{
Initialize_value();
for(i=0; i<countFor; i++) //循环找所有的空位置,从中找最好的
{
id = searchResult[i];
myList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1) //找到一个空位置
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if(best_myInc[3] >= 2)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在对手的棋盘上两个三的交点
adverStr.SearchThree(searchResult,countFor);
if(countFor>=2)
{
Initialize_value();
for(i=0; i<countFor; i++)
{
id = searchResult[i];
adverList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1)
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1, myInc, adverDec, myList, adverList, myStr, adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if(best_adverDec[2] >= 2)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在自己的棋盘上找二的交点
myStr.SearchTwo(searchResult,countFor);
if(countFor>=2)
{
Initialize_value();
for(i=0; i<countFor; i++) //循环找所有的空位置,从中找最好的
{
id = searchResult[i];
myList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1) //找到一个空位置
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1, myInc, adverDec, myList, adverList, myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if (best_myInc[2] >= 2)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1)
{
//在对方的棋盘上找二的交点
adverStr.SearchTwo(searchResult,countFor);
if(countFor>=2)
{
Initialize_value();
for(i=0; i<countFor; i++)
{
id = searchResult[i];
adverList.GetCoor(id,strxy);
for(j = 0; j < 6; j++)
if(position[strxy[j][0]][strxy[j][1]] == -1)
{
atemPos1.x = strxy[j][0];
atemPos1.y = strxy[j][1];
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
}
}
if (best_adverDec[1] >= 2)
{
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
}
}
if(!put1){ //缺省情况,找最优空位落子
bestWeight = -1;
for (i = 0; i < 19; i++){
for (j = 0; j < 19; j++){
if (position[i][j] == -1)
{
position[i][j] = myStr.KnowType();
myStr.SearchOne(searchResult,countFor);
if (countFor > bestWeight)
{
bestWeight = countFor;
bestAtem.x = i;
bestAtem.y = j;
}
position[i][j] = NOSTONE; //还原
myStr.UpDate(adverList,bestAtem);
}
}
}
m_cmBestMove.StonePos[0] = bestAtem;
put1 = true;
}
//第一颗子要放的位置已经找出来,放下了,下面要找第二颗子要放下的位置
//但是在这时,应该把棋盘更新,并且双方的活棋表应该先更新
position[m_cmBestMove.StonePos[0].x][m_cmBestMove.StonePos[0].y] = myStr.KnowType();
myStr.UpDate(myList,m_cmBestMove.StonePos[0]);
adverStr.UpDate(adverList,m_cmBestMove.StonePos[0]);
//开始找第二个子的位置
order = 2;
adverStr.SearchFive(searchResult,count);//找敌人的五
if(count>0)
{
id = searchResult[0];
adverList.GetCoor(id,strxy);
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1)
i++;
m_cmBestMove.StonePos[1].x = strxy[i][0];
m_cmBestMove.StonePos[1].y = strxy[i][1];
put2 = true;
}
//在在棋盘上找到敌人的四,然后选择一个对我们权值较高的位置,堵之
if( !put2 )
{
adverStr.SearchFour(searchResult,countFor); //记录下本来有几个四
if(countFor>0)
{
Initialize_value();
id = searchResult[0]; //第一个四的id编号
adverList.GetCoor(id,strxy); //获取这id对应的六个点的坐标
i=0;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //找到第一个空位置
i++;
atemPos1.x = strxy[i][0];
atemPos1.y = strxy[i][1]; //试探性的放入一个子在第一个空位
Value(atemPos1,myInc, adverDec,myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
best_adverDec[k] = adverDec[k];
}
bestAtem = atemPos1;
}
i++;
while(i<6 && position[strxy[i][0]][strxy[i][1]] != -1) //继续找第二个空位置
i++;
atemPos2.x = strxy[i][0]; //试探性的把子放入第二个空置位上
atemPos2.y = strxy[i][1];
Value(atemPos2, myInc, adverDec, myList,adverList,myStr,adverStr);
if (Judge(myInc, adverDec, order) == true)
{
for (int k = 0;k < 6; k++)
{
best_myInc[k] = myInc[k];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -