Пример #1
0
JsonObject*
SamiEvent::asJsonObject() {
    JsonObject *pJsonObject = new JsonObject();
    pJsonObject->Construct();

    
    JsonString *p_idKey = new JsonString(L"_id");
    pJsonObject->Add(p_idKey, toJson(getPId(), "String", ""));

    
    JsonString *pTypeKey = new JsonString(L"type");
    pJsonObject->Add(pTypeKey, toJson(getPType(), "String", ""));

    
    JsonString *pRefererKey = new JsonString(L"referer");
    pJsonObject->Add(pRefererKey, toJson(getPReferer(), "String", ""));

    
    JsonString *pOriginal_urlKey = new JsonString(L"original_url");
    pJsonObject->Add(pOriginal_urlKey, toJson(getPOriginalUrl(), "String", ""));

    
    JsonString *pOriginator_emailKey = new JsonString(L"originator_email");
    pJsonObject->Add(pOriginator_emailKey, toJson(getPOriginatorEmail(), "String", ""));

    
    JsonString *pSubject_emailKey = new JsonString(L"subject_email");
    pJsonObject->Add(pSubject_emailKey, toJson(getPSubjectEmail(), "String", ""));

    
    JsonString *pParent_event_idKey = new JsonString(L"parent_event_id");
    pJsonObject->Add(pParent_event_idKey, toJson(getPParentEventId(), "String", ""));

    
    JsonString *pOriginator_idKey = new JsonString(L"originator_id");
    pJsonObject->Add(pOriginator_idKey, toJson(getPOriginatorId(), "String", ""));

    
    JsonString *pAdvisor_idKey = new JsonString(L"advisor_id");
    pJsonObject->Add(pAdvisor_idKey, toJson(getPAdvisorId(), "String", ""));

    
    JsonString *pSubject_idKey = new JsonString(L"subject_id");
    pJsonObject->Add(pSubject_idKey, toJson(getPSubjectId(), "String", ""));

    
    JsonString *pEvent_contentKey = new JsonString(L"event_content");
    pJsonObject->Add(pEvent_contentKey, toJson(getPEventContent(), "SamiEventContent", ""));

    
    JsonString *pCreated_atKey = new JsonString(L"created_at");
    pJsonObject->Add(pCreated_atKey, toJson(getPCreatedAt(), "String", ""));

    
    return pJsonObject;
}
Пример #2
0
JsonObject*
SamiApiResponse::asJsonObject() {
    JsonObject *pJsonObject = new JsonObject();
    pJsonObject->Construct();

    JsonString *pCodeKey = new JsonString(L"code");
    pJsonObject->Add(pCodeKey, toJson(getPCode(), "Integer", ""));

    JsonString *pTypeKey = new JsonString(L"type");
    pJsonObject->Add(pTypeKey, toJson(getPType(), "String", ""));

    JsonString *pMessageKey = new JsonString(L"message");
    pJsonObject->Add(pMessageKey, toJson(getPMessage(), "String", ""));

    return pJsonObject;
}
Пример #3
0
moveGroup generateAllMoves(state s, playerNum p)
{
    pType playerType = getPType(s, p);
    if((p == PLAYER_ONE && (getP1LeadTrick(s))) ||
        (p == PLAYER_TWO && !getP1LeadTrick(s)))
    {
        if(playerType == MINIMAX_LOWEST_CLOSE ||
            playerType == MINIMAX_HIGHEST_CLOSE)
            {return generateAllLeadMoves_CLOSE(s, p);}
        else {return generateAllLeadMoves_NOCLOSE(s, p);}
    }
    if(playerType == MINIMAX_LOWEST_CLOSE ||
        playerType == MINIMAX_HIGHEST_CLOSE)
        {return generateAllFollowMoves_CLOSE(s, p);}
    //else
    return generateAllFollowMoves_NOCLOSE(s, p);
}
JsonObject*
SamiActivity::asJsonObject() {
    JsonObject *pJsonObject = new JsonObject();
    pJsonObject->Construct();

    JsonString *pTypeKey = new JsonString(L"type");
    pJsonObject->Add(pTypeKey, toJson(getPType(), "String", ""));

    JsonString *pIdKey = new JsonString(L"id");
    pJsonObject->Add(pIdKey, toJson(getPId(), "String", ""));

    JsonString *pLocation_idKey = new JsonString(L"location_id");
    pJsonObject->Add(pLocation_idKey, toJson(getPLocationId(), "String", ""));

    JsonString *pArr_timeKey = new JsonString(L"arr_time");
    pJsonObject->Add(pArr_timeKey, toJson(getPArrTime(), "Long", ""));

    JsonString *pEnd_timeKey = new JsonString(L"end_time");
    pJsonObject->Add(pEnd_timeKey, toJson(getPEndTime(), "Long", ""));

    JsonString *pWaiting_timeKey = new JsonString(L"waiting_time");
    pJsonObject->Add(pWaiting_timeKey, toJson(getPWaitingTime(), "Long", ""));

    JsonString *pDistanceKey = new JsonString(L"distance");
    pJsonObject->Add(pDistanceKey, toJson(getPDistance(), "Long", ""));

    JsonString *pDriving_timeKey = new JsonString(L"driving_time");
    pJsonObject->Add(pDriving_timeKey, toJson(getPDrivingTime(), "Long", ""));

    JsonString *pLoad_beforeKey = new JsonString(L"load_before");
    pJsonObject->Add(pLoad_beforeKey, toJson(getPLoadBefore(), "Integer", "array"));

    JsonString *pLoad_afterKey = new JsonString(L"load_after");
    pJsonObject->Add(pLoad_afterKey, toJson(getPLoadAfter(), "Integer", "array"));

    return pJsonObject;
}
Пример #5
0
JsonObject*
SamiMemberReport::asJsonObject() {
    JsonObject *pJsonObject = new JsonObject();
    pJsonObject->Construct();

    
    JsonString *pDayKey = new JsonString(L"day");
    pJsonObject->Add(pDayKey, toJson(getPDay(), "Integer", ""));

    
    JsonString *pEvent_countKey = new JsonString(L"event_count");
    pJsonObject->Add(pEvent_countKey, toJson(getPEventCount(), "Integer", ""));

    
    JsonString *pOriginator_group_idKey = new JsonString(L"originator_group_id");
    pJsonObject->Add(pOriginator_group_idKey, toJson(getPOriginatorGroupId(), "String", ""));

    
    JsonString *pParent_originator_idKey = new JsonString(L"parent_originator_id");
    pJsonObject->Add(pParent_originator_idKey, toJson(getPParentOriginatorId(), "String", ""));

    
    JsonString *pSourceKey = new JsonString(L"source");
    pJsonObject->Add(pSourceKey, toJson(getPSource(), "String", ""));

    
    JsonString *pTypeKey = new JsonString(L"type");
    pJsonObject->Add(pTypeKey, toJson(getPType(), "String", ""));

    
    JsonString *pYearKey = new JsonString(L"year");
    pJsonObject->Add(pYearKey, toJson(getPYear(), "Integer", ""));

    
    return pJsonObject;
}
Пример #6
0
void testState()
{
    testMove();
    state s = newStartingState(0b00010010);
    if(getPScores(s, PLAYER_ONE) != 0) {fail("getPScores() failed in State module\n");}
    if(getPScores(s, PLAYER_TWO) != 0) {fail("getPScores() failed in State module\n");}
    s = addPScore(s, PLAYER_ONE, 16);
    s = addPScore(s, PLAYER_TWO, 52);
    if(getPScores(s, PLAYER_ONE) != 16) {fail("addPScore() failed in State module\n");}
    if(getPScores(s, PLAYER_TWO) != 52) {fail("addPScore() failed in State module\n");}
    card firstDealt = getNextCard(s);
    if(numCardsLeft(getDeck(s) & DECK) != 9) {fail("getNextCard() failed in State module\n");}
    s = removeNextCard(s, firstDealt);
    if(!equal(s.deckOrder[0], firstDealt)) {fail("getNextCard() failed in State module\n");}
    if(numCardsLeft(getDeck(s) & DECK) != 8) {fail("removeNextCard() failed in State module\n");}
    if(((getDeck(s) & ~DECK) >> 28) != 1) {fail("removeNextCard() failed in State module\n");}
    pile p = newCardRankSuit(KING, CLUBS) | newCardRankSuit(KING, HEARTS) |
        newCardRankSuit(ACE, CLUBS) | newCardRankSuit(JACK, DIAMONDS);
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 5) {fail("getPHand() failed in State module\n");}
    s = setPHand(s, PLAYER_ONE, p);
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 4) {fail("setPHand() failed in State module\n");}
    s = addCardPHand(s, PLAYER_ONE, newCardRankSuit(QUEEN, SPADES));
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(JACK, DIAMONDS)))
        {fail("addCardPHand() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(QUEEN, SPADES)))
        {fail("addCardPHand() failed in State module\n");}
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 5)
        {fail("addCardPHand() failed in State module\n");}
    s = removePHandCard(s, PLAYER_ONE, newCardRankSuit(KING, HEARTS));
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(JACK, DIAMONDS)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(QUEEN, SPADES)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(KING, CLUBS)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(ACE, CLUBS)))
        {fail("removePHandCard() failed in State module\n");}
    if(contains(getPHand(s, PLAYER_ONE), newCardRankSuit(KING, HEARTS)))
        {fail("removePHandCard() failed in State module\n");}
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 4)
        {fail("removePHandCard() failed in State module\n");}
    if(getPType(s, PLAYER_ONE) != MINIMAX_HIGHEST_CLOSE)
        {fail("getPType() failed in State module\n");}
    if(getPType(s, PLAYER_TWO) != MINIMAX_LOWEST_CLOSE)
        {fail("getPType() failed in State module\n");}
    s = switchPTypes(s);
    if(getPType(s, PLAYER_ONE) != MINIMAX_LOWEST_CLOSE)
        {fail("switchPTypes() failed in State module\n");}
    if(getPType(s, PLAYER_TWO) != MINIMAX_HIGHEST_CLOSE)
        {fail("switchPTypes() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_ONE) != 0)
        {fail("getPCurrGamePoints() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_TWO) != 0)
        {fail("getPCurrGamePoints() failed in State module\n");}
    s = addGamePoints(s, PLAYER_ONE, 4);
    if(getPCurrGamePoints(s, PLAYER_ONE) != 4)
        {fail("addGamePoints() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_TWO) != 0)
        {fail("addGamePoints() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("getPRevCards() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 0)
        {fail("getPRevCards() failed in State module\n");}
    s = addCardPRevCards(s, PLAYER_TWO, newCardRankSuit(JACK, HEARTS));
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("addCardPRevCards() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 1)
        {fail("addCardPRevCards() failed in State module\n");}
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(QUEEN, HEARTS));
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(JACK, DIAMONDS));
    s = removePRevCard(s, PLAYER_ONE, newCardRankSuit(JACK, DIAMONDS));
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("removePRevCard() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 1)
        {fail("removePRevCard() failed in State module\n");}
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(JACK, HEARTS));
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 0)
        {fail("removePRevCard() failed in State module\n");}
    if(getTrumpSwapped(s))
        {fail("getTrumpSwapped() failed in State module\n");}
    s = setTrumpSwapped(s);
    if(!getTrumpSwapped(s))
        {fail("setTrumpSwapped() failed in State module\n");}
    if(getP1ClosedTalon(s))
        {fail("newStartingState() with getP1ClosedTalon() failed in State module\n");}
    s = setPClosedTalon(s, PLAYER_ONE);
    if(!getP1ClosedTalon(s))
        {fail("setPClosedTalon() 1failed in State module\n");}
    s = setPClosedTalon(s, PLAYER_TWO);
    if(getP1ClosedTalon(s))
        {fail("setPClosedTalon() 2failed in State module\n");}
    if(getDealEnded(s)) {fail("newStartingState() failed in State module\n");}
    s = setDealEnded(s);
    if(!getDealEnded(s)) {fail("setDealEnded() failed in State module\n");}
    bool p1Leading = getP1PlayedFirst(s);
    if(p1Leading)
    {
        if(!getP1LeadTrick(s)) {fail("getP1LeadTrick() failed in State module\n");}
        s = setP1LeadTrick(s, false);
        if(getP1LeadTrick(s)) {fail("setP1LeadTrick() failed in State module\n");}
    }
    else
    {
        if(getP1LeadTrick(s)) {fail("getP1LeadTrick() failed in State module\n");}
        s = setP1LeadTrick(s, true);
        if(!getP1LeadTrick(s)) {fail("setP1LeadTrick() failed in State module\n");}
    }
    if(numCardsLeft(getAllUnseenCards(s, PLAYER_ONE)) != 13)
        {fail("getAllUnseenCards() 1failed in State module\n");}
    s = updatePPossGamePoints(s, PLAYER_ONE);
    if(getPPossGamePoints(s, PLAYER_ONE) != 3)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(getPPossGamePoints(s, PLAYER_TWO) != 3)
        {fail("updatePPossGamePoints() failed in State module\n");}
    s = setPWonATrick(s, PLAYER_TWO);
    s = updatePPossGamePoints(s, PLAYER_ONE);
    if(getPPossGamePoints(s, PLAYER_ONE) != 4)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(getPPossGamePoints(s, PLAYER_TWO) != 5)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(strcmp(strPlayerNum(PLAYER_ONE), "Player One") != 0)
        {fail("strPlayerNum() failed in State module\n");}
    if(strcmp(strPlayerNum(PLAYER_TWO), "Player Two") != 0)
        {fail("strPlayerNum() failed in State module\n");}
    if(strcmp(strPType(MINIMAX_HIGHEST_CLOSE), "Minimax (highest close)") != 0)
        {fail("strPType() failed in State module\n");}
    puts("State Module OK\n");
}