Пример #1
0
void methodassignhashcode(struct rolemethod * method) {
  int i;
  int hashcode=hashptr(method->methodname);
  for(i=0;i<method->numobjectargs;i++)
    hashcode^=hashstring(method->paramroles[i]);
  method->hashcode=hashcode;
}
Пример #2
0
unsigned int list_hash(list_t *list) {
  unsigned int hash;
  reduce_ctx *ctx;

  hash = hashptr(list);
  if (list -> type.hash && list_size(list)) {
    ctx = NEW(reduce_ctx);
    ctx -> fnc = (void_t) list -> type.hash;
    ctx -> longdata = hash;
    list_reduce(list, (reduce_t) collection_hash_reducer, ctx);
    hash = (unsigned int) ctx -> longdata;
    free(ctx);
  }
  return hash;
}
Пример #3
0
bool Board::save(string saveName)
{
    ofstream save(saveName+".save",ios::binary);
    if (!save)
    {
        cout << Game::mainLang.savefl;
        PAUSE;
        return false;
    }

    save << Game::AIFlag << endl;
    save << Game::assistFlag << endl;
    save << Game::humanSide << endl;
    save << Game::diff << endl << endl;
    save << movesRecord.size() << endl;
    for (unsigned i = 0; i < movesRecord.size(); i++)
        save << movesRecord[i].x << ' '
        << movesRecord[i].y << endl << endl;
    save.close();

    ifstream load(saveName + ".save");
    ofstream hsave(saveName + ".hash");
    if (!load || !hsave)
    {
        cout << Game::mainLang.savefl;
        PAUSE;
        return false;
    }
    ostringstream sload;
    sload << load.rdbuf();

    string read = sload.str();

    hash<string> hashptr;

    hsave << hashptr(read);
    hsave.close();
    load.close();

    return true;
}
Пример #4
0
bool Board::load(string loadName, int undoSteps)
{
    CLS;
    ifstream load(loadName + ".save", ios::binary);
    ifstream hload(loadName + ".hash");
    ostringstream sload, hsload;
    if (!load || !hload || !sload)
    {
        cout << Game::mainLang.loadfl << endl;
        cout << Game::mainLang.gotomain;
        PAUSE;
        return false;
    }

    hash<string> hashptr;
    hsload << hload.rdbuf();
    sload << load.rdbuf();

    string saveHash = hsload.str();
    string file = sload.str();

    ostringstream convert;
    convert << hashptr(file);
    string fileHash = convert.str();

    if (fileHash != saveHash)
    {
        cout << Game::mainLang.savedmg << endl;
        cout << Game::mainLang.gotomain;
        PAUSE;
        return false;
    }
    load.close();
    hload.close();

    Game::board.init();

    load.open(loadName + ".save");

    load >> Game::AIFlag;
    load >> Game::assistFlag;
    load >> Game::humanSide;
    load >> Game::diff;

    if (Game::diff)
        AchillesInit(Game::diff);

    int movesCount;
    load >> movesCount;
    movesCount -= undoSteps;
    Game::board.movesRecord.clear();

    for (int i = 0; i < movesCount; i++)
    {
        Coord tmpCoord{};
        load >> tmpCoord.x;
        load >> tmpCoord.y;
        Game::board.move(tmpCoord);
    }
    load.close();

    print();

    return true;
}