从视图控制器而不是应用程序委托iOS加载时,Stockfish引擎会中断

时间:2016-05-24 14:39:54

标签: c++ ios objective-c chess

我试图将Stockfish UCI引擎实现为国际象棋游戏应用程序。最初在Stockfish iOS游戏中,保存棋盘和棋子的视图控制器从app delegate加载。我想要做的是在导航到游戏之前还有几个屏幕。我遇到的问题是,只要我加载电路板屏幕,游戏就会在 bitboard.cpp 文件中断,并显示消息 EXC_BAD_ACCESS(code = 1,address = 0x1fa80000)有几次我设法将这些碎片装在板上并移动其中一个然后它在下面这一行所示的相同位置制动:占用[size] = 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 ++方面没有太多经验和知识,我正在努力弄清楚是什么导致了这个问题。

1 个答案:

答案 0 :(得分:0)

我现在已经设法解决了!我认为在我加载视图时游戏仍在初始化,这导致了整个问题,因为初始化程序在后台运行!为了解决这个问题,我已经制作了一个加载屏幕并在那里调用游戏的初始化程序!一旦它全部在后台设置我加载屏幕与游戏!希望我的帖子能帮助将来的某个人!