从视图控制器而不是应用程序委托加载时 Stockfish 引擎中断 iOS
Stockfish Engine breaks when loaded from a view controller instead of the app delegate iOS
我试图将 Stockfish UCI 引擎实现到国际象棋游戏应用程序中。最初在 Stockfish iOS 游戏中,持有棋盘和棋子的视图控制器是从应用程序委托加载的。我想要做的是在导航到游戏之前再显示几个屏幕。我遇到的问题是,一旦我加载棋盘屏幕,游戏就会在 bitboard.cpp 文件中中断,并显示消息 EXC_BAD_ACCESS(代码=1, address=0x1fa80000) 有几次我设法把棋子装到棋盘上并移动了其中一个,但随后它在下面这条线显示的同一个地方刹车:占用[大小] = b;
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index) {
int MagicBoosters[][8] = { { 969, 1976, 2850, 542, 2069, 2852, 1708, 164 },
{ 3101, 552, 3555, 926, 834, 26, 2131, 1117 } };
RKISS rk;
Bitboard occupancy[4096], reference[4096], edges, b;
int i, size, booster;
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
attacks[SQ_A1] = table;
for (Square s = SQ_A1; s <= SQ_H8; ++s)
{
// Board edges are not considered in the relevant occupancies
edges = ((Rank1BB | Rank8BB) & ~rank_bb(s)) | ((FileABB | FileHBB) & ~file_bb(s));
// Given a square 's', the mask is the bitboard of sliding attacks from
// 's' computed on an empty board. The index must be big enough to contain
// all the attacks for each possible subset of the mask and so is 2 power
// the number of 1s of the mask. Hence we deduce the size of the shift to
// apply to the 64 or 32 bits word to get the index.
masks[s] = sliding_attack(deltas, s, 0) & ~edges;
shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
// store the corresponding sliding attack bitboard in reference[].
b = size = 0;
do {
occupancy[size] = b;
reference[size] = sliding_attack(deltas, s, b);
if (HasPext)
attacks[s][_pext_u64(b, masks[s])] = reference[size];
size++;
b = (b - masks[s]) & masks[s];
} while (b);
// Set the offset for the table of the next square. We have individual
// table sizes for each square with "Fancy Magic Bitboards".
if (s < SQ_H8)
attacks[s + 1] = attacks[s] + size;
if (HasPext)
continue;
booster = MagicBoosters[Is64Bit][rank_of(s)];
// Find a magic for square 's' picking up an (almost) random number
// until we find the one that passes the verification test.
do {
do magics[s] = rk.magic_rand<Bitboard>(booster);
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
std::memset(attacks[s], 0, size * sizeof(Bitboard));
// A good magic must map every possible occupancy to an index that
// looks up the correct sliding attack in the attacks[s] database.
// Note that we build up the database for square 's' as a side
// effect of verifying the magic.
for (i = 0; i < size; ++i)
{
Bitboard& attack = attacks[s][index(s, occupancy[i])];
if (attack && attack != reference[i])
break;
assert(reference[i]);
attack = reference[i];
}
} while (i < size);
}
我在 C++ 方面没有太多经验和知识,我正在努力找出导致问题的原因。
我现在已经解决了!我认为当我加载它的视图时游戏仍在初始化,这导致了整个问题,因为初始化程序在后台 运行!为了解决这个问题,我制作了一个加载屏幕并在那里调用了游戏的初始化程序!一旦在后台设置完毕,我就会加载游戏的屏幕!!!希望我的 post 对以后的人有所帮助!
我试图将 Stockfish UCI 引擎实现到国际象棋游戏应用程序中。最初在 Stockfish iOS 游戏中,持有棋盘和棋子的视图控制器是从应用程序委托加载的。我想要做的是在导航到游戏之前再显示几个屏幕。我遇到的问题是,一旦我加载棋盘屏幕,游戏就会在 bitboard.cpp 文件中中断,并显示消息 EXC_BAD_ACCESS(代码=1, address=0x1fa80000) 有几次我设法把棋子装到棋盘上并移动了其中一个,但随后它在下面这条线显示的同一个地方刹车:占用[大小] = b;
void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
Bitboard masks[], unsigned shifts[], Square deltas[], Fn index) {
int MagicBoosters[][8] = { { 969, 1976, 2850, 542, 2069, 2852, 1708, 164 },
{ 3101, 552, 3555, 926, 834, 26, 2131, 1117 } };
RKISS rk;
Bitboard occupancy[4096], reference[4096], edges, b;
int i, size, booster;
// attacks[s] is a pointer to the beginning of the attacks table for square 's'
attacks[SQ_A1] = table;
for (Square s = SQ_A1; s <= SQ_H8; ++s)
{
// Board edges are not considered in the relevant occupancies
edges = ((Rank1BB | Rank8BB) & ~rank_bb(s)) | ((FileABB | FileHBB) & ~file_bb(s));
// Given a square 's', the mask is the bitboard of sliding attacks from
// 's' computed on an empty board. The index must be big enough to contain
// all the attacks for each possible subset of the mask and so is 2 power
// the number of 1s of the mask. Hence we deduce the size of the shift to
// apply to the 64 or 32 bits word to get the index.
masks[s] = sliding_attack(deltas, s, 0) & ~edges;
shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and
// store the corresponding sliding attack bitboard in reference[].
b = size = 0;
do {
occupancy[size] = b;
reference[size] = sliding_attack(deltas, s, b);
if (HasPext)
attacks[s][_pext_u64(b, masks[s])] = reference[size];
size++;
b = (b - masks[s]) & masks[s];
} while (b);
// Set the offset for the table of the next square. We have individual
// table sizes for each square with "Fancy Magic Bitboards".
if (s < SQ_H8)
attacks[s + 1] = attacks[s] + size;
if (HasPext)
continue;
booster = MagicBoosters[Is64Bit][rank_of(s)];
// Find a magic for square 's' picking up an (almost) random number
// until we find the one that passes the verification test.
do {
do magics[s] = rk.magic_rand<Bitboard>(booster);
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
std::memset(attacks[s], 0, size * sizeof(Bitboard));
// A good magic must map every possible occupancy to an index that
// looks up the correct sliding attack in the attacks[s] database.
// Note that we build up the database for square 's' as a side
// effect of verifying the magic.
for (i = 0; i < size; ++i)
{
Bitboard& attack = attacks[s][index(s, occupancy[i])];
if (attack && attack != reference[i])
break;
assert(reference[i]);
attack = reference[i];
}
} while (i < size);
}
我在 C++ 方面没有太多经验和知识,我正在努力找出导致问题的原因。
我现在已经解决了!我认为当我加载它的视图时游戏仍在初始化,这导致了整个问题,因为初始化程序在后台 运行!为了解决这个问题,我制作了一个加载屏幕并在那里调用了游戏的初始化程序!一旦在后台设置完毕,我就会加载游戏的屏幕!!!希望我的 post 对以后的人有所帮助!