refactor: 清理成三表和着法表等无用的逻辑

This commit is contained in:
CalciteM 2019-09-08 23:58:26 +08:00
parent fa531d5926
commit 3d1022f292
8 changed files with 101 additions and 155 deletions

View File

@ -56,9 +56,6 @@
//#define MILL_FIRST
#define CONST_MOVE_TABLE
#define CONST_MILL_TABLE
//#define DEAL_WITH_HORIZON_EFFECT
#define IDS_SUPPORT

View File

@ -467,7 +467,6 @@
<QtMoc Include="src\ui\qt\server.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\Readme.md" />
<None Include="include\version.h.template" />
<None Include="millgame.pro" />
<None Include="Resources\icon\ActualSizeHS.png">
@ -689,11 +688,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="..\History.txt" />
<Text Include="..\Licence.txt" />
<Text Include="..\Sample.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ai\evaluate.cpp" />
<ClCompile Include="src\ai\movegen.cpp" />

View File

@ -37,9 +37,6 @@
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Text Files">
<UniqueIdentifier>{d3810898-e5d4-49ce-92da-beddffba0697}</UniqueIdentifier>
</Filter>
<Filter Include="Project Files">
<UniqueIdentifier>{16c52ca8-0391-4ad2-919c-4a865ad87e98}</UniqueIdentifier>
</Filter>
@ -229,9 +226,6 @@
<None Include="Resources\image\white_piece.png">
<Filter>Resource Files</Filter>
</None>
<None Include="..\Readme.md">
<Filter>Text Files</Filter>
</None>
<None Include="include\version.h.template">
<Filter>Header Files</Filter>
</None>
@ -242,17 +236,6 @@
<Filter>base</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="..\History.txt">
<Filter>Text Files</Filter>
</Text>
<Text Include="..\Licence.txt">
<Filter>Text Files</Filter>
</Text>
<Text Include="..\Sample.txt">
<Filter>Text Files</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\ui\qt\gamecontroller.h">
<Filter>ui</Filter>

View File

@ -1,4 +1,25 @@
#include "evaluate.h"
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "evaluate.h"
value_t Evaluation::getValue(MillGame &gameTemp, GameContext *gameContext, MillGameAi_ab::Node *node)
{

View File

@ -1,3 +1,24 @@
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef EVALUATE_H
#define EVALUATE_H
@ -15,7 +36,7 @@ public:
static value_t getValue(MillGame &gameTemp, GameContext *gameContext, MillGameAi_ab::Node *node);
// 팀뮌綾제
// 评估子力
#ifdef EVALUATE_ENABLE
#ifdef EVALUATE_MATERIAL

View File

@ -1,4 +1,25 @@
#include <random>
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <random>
#include "movegen.h"
@ -145,7 +166,6 @@ void MoveList::generateLegalMoves(MillGameAi_ab &ai_ab, MillGame &gameTemp,
void MoveList::createMoveTable(MillGame &game)
{
#ifdef CONST_MOVE_TABLE
#if 1
const int moveTable_obliqueLine[Board::N_POINTS][N_MOVE_DIRECTIONS] = {
/* 0 */ {0, 0, 0, 0},
@ -342,46 +362,9 @@ void MoveList::createMoveTable(MillGame &game)
memcpy(moveTable, moveTable_noObliqueLine, sizeof(moveTable));
}
#else /* CONST_MOVE_TABLE */
for (int r = 1; r <= N_RINGS; r++) {
for (int s = 0; s < N_SEATS; s++) {
int p = r * N_SEATS + s;
// 顺时针走一步的位置
moveTable[p][MOVE_DIRECTION_CLOCKWISE] = r * N_SEATS + (s + 1) % N_SEATS;
// 逆时针走一步的位置
moveTable[p][MOVE_DIRECTION_ANTICLOCKWISE] = r * N_SEATS + (s + N_SEATS - 1) % N_SEATS;
// 如果是 0、2、4、6位偶数位或是有斜线
if (!(s & 1) || this->currentRule.hasObliqueLines) {
if (r > 1) {
// 向内走一步的位置
moveTable[p][MOVE_DIRECTION_INWARD] = (r - 1) * N_SEATS + s;
}
if (r < N_RINGS) {
// 向外走一步的位置
moveTable[p][MOVE_DIRECTION_OUTWARD] = (r + 1) * N_SEATS + s;
}
}
#if 0
// 对于无斜线情况下的1、3、5、7位奇数位则都设为棋盘外点默认'\x00'
else {
// 向内走一步的位置设为随便棋盘外一点
moveTable[i * SEAT + j][2] = '\x00';
// 向外走一步的位置设为随便棋盘外一点
moveTable[i * SEAT + j][3] = '\x00';
}
#endif
}
}
#endif /* CONST_MOVE_TABLE */
#if 0
#ifdef DEBUG_MODE
int sum = 0;
for (int i = 0; i < N_POINTS; i++) {
for (int i = 0; i < Board::N_POINTS; i++) {
loggerDebug("/* %d */ {", i);
for (int j = 0; j < N_MOVE_DIRECTIONS; j++) {
if (j == N_MOVE_DIRECTIONS - 1)
@ -392,7 +375,7 @@ void MoveList::createMoveTable(MillGame &game)
}
loggerDebug("},\n");
}
loggerDebug("sum = %d\n");
loggerDebug("sum = %d\n", sum);
#endif
}

View File

@ -1,4 +1,25 @@
#ifndef MOVEGEN_H
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef MOVEGEN_H
#define MOVEGEN_H
#include "config.h"

View File

@ -67,7 +67,6 @@ Board &Board::operator= (const Board &other)
void Board::createMillTable(const Rule &currentRule)
{
#ifdef CONST_MILL_TABLE
const int millTable_noObliqueLine[Board::N_POINTS][Board::N_DIRECTIONS][2] = {
/* 0 */ {{0, 0}, {0, 0}, {0, 0}},
/* 1 */ {{0, 0}, {0, 0}, {0, 0}},
@ -167,103 +166,30 @@ void Board::createMillTable(const Rule &currentRule)
} else {
memcpy(millTable, millTable_noObliqueLine, sizeof(millTable));
}
#else /* CONST_MILL_TABLE */
for (int i = 0; i < N_SEATS; i++) {
// 内外方向的“成三”
// 如果是0、2、4、6位偶数位或是有斜线
if (!(i & 1) || this->currentRule.hasObliqueLines) {
millTable[1 * N_SEATS + i][0][0] = 2 * N_SEATS + i;
millTable[1 * N_SEATS + i][0][1] = 3 * N_SEATS + i;
millTable[2 * N_SEATS + i][0][0] = 1 * N_SEATS + i;
millTable[2 * N_SEATS + i][0][1] = 3 * N_SEATS + i;
millTable[3 * N_SEATS + i][0][0] = 1 * N_SEATS + i;
millTable[3 * N_SEATS + i][0][1] = 2 * N_SEATS + i;
}
// 对于无斜线情况下的1、3、5、7位奇数位
else {
// 置空该组“成三”
millTable[1 * N_SEATS + i][0][0] = 0;
millTable[1 * N_SEATS + i][0][1] = 0;
millTable[2 * N_SEATS + i][0][0] = 0;
millTable[2 * N_SEATS + i][0][1] = 0;
millTable[3 * N_SEATS + i][0][0] = 0;
millTable[3 * N_SEATS + i][0][1] = 0;
}
// 当前圈上的“成三”
// 如果是0、2、4、6位
if (!(i & 1)) {
millTable[1 * N_SEATS + i][1][0] = 1 * N_SEATS + (i + 1) % N_SEATS;
millTable[1 * N_SEATS + i][1][1] = 1 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
millTable[2 * N_SEATS + i][1][0] = 2 * N_SEATS + (i + 1) % N_SEATS;
millTable[2 * N_SEATS + i][1][1] = 2 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
millTable[3 * N_SEATS + i][1][0] = 3 * N_SEATS + (i + 1) % N_SEATS;
millTable[3 * N_SEATS + i][1][1] = 3 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
// 置空另一组“成三”
millTable[1 * N_SEATS + i][2][0] = 0;
millTable[1 * N_SEATS + i][2][1] = 0;
millTable[2 * N_SEATS + i][2][0] = 0;
millTable[2 * N_SEATS + i][2][1] = 0;
millTable[3 * N_SEATS + i][2][0] = 0;
millTable[3 * N_SEATS + i][2][1] = 0;
}
// 对于1、3、5、7位奇数位
else {
// 当前圈上逆时针的“成三”
millTable[1 * N_SEATS + i][1][0] = 1 * N_SEATS + (i + N_SEATS - 2) % N_SEATS;
millTable[1 * N_SEATS + i][1][1] = 1 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
millTable[2 * N_SEATS + i][1][0] = 2 * N_SEATS + (i + N_SEATS - 2) % N_SEATS;
millTable[2 * N_SEATS + i][1][1] = 2 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
millTable[3 * N_SEATS + i][1][0] = 3 * N_SEATS + (i + N_SEATS - 2) % N_SEATS;
millTable[3 * N_SEATS + i][1][1] = 3 * N_SEATS + (i + N_SEATS - 1) % N_SEATS;
// 当前圈上顺时针的“成三”
millTable[1 * N_SEATS + i][2][0] = 1 * N_SEATS + (i + 1) % N_SEATS;
millTable[1 * N_SEATS + i][2][1] = 1 * N_SEATS + (i + 2) % N_SEATS;
millTable[2 * N_SEATS + i][2][0] = 2 * N_SEATS + (i + 1) % N_SEATS;
millTable[2 * N_SEATS + i][2][1] = 2 * N_SEATS + (i + 2) % N_SEATS;
millTable[3 * N_SEATS + i][2][0] = 3 * N_SEATS + (i + 1) % N_SEATS;
millTable[3 * N_SEATS + i][2][1] = 3 * N_SEATS + (i + 2) % N_SEATS;
}
}
#endif /* CONST_MILL_TABLE */
#if 0
#ifdef DEBUG_MODE
for (int i = 0; i < N_POINTS; i++) {
printf("/* %d */ {", i);
loggerDebug("/* %d */ {", i);
for (int j = 0; j < N_DIRECTIONS; j++) {
printf("{");
loggerDebug("{");
for (int k = 0; k < 2; k++) {
if (k == 0) {
printf("%d, ", millTable[i][j][k]);
loggerDebug("%d, ", millTable[i][j][k]);
} else {
printf("%d", millTable[i][j][k]);
loggerDebug("%d", millTable[i][j][k]);
}
}
if (j == 2)
printf("}");
loggerDebug("}");
else
printf("}, ");
loggerDebug("}, ");
}
printf("},\n");
loggerDebug("},\n");
}
printf("======== millTable End =========\n");
#endif
loggerDebug("======== millTable End =========\n");
#endif /* DEBUG_MODE */
}
void Board::pos2rs(const int pos, int &r, int &s)