Example #1
0
void compute_all_status(Position *pos, int owner_map[BOARDSIZE],
        int score_count[], Status block_status[], Status point_status[])
// Compute status of of points and blocks (based on owner_map)
// - the points : OWN_BY_BLACK, OWN_BY_WHITE or UNKNOWN
// - the blocks : DEAD, ALIVE or UNKNOWN
{
    Color c;
    int   b;
    Status new_g_st, p_st;
    TreeNode *tree=new_tree_node();

    // Launch a full depth MCTS search in order to compute owner_map
    double FASTPLAY20_THRES_sav = FASTPLAY20_THRES;
    double FASTPLAY5_THRES_sav = FASTPLAY5_THRES;
    memset(owner_map, 0, BOARDSIZE*sizeof(int));
    nplayouts_real = 0;
    tree_search(pos, tree, 2*N_SIMS, owner_map, score_count, 0);
    FASTPLAY20_THRES = FASTPLAY20_THRES_sav;
    FASTPLAY5_THRES = FASTPLAY5_THRES_sav;
    sprintf(buf, "nsims: %d", nplayouts_real);
    log_fmt_s('I',buf,NULL);

    // Reset status of points and blocks
    FORALL_POINTS(pos, pt)
        point_status[pt] = UNKNOWN;
    for (b=1 ; b<MAX_BLOCKS ; b++)
        block_status[b] = UNKNOWN;

    // Try to evaluate block status
    FORALL_POINTS(pos, pt) {
        b = point_block(pos, pt);
        if (b != 0) {
            c = point_color(pos, pt);
            point_status[pt] = p_st = mcts_point_status(pt, owner_map);
            if (p_st == UNKNOWN)
                block_status[b] = UNKNOWN;
            else {
                new_g_st = UNKNOWN;
                if ((p_st == OWN_BY_WHITE && c==BLACK) ||
                        (p_st == OWN_BY_BLACK && c==WHITE))
                    new_g_st = DEAD;
                else if ((p_st == OWN_BY_BLACK && c==BLACK) ||
                            (p_st == OWN_BY_WHITE && c == WHITE))
                    new_g_st = ALIVE;

                if(block_status[b] == UNKNOWN)
                    block_status[b] = new_g_st;
                else if (block_status[b] != new_g_st)
                    block_status[b] = UNKNOWN;
            }
        }
        else
            point_status[pt] = mcts_point_status(pt, owner_map);
    }
Example #2
0
void stereo::process( const cv::Mat& left, const cv::Mat& right, const cv::StereoSGBM& sgbm, boost::posix_time::ptime time )
{
    snark::imaging::point_cloud cloud( sgbm );

    cv::Mat points;
    cv::Mat leftRectified, rightRectified;
    if (!m_input_rectified)
    {
        leftRectified = m_rectify.remap_left( left );
        rightRectified = m_rectify.remap_right( right );
        points = cloud.get( m_rectify.Q(), leftRectified, rightRectified );
    }
    else
    {
        leftRectified = left;
        rightRectified = right;
        points = cloud.get( m_rectify.Q(), left, right );
    }

    for( int i = 0; i < points.rows; i++ )
    {
       for( int j = 0; j < points.cols; j++ )
       {
            cv::Point3f point = points.at< cv::Point3f >( i, j );

            if( std::fabs( point.z ) < 10000 ) // CV uses 10,000 as invalid. TODO config max distance ?
            {
                point *= 16.0; // disparity has a factor 16
                cv::Vec3b color = leftRectified.at< cv::Vec3b >( i, j );
                colored_point point_color( point.x, point.y, point.z, color[2], color[1], color[0] );
                point_color.time = time;
                point_color.block = m_frame_counter;
                if( m_binary )
                {
                    m_binary->put( point_color, &m_output[0] );
                    std::cout.write( &m_output[0], m_output.size() );
                    std::cout.flush();
                }
                else
                {
                    std::string line;
                    m_ascii->put( point_color, line );
                    std::cout << line << std::endl;
                }
            }
        }
    }
    m_frame_counter++;
}
Example #3
0
//====================================== Eyes =================================
char is_eyeish(Position *pos, Point pt)
// test if pt is inside a single-color diamond and return the diamond color or 0
// this could be an eye, but also a false one
{
    Color eyecolor=EMPTY, other=EMPTY;
    int k;
    Point n;
    FORALL_NEIGHBORS(pos, pt, k, n) {
        Color c = point_color(pos,n);
        if(c == OUT) continue;                // ignore OUT of board neighbours
        if(c == EMPTY) return 0;
        if(eyecolor == EMPTY) {
            eyecolor = c;
            other = color_other(c);
        }
        else if (c == other) return 0;
    }
Example #4
0
char* do_play(Game *game, Color c, Point pt)
// Play the move (updating the Game struct)
{
    char *ret;
    Color to_play_before;
    int   played=0;
    Info  m = 0;
    Position *pos = game->pos;

    to_play_before = board_color_to_play(pos);
    board_set_color_to_play(pos, c);

    if (point_color(pos,pt) == EMPTY) {
        ret = play_move(pos, pt);
        if (ret[0] == 0) {
            m = pt + (board_captured_neighbors(pos) << 9) 
                   + (board_ko_old(pos) << 13) 
                   + ((to_play_before) << 22);
            played = 1;
        }
        // else illegal move: nothing played
    }
    else if(pt == PASS_MOVE) {
        ret = pass_move(pos);
        m = pt + (board_captured_neighbors(pos) << 9) 
               + (board_ko_old(pos) << 13) 
               + ((to_play_before) << 22);
        played = 1;
    }
    else ret ="Error Illegal move: point not EMPTY\n";
    if (played) {
        c2++;
        slist_push(game->moves, m);
    }
    return ret;
}
Example #5
0
void
ui_result (global_t * gp)
{
  int p, i;
  int iy[4];
  char buf[1024];
  int n = 0;

  if (flag_pause && !auto_play && !BUILD4)
    {
      wait4key ();
    }
  if (!point)
    make_point ();
  if (BUILD4)
    wrap_widgets ();

  snd (audioplay_yaku ());
  flag_not_needredraw = 0;
  point_clear ();

  memcpy (hora_global, gp, sizeof (global_t));
  hora_reset ();

  for (p = 0; p < 4; p++)
    {
      if (result[p].flag == 0)
        {
          continue;
        }
      n++;
    }
  for (p = 0; p < 4; p++)
    {
      if (result[p].flag == 0)
        {
          continue;
        }

      if (result[p].flag != RESULT_RYUKYOKU && (result[p].who != -1))
        {
          hora_set (hora_global, result[p].who);
        }
      else
        {
          hora_set (hora_global, -1);
        }

      result_cvt_to_int (result + p, iy);
      pmcontainer_print (point_results, pm_result_name[result[p].flag]);

      for (i = 0; i < 4; i++)
        {
          integer_t color;
          pmcontainer_print (point_home[i], pm_home_names[i]);
          print_yakupoint (point_home_point[i], result[p].points[i]);

          widget_configure (point_home_user[i], resource_text,
                            player[pplayer[i]].name);
          color = point_color (result[p].points[i]);
          widget_configure (point_home_user[i], resource_textfont, MEDIUMJP);
          widget_configure (point_home_user[i], resource_textcolor, color);
          {
            extern integer_t *tblpos;
            color = point_bgcolor (result[p].points[i]);
            widget_model_change (name_frame[tblpos[i]], color, white, white,
                                 white);
          }
        }

      if (result[p].fu)
        {
          widget_configure (point_fubase, resource_invisible, 0);
          print_yakupoint (point_fu, result[p].fu);
          print_yakupoint (point_fan, result[p].fan);
        }
      else
        {
          widget_configure (point_fubase, resource_invisible, 1);
        }

#define yaku_idx(idx)  		\
		if (!point_yaku[idx]) { goto YAKUEND; }

      {
        integer_t idx = 0;
        for (i = 0; i < Y_MAX; i++)
          {
            if (Y_GET (iy, i))
              {
                char buf[128];
                int len, n;

                yaku_idx (idx);

                strcpy (buf, result_str[i]);
                len = strlen (buf);

                if (buf[len - 1] == ')' && buf[len - 3] == '(')
                  {
                    buf[len - 3] = buf[len - 1] = 0;
                    n = buf[len - 2] - '0';
                    print_yakupoint (point_yaku_point[idx], n);
                  }
                else
                  {
                    widget_configure (point_yaku_point[idx], resource_text,
                                      "");
                  }
                widget_configure (point_yaku[idx], resource_text, buf);
                idx++;
              }
          }

        if (result[p].dora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, dora_str);
            print_yakupoint (point_yaku_point[idx], result[p].dora);
            idx++;
          }
        if (result[p].uradora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, uradora_str);
            print_yakupoint (point_yaku_point[idx], result[p].uradora);
            idx++;
          }
        if (result[p].akadora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, akadora_str);
            print_yakupoint (point_yaku_point[idx], result[p].akadora);
            idx++;
          }
        for (; idx < 30; idx++)
          {
            if (!point_yaku[idx])
              {
                continue;
              }
            widget_configure (point_yaku[idx], resource_text, "");
            widget_configure (point_yaku_point[idx], resource_text, "");
          }
      }
    YAKUEND:
      draw_hora ();
      {
        extern widget_t board;
        if (!BUILD4)
          {
            widget_unmap (board);
          }
        widget_map (point);
        widget_display (point);
        widget_flush (point);
        {
          for (i = 0; i < 4; i++)
            {
              widget_display (name_frame[i]);
              widget_flush (name_frame[i]);
            }
        }

        if (!auto_play)
          wait_key ();

        hora_reset ();
      }
    }

  linepos_clear ();
  for (i = 0; i < 4; i++)
    {
      widget_model_change (name_frame[i], get_basiccolorpixel (), white,
                           white, white);
    }
  if (!BUILD4)
    {
      widget_unmap (point);
    }
  else
    {
      unwrap_widgets ();
    }
  board_reset ();
  board_redraw (1);

  if (logfile)
    log_play (gp, logfile);
}