Example #1
0
void showPlayersCard(const struct Player* player)
{
    int indent = 0;
    int i;

    player->isDealer ? printf("Dealer's card") : printf("Your card ");
    if(player->isSplit) printf("(Splited)");
    printf("\n");

    for(i = 0; i < MAX_PLAYER_CARD_NUM; i++) {
        int card_id = getCardInSlot(&player->slot, i);
        int spCardId = getCardInSlot(&player->spSlot, i);
        if(card_id != INVALID_CARD_ID) {
            if(player->isDealer && i == 1 && !player->isStand) {
                printf("%7s [%2s] (Hole Card)", "XXXXX", "X");
            }
            else {
                indent = 0;
                printCardInfo(card_id, indent);
            }
            if(spCardId != INVALID_CARD_ID) {
                indent = 4;
                printCardInfo(spCardId, indent);
            }
            printf("\n");
        }
        else if(spCardId != INVALID_CARD_ID) {
            indent = 16;
            printCardInfo(spCardId, indent);
            printf("\n");
        }
    }
    printf("\n");
}
Example #2
0
int drawCard_d()
{
    int drawCard = INVALID_CARD_ID;
    printAvailableCardInfo(&s_cardDeck);
    printf("[DEBUG] Input Card ID manualy\n");
    while(drawCard == INVALID_CARD_ID) {
        drawCard = getUserInputNum("[DEBUG] Input card ID", 0, 51);
        drawCard = serveSpecificCard(&s_cardDeck, drawCard);
    }
    printf("[DEBUG] Serve ");
    printCardInfo(drawCard, 0);
    printf("\n\n");

    return drawCard;
}
Example #3
0
void splitCard(struct Player* player)
{
    int moveCard = popCardFromSlot(&player->slot);
    pushCardToSlot(&player->spSlot, moveCard);

#ifdef BJDEBUG
    printf("[DEBUG] Move ");
    printCardInfo(moveCard, 0);
    printf("\n");
#endif
    player->isSplit = TRUE;

    calcScoreState(&player->slot, player->isDealer, player->isSplit);
    calcScoreState(&player->spSlot, player->isDealer, player->isSplit);
}
Example #4
0
void setupLog() {
    if (!card.init(SPI_HALF_SPEED, SD_CS)) {
        Serial.println(F("No SD card inserted, disabling data logger."));
        disableLogging = true;
    }

    if (!disableLogging && !volume.init(card)) {
        Serial.println(F("Unable to initialize SD volume"));
        disableLogging = true;
    }

    if (!disableLogging && !root.openRoot(volume)) {
        Serial.println(F("Unable to open volume root"));
        disableLogging = true;
    }

#ifdef DEBUG
    printCardInfo();
#endif

    if (!disableLogging) {
        openLog();
    }
}
Example #5
0
void loop() {
    unsigned long tick = millis();
    long diff = tick - lastTick;
    avgTickDelay = expAvg(avgTickDelay, diff);
    lastTick = tick;
    if (printTicks > printTicksI) {
        Serial.print("tick delay: ");
        Serial.print(diff);
        Serial.println("ms");
    }

    // Radio tick.
    radio->tick();

    // Send helo.
    diff = tick - lastSent;
    if ((lastAck < lastSent && diff > MAX_SEND_WAIT)
        || diff > MIN_SEND_WAIT
    ) {
        avgSendDelay = expAvg(avgSendDelay, diff);
        lastSent = tick;
        if (printTicks > printTicksI) {
            printTicksI++;
            Serial.print("send delay: ");
            Serial.print(diff);
            Serial.println("ms");
        }

        if (sendInfx) {
            Message msg("he");
            radio->send(&msg);
        } else {
            Message msg("lo");
            radio->send(&msg);
        }
        sendInfx = !sendInfx;
    }

    // Update metrics.
    tick = millis();
    if (tick - lastUpdate > UPDATE_WAIT) {
        memcpy(&mLast, &m, sizeof(metrics));
        lastUpdate = tick;
        lastVcc = readVcc();

        sinceLastAck = (int) ((lastUpdate - lastAck) / 1000L);
        if (sinceLastAck < 0) {
#ifdef DEBUG
            Serial.println("sinceLastAck less than 0");
            Serial.print("round((");
            Serial.print(lastUpdate);
            Serial.print(" - ");
            Serial.print(lastAck);
            Serial.print(") / 1000.0) = ");
            Serial.println(sinceLastAck);
#endif

            sinceLastAck = 0;
        }

        if (lastAck + TIMEOUT_WAIT < lastSent) {
            lastRoundtrip = NO_READING_INT;
            lastRssi = NO_READING_INT;
        }

        writeLog();
    }

    // Pipeline tick.
    pipe->tick();

    // Serial commands.
    if (Serial.available()) {
        String cmd = Serial.readStringUntil('\n');
        if (cmd[0] == 'D') {
            dataFile.close();
            if (!dataFile.open(root, logFilename, O_READ)) {
                Serial.println();
                Serial.println("Could not open file for reading");
                return;
            }
            uint32_t offset;
            long cmdOffset = cmd.substring(1).toInt();
            if (cmdOffset < 0) {
                offset = dataFile.fileSize() + cmdOffset;
            } else {
                offset = cmdOffset;
            }
            dataFile.seekSet(offset);
            char buf[128];
            int16_t read;
            bool firstRead = true;
            do {
                read = dataFile.read(buf, 127);
                buf[read] = 0;
                if (firstRead && read > 0) {
                    firstRead = false;
                    char *firstNewline = strchr(buf, '\n');
                    Serial.print(++firstNewline);
                } else {
                    Serial.print(buf);
                }
            } while (read > 0);
            Serial.println();
            dataFile.close();

        } else if (cmd[0] == 'L') {
            printCardInfo();

        } else if (cmd[0] == 'I') {
            Serial.print(F("Average tick delay: "));
            Serial.print(avgTickDelay);
            Serial.println(F("ms"));
            Serial.print(F("Average send delay: "));
            Serial.print(avgSendDelay);
            Serial.println(F("ms"));
            Serial.print(F("RAM free: "));
            Serial.print(freeRam());
            Serial.println(F(" bytes"));
            printTicks = (int) cmd.substring(1).toInt();
            printTicksI = 0;
        } else if (cmd[0] == 'G') {
            Serial.print(F("Location: "));
            Serial.print(m.latitude, 6);
            Serial.print(F(","));
            Serial.println(m.longitude, 6);
        } else if (cmd[0] == 'U') {
            Message msg("up");
            radio->send(&msg);
        } else if (cmd[0] == 'F') {
            if (m.logging != MODULE_ENABLED) {
                Serial.println(F("Requesting to enable logging"));
            } else {
                Serial.println(F("Requesting to disable logging"));
            }
            Message msg("tl");
            radio->send(&msg);
        } else if (cmd[0] == 'T') {
            Serial.print(F("Remote data logging is "));
            Serial.println(m.logging == MODULE_ENABLED ? "enabled" : "disabled");
        }
    }
}