示例#1
0
文件: go11.c 项目: KitAiProject/Go
int playout(int turn_color)
{
  int color =  turn_color;
  int previous_z = 0;
  int loop;
  int loop_max = B_SIZE*B_SIZE + 200;  // for triple ko

  all_playouts++;
  for (loop=0; loop<loop_max; loop++) {
    // all empty points are candidates.
    int empty[BOARD_MAX][2];  // [0]...z, [1]...probability
    int empty_num = 0;
    int prob_sum = 0;
    int x,y,z,err,pr;
    for (y=0;y<B_SIZE;y++) for (x=0;x<B_SIZE;x++) {
      int z = get_z(x+1,y+1);
      if ( board[z] != 0 ) continue;
      empty[empty_num][0] = z;
      pr = 100;
//    pr = get_prob(z, previous_z, color);
      empty[empty_num][1] = pr;
      prob_sum += pr;
      empty_num++;
    }
    for (;;) {
      int i = 0;
      if ( empty_num == 0 ) {
        z = 0;
      } else {
        int r = rand() % prob_sum;
        int sum = 0;
        for (i=0; i<empty_num; i++) {
          sum += empty[i][1];    // 0,1,2   [0]=1, [1]=1, [2]=1 
          if ( sum > r ) break;
        }
        if ( i==empty_num ) { prt("Err! prob_sum=%d,sum=%d,r=%d,r=%d\n",prob_sum,sum,r,i); exit(0); }
        z = empty[i][0]; 
      }
      err = put_stone(z, color, FILL_EYE_ERR);
      if ( err == 0 ) break;  // pass is ok.
      prob_sum -= empty[i][1];
      empty[i][0] = empty[empty_num-1][0];  // err, delete
      empty[i][1] = empty[empty_num-1][1];
      empty_num--;
    }
    if ( flag_test_playout ) record[moves++] = z;

    if ( depth < D_MAX ) path[depth++] = z;

    if ( z == 0 && previous_z == 0 ) break;  // continuous pass
    previous_z = z;
//  prt("loop=%d,z=%s,c=%d,empty_num=%d,ko_z=%d\n",loop,get_char_z(z),color,empty_num,ko_z);
    color = flip_color(color);
  }
  return count_score(turn_color);
}
示例#2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ping_process, ev, data)
{
  PROCESS_BEGIN();

  while(1)
    {
      //etimer_set (&et_tx, CLOCK_SECOND * 4 + random_rand() % (CLOCK_SECOND * 4));
      etimer_set (&et_tx, CLOCK_SECOND * 5);// + random_rand() % (CLOCK_SECOND * 1));

      PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);

    txbuffer[SCENARIO] 	= 	55;
    txbuffer[COUNT] 	= 	count++;
    txbuffer[SENDER] 	=	DEVICE_ID;
    txbuffer[23]	=	88;
    txbuffer[24]	=	77;


    /* ---- TX ---- */

    // Change this to not hardcode the packet length
    nrf_radio_send (txbuffer, 25);

    PRINTF ("PING\t TX: ----- Packet: %hi %hi %hi %hi %hi %hi %hi %hi\n\r",
    txbuffer[SCENARIO], txbuffer[COUNT], txbuffer[SENDER], txbuffer[DELAY],
    txbuffer[MULT], txbuffer[POWERA], txbuffer[POWERB], txbuffer[OPTIONAL]);

    /* ---- RX ---- */
    //nrf_radio_on();
    NETSTACK_RADIO.on();

    /* do we have a packet pending?*/

    /* FIXME CR: quick hack to prevent the program from waiting on an
     * Radio END Event if the packets have collided.
     */
    while (NRF_RADIO->EVENTS_END == 0 && escape < 400000)
      {
	escape++;
      }
    /* Reset the escape counter */
    escape = 0;

    /* Switch the radio off */
    //nrf_radio_off();
    NETSTACK_RADIO.off();

    /* Read what is in the radio buffer */
    nrf_radio_read(rxbuffer, sizeof(rxbuffer));

    PRINTF ("PING\t RX: ----- Last packet: %hi %hi %hi %hi %hi %hi %hi %hi\t\tRSSI: %i\n\r",
    rxbuffer[SCENARIO], rxbuffer[COUNT], rxbuffer[SENDER], rxbuffer[DELAY],
    rxbuffer[MULT], rxbuffer[POWERA], rxbuffer[POWERB], rxbuffer[OPTIONAL], nrf_radio_rssi());

    /* Check of whom we received a packet and count it */

    count_score();

    }

  PROCESS_END();
}