小编dyl*_*unn的帖子

国际象棋:Alpha-Beta中的错误

我正在实现一个国际象棋引擎,我已经编写了一个相当复杂的alpha-beta搜索例程,具有静止搜索和转置表.但是,我正在观察一个奇怪的错误.

评估函数使用了方块表,就像这个用于典当的:

static int ptable_pawn[64] = {  
   0,  0,  0,  0,  0,  0,  0,  0,
  30, 35, 35, 40, 40, 35, 35, 30,
  20, 25, 25, 30, 30, 25, 25, 20,
  10, 20, 20, 20, 20, 20, 20, 10,
   3,  0, 14, 15, 15, 14,  0,  3,
   0,  5,  3, 10, 10,  3,  5,  0,
   5,  5,  5,  5,  5,  5,  5,  5,
   0,  0,  0,  0,  0,  0,  0,  0
};
Run Code Online (Sandbox Code Playgroud)

当它转过黑色时,表格会在x轴上反射出来.具体来说,如果你很好奇,查找会发生这样的情况,其中AH列映射到0-7,而行的颜色是白色的0-7:

int ptable_index_for_white(int col, int row) {
    return …
Run Code Online (Sandbox Code Playgroud)

algorithm chess artificial-intelligence minimax alpha-beta-pruning

11
推荐指数
1
解决办法
652
查看次数

Go:使用基准的时间值

我在Go中为我的国际象棋引擎写了一个基准:

func BenchmarkStartpos(b *testing.B) {
    board := ParseFen(startpos)
    for i := 0; i < b.N; i++ {
        Perft(&board, 5)
    }
}
Run Code Online (Sandbox Code Playgroud)

运行时我看到这个输出:

goos: darwin
goarch: amd64
BenchmarkStartpos-4           10     108737398 ns/op
PASS
ok      _/Users/dylhunn/Documents/go-chess  1.215s
Run Code Online (Sandbox Code Playgroud)

我想使用每次执行的时间(在这种情况下108737398 ns/op)来计算另一个值,并将其作为基准测试的结果打印出来.具体来说,我希望每秒输出节点,这是作为Perft呼叫结果除以每次呼叫的时间给出的.

如何访问基准测试执行的时间,以便打印自己的派生结果?

benchmarking go

6
推荐指数
1
解决办法
319
查看次数

使用内存进行 alpha-beta 搜索何时返回截止值?

我已经使用换位表实现了 alpha beta 搜索。

关于在表中存储截止值,我有正确的想法吗?

具体来说,我在发生表命中时返回截止值的方案是否正确?(同样,存储它们。)我的实现似乎与冲突,但直观上对我来说似乎是正确的。

另外,我的算法从不存储带有 at_most 标志的条目。我应该什么时候存储这些条目?

这是我的(简化的)代码,演示了主要思想:

int ab(board *b, int alpha, int beta, int ply) {
    evaluation *stored = tt_get(b);
    if (entryExists(stored) && stored->depth >= ply) {
        if (stored->type == at_least) { // lower-bound
            if (stored->score >= beta) return beta;
        } else if (stored->type == at_most) { // upper bound
            if (stored->score <= alpha) return alpha;
        } else { // exact
            if (stored->score >= beta) return beta; // respect fail-hard cutoff
            if (stored->score …
Run Code Online (Sandbox Code Playgroud)

algorithm chess artificial-intelligence minimax alpha-beta-pruning

5
推荐指数
1
解决办法
1446
查看次数

如何发布Go包

我正在尝试发布我的Go包,以便在文档搜索搜索中可见,并且可以安装go get.

但是,我发现的一个文档并没有清楚地告诉我如何生成和托管文档,或者根本不发布文件包.我该如何发布我的包裹?

go

4
推荐指数
2
解决办法
1446
查看次数

Flex:尝试使用Flex生成C ++词法分析器;“无法识别的规则”错误

我正在尝试使用生成词法分析器flex。这是我的定义文件lexer.l

%{
#include <iostream>

using namespace std;

//#define YY_DECL extern "C" int yylex()
%}

staffType "grand" | "treble" | "bass" | "alto" | "tenor"
upperRomans "I" | "II" | "III" | "IV" | "V" | "VI" | "VII"
lowerRomans "i" | "ii" | "iii" | "iv" | "v" | "vi" | "vii"
quality "dim" | "halfdim" | "aug" | "maj" | "min"

%%

[ \t\n]+ { ; // Ignore arbitrary whitespace. }
{staffType} { cout << …
Run Code Online (Sandbox Code Playgroud)

c++ lex lexer flex-lexer

4
推荐指数
1
解决办法
218
查看次数

结构中未初始化的字段没有Clang警告

考虑以下结构:

typedef struct foo {
    int a;
    int b;
} foo;
Run Code Online (Sandbox Code Playgroud)

我的编译器没有对以下语句发出警告:

foo m = {300}
Run Code Online (Sandbox Code Playgroud)

为什么没有发出警告?我期待一个警告,因为我没有为结构的最后一个字段提供任何值.

这是我的编译器调用:

gcc -Wall -Wpadded -Wuninitialized -g bar.c
Run Code Online (Sandbox Code Playgroud)

这是我的gcc版本:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

flipped_move字段是否只包含垃圾?这样安全吗?

c struct clang

3
推荐指数
2
解决办法
1201
查看次数

我对欧拉#3的Haskell解决方案效率低下

我试图解决Haskell中的Euler问题3,它涉及找到数字的最大素数因子.我的代码运行了很长时间,似乎挂了.是什么导致我的代码如此低效?

primes = sieve (2:[3,5..])
 where sieve (x:xs) = x:[y | y <- (sieve xs), mod y x /= 0]
       sieve [] = []
primefactors n = filter (\x -> mod n x == 0) (primesUnder n)
 where primesUnder z = reverse (takeWhile (< z) primes)
solve3 = head (primefactors 600851475143)
Run Code Online (Sandbox Code Playgroud)

performance primes haskell prime-factoring

1
推荐指数
1
解决办法
243
查看次数