Exemplo n.º 1
0
void Session::_main_loop(SessionLog& log, HandState& hand_state) {
  // Pre-deal cards before any of the Player's start calling rand()
  ps::Card holdings[2][2];
  ps::Card flop[3];
  ps::Card turn;
  ps::Card river;

  for (int p=0; p<2; ++p) {
    for (int i=0; i<2; ++i ) {
      holdings[p][i] = _deck.deal();
    }
  }
  for (int i=0; i<3; ++i ) {
    flop[i] = _deck.deal();
  }
  turn = _deck.deal();
  river = _deck.deal();

  for (seat_t seat=0; seat<2; ++seat) {
    HoleCardDealEvent event(holdings[seat], seat);
    _players[seat]->handleEvent(hand_state, event);
    _set_holding(event.getSeat(), event.getCard(0), event.getCard(1));
    log.record(*this, hand_state, event);
  }

  hand_state.setActionOn(_button);
  BlindPostDecision small_blind = _players[_button]->handleBlindRequest(SMALL_BLIND);
  log.record(*this, hand_state, small_blind);
  
  hand_state.setActionOn(!_button);
  BlindPostDecision big_blind = _players[!_button]->handleBlindRequest(BIG_BLIND);
  log.record(*this, hand_state, big_blind);

  hand_state.payBlinds(_button, _betting_rules->getSmallBlind(), _betting_rules->getBigBlind());

  hand_state.setActionOn(_button);
  hand_state.setBettingRound(ROUND_PREFLOP);
  _do_betting_round(log, hand_state);
  if (hand_state.isDone()) return;
 
  PublicDealEvent flop_event(flop, 3);
  handleEvent(log, hand_state, flop_event);
  broadcastEvent(hand_state, flop_event);
  hand_state.setBettingRound(ROUND_FLOP);
  _do_betting_round(log, hand_state);
  if (hand_state.isDone()) return;

  PublicDealEvent turn_event(&turn, 1);
  handleEvent(log, hand_state, turn_event);
  broadcastEvent(hand_state, turn_event);
  hand_state.setBettingRound(ROUND_TURN);
  _do_betting_round(log, hand_state);
  if (hand_state.isDone()) return;
  
  PublicDealEvent river_event(&river, 1);
  handleEvent(log, hand_state, river_event);
  broadcastEvent(hand_state, river_event);
  hand_state.setBettingRound(ROUND_RIVER);
  _do_betting_round(log, hand_state);
}
Exemplo n.º 2
0
//callback for outgoing (TCP) connections
// NULL rule: broadcast event to user and sleep
// non-NULL rule: block/allow based on what rule says
static kern_return_t connect_out(void *cookie, socket_t so, const struct sockaddr *to)
{
    //result
    kern_return_t result = kIOReturnError;
    
    //dbg msg
    IOLog("LULU: in %s\n", __FUNCTION__);
    
    //sanity check
    if(NULL == cookie)
    {
        //bail
        goto bail;
    }
    
    //broadcast to user mode
    broadcastEvent(EVENT_CONNECT_OUT, so, to);
    
    //process
    // ->block/allow/ask user
    result = process(cookie, so, to);
    
bail:
    
    return result;
}
Exemplo n.º 3
0
//callback for outgoing (UDP) connections
// NULL rule: broadcast event to user and sleep
// non-NULL rule: block/allow based on what rule says
static kern_return_t data_out(void *cookie, socket_t so, const struct sockaddr *to, mbuf_t *data, mbuf_t *control, sflt_data_flag_t flags)
{
    //result
    kern_return_t result = kIOReturnError;
    
    //dbg msg
    IOLog("LULU: in %s\n", __FUNCTION__);
    
    //sanity check
    if(NULL == cookie)
    {
        //bail
        goto bail;
    }
    
    //broadcast to user mode
    broadcastEvent(EVENT_DATA_OUT, so, to);
    
    //process
    // ->block/allow/ask user
    result = process(cookie, so, to);
    
bail:
    
    return result;
}
Exemplo n.º 4
0
//
// The main read loop is in ANT.cpp, it will pass us
// the inbound message received for our channel.
// XXX fix this up to re-use ANTMessage for decoding
// all the inbound messages
//
void ANTChannel::receiveMessage(unsigned char *ant_message)
{
    switch (ant_message[2]) {
    case ANT_CHANNEL_EVENT:
        channelEvent(ant_message);
        break;
    case ANT_BROADCAST_DATA:
        broadcastEvent(ant_message);
        break;
    case ANT_ACK_DATA:
        ackEvent(ant_message);
        break;
    case ANT_CHANNEL_ID:
        channelId(ant_message);
        break;
    case ANT_BURST_DATA:
        burstData(ant_message);
        break;
    default:
        break; //XXX should trap error here, but silently ignored for now
    }

    if (get_timestamp() > blanking_timestamp + timeout_blanking) {
        if (!blanked) {
            blanked=1;
            value2=value=0;
            emit staleInfo(number);
        }
    } else blanked=0;
}
Exemplo n.º 5
0
void Session::_finish_hand(SessionLog& log, HandState& hand_state) {
  assert(!(hand_state.hasFolded(0) && hand_state.hasFolded(1)));
  assert(hand_state.getPotSize() == 
      hand_state.getAmountWageredPriorRounds(0) + hand_state.getAmountWageredPriorRounds(1));

  if (hand_state.hasFolded(0)) {
    _award_pot(log, hand_state, 1);
  } else if (hand_state.hasFolded(1)) {
    _award_pot(log, hand_state, 0);
  } else {
    ps::PokerEvaluation evals[2];
    seat_t showdown_order[2] = {!hand_state.getButton(), hand_state.getButton()};
    for (int i=0; i<2; ++i) {
      seat_t seat = showdown_order[i];
      Holding holding = _get_holding(seat);
      ps::PokerEvaluation eval = _evaluator.evaluateHand(holding.getCardSet(), 
          hand_state.getBoard().getCards()).high();
      evals[seat] = eval;
      ShowdownEvent showdown_event(holding, eval, seat);
      broadcastEvent(hand_state, !seat, showdown_event);
      log.record(*this, hand_state, showdown_event);
    }
    if (evals[0] > evals[1]) {
      _award_pot(log, hand_state, 0);
    } else if (evals[0] < evals[1]) {
      _award_pot(log, hand_state, 1);
    } else {
      _split_pot(log, hand_state);
    }
  }
}
Exemplo n.º 6
0
void Session::_split_pot(SessionLog& log, const HandState& hand_state) {
  // no change to scores
  
  PotSplitEvent split_event(&hand_state);
  broadcastEvent(hand_state, split_event);
  log.record(*this, hand_state, split_event);
}
Exemplo n.º 7
0
void Session::_do_betting_round(SessionLog& log, HandState& hand_state) {
  while (!hand_state.isCurrentBettingRoundDone()) {
    seat_t seat = hand_state.getActionOn();
    BettingDecision decision = _players[seat]->makeDecision(hand_state);
    _validate_decision(hand_state, decision);

    handleEvent(log, hand_state, seat, decision);
    broadcastEvent(hand_state, !seat, decision);
  }
  hand_state.advanceBettingRound();
}
Exemplo n.º 8
0
void Session::_award_pot(SessionLog& log, const HandState& hand_state, seat_t seat) {
  chip_amount_t net_gain = hand_state.getPotSize() - hand_state.getAmountWageredPriorRounds(seat);
  chip_amount_t net_loss = - hand_state.getAmountWageredPriorRounds(!seat);

  assert(net_gain + net_loss == 0);
  _update_score(seat, net_gain);
  _update_score(!seat, net_loss);

  PotWinEvent win_event(&hand_state, seat);
  broadcastEvent(hand_state, win_event);
  log.record(*this, hand_state, win_event);
}
Exemplo n.º 9
0
void RGBDGrabber :: advertiseNewFrame()
{
    ++m_frame_count;
    float tick = ntk::Time::getMillisecondCounter();
    float delta_tick = (tick - m_last_frame_tick);
    if (delta_tick > 1000)
    {
        m_framerate = (1000.f * m_frame_count) / (delta_tick);
        m_last_frame_tick = tick;
        m_frame_count = 0;
    }

    m_condition.wakeAll();
    broadcastEvent();
}
Exemplo n.º 10
0
    void
    HIVSimpleDiagnostic::onNegativeTestResult()
    {
        auto iid = parent->GetSuid().data;
        LOG_DEBUG_F( "Individual %d tested 'negative' in HIVSimpleDiagnostic, receiving actual intervention.\n", iid );

        if( !negative_diagnosis_event.IsUninitialized() )
        {
            LOG_DEBUG_F( "Brodcasting event %s as negative diagnosis event for individual %d.", negative_diagnosis_event.c_str(), iid );
            broadcastEvent( negative_diagnosis_event );
        }
        else
        {
            LOG_DEBUG_F( "Negative diagnosis event is NoTrigger for individual %d.\n", iid );
        }
        expired = true;
    }