本文整理汇总了C++中POS函数的典型用法代码示例。如果您正苦于以下问题:C++ POS函数的具体用法?C++ POS怎么用?C++ POS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了POS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: POS
bool chain::evaluating_chain(int black_live_eye_arr[], int white_live_eye_arr[])
{
this->live = 0;
list<stone*> try_position;
int forbid = 0;
int forbiden[5] = {-1,-1,-1,-1,-1};
int S[BOARD_SIZE*BOARD_SIZE];
for (int i = 0; i < BOARD_SIZE*BOARD_SIZE; i++) S[i] = 0;
for (std::list<stone*>::iterator itor = this->stones.begin(); itor != this->stones.end(); ++itor)
{
for (int i = 0; i < 4; i++)
{
int row = (*itor)->row + deltai[i];
int col = (*itor)->col + deltaj[i];
int index = POS(row,col);
stone* curr = chain_block->block_board->main_board[index];
if (chain_block->block_board->on_board(row, col))
{
if (curr->color == EMPTY)
{
if (S[index] != 0) continue;
S[index] = 1;
curr->color = OTHER_COLOR(chain_block->color);
if (curr->eat_this_chain(this))
{
try_position.push_back(curr);
std::list<stone*>::iterator itor2 = try_position.begin();
while (itor2 != try_position.end())
{
if (chain_block->color == BLACK){
black_live_eye_arr[POS((*itor2)->row, (*itor2)->col)] = 1; //try_position不是白棋的真眼
}
else{
white_live_eye_arr[POS((*itor2)->row, (*itor2)->col)] = 1; //try_position不是黑棋的真眼
}
(*itor2)->color = EMPTY;
try_position.erase(itor2++);
}
this->live = 0;
return 1;
}
else if (curr->can_live(this))
{
try_position.push_back(curr);
}
else //Neither to eat this chain nor to live
{
curr->color = EMPTY;
S[index] = 2;
}
}
}
}
}
int count = 0;
for (int i = 0; i < BOARD_SIZE*BOARD_SIZE; i++){
if (S[i] == 2) count++;
}
if (count < 2)
{
//S[i]周围不能是live eye
for (int i = 0; i < BOARD_SIZE*BOARD_SIZE; i++){
if (S[i] == 2) {
if (chain_block->color == BLACK){
black_live_eye_arr[i] = 1; //try_position不是白棋的真眼
}
else{
white_live_eye_arr[i] = 1; //try_position不是黑棋的真眼
}
queue<int> q;
q.push(i);
not_live_eye_bfs(this, OTHER_COLOR(this->chain_block->color), q, black_live_eye_arr, white_live_eye_arr);
}
}
std::list<stone*>::iterator itor2 = try_position.begin();
while (itor2 != try_position.end())
{
if (chain_block->color == BLACK){
black_live_eye_arr[POS((*itor2)->row, (*itor2)->col)] = 1; //try_position不是白棋的真眼
}
else{
white_live_eye_arr[POS((*itor2)->row, (*itor2)->col)] = 1; //try_position不是黑棋的真眼
}
(*itor2)->color = EMPTY;
try_position.erase(itor2++);
}
this->live = 0;
}
else
{
for (int i = 0; i < BOARD_SIZE*BOARD_SIZE; i++){
if (S[i] == 2) {
if (chain_block->color == BLACK){
if (black_live_eye_arr[i] != 1) black_live_eye_arr[i] = 2; //可能是白棋的真眼
}
else{
if (white_live_eye_arr[i] != 1) white_live_eye_arr[i] = 2; //可能是黑棋的真眼
}
//.........这里部分代码省略.........
示例2: play_move
/* Play at (i, j) for color. No legality check is done here. We need
* to properly update the board array, the next_stone array, and the
* ko point.
*/
static void
play_move(int i, int j, int color)
{
int pos = POS(i, j);
int captured_stones = 0;
int k;
/* Reset the ko point. */
ko_i = -1;
ko_j = -1;
/* Nothing more happens if the move was a pass. */
if (pass_move(i, j))
return;
/* If the move is a suicide we only need to remove the adjacent
* friendly stones.
*/
if (suicide(i, j, color)) {
for (k = 0; k < 4; k++) {
int ai = i + deltai[k];
int aj = j + deltaj[k];
if (on_board(ai, aj)
&& get_board(ai, aj) == color)
remove_string(ai, aj);
}
return;
}
/* Not suicide. Remove captured opponent strings. */
for (k = 0; k < 4; k++) {
int ai = i + deltai[k];
int aj = j + deltaj[k];
if (on_board(ai, aj)
&& get_board(ai, aj) == OTHER_COLOR(color)
&& !has_additional_liberty(ai, aj, i, j))
captured_stones += remove_string(ai, aj);
}
/* Put down the new stone. Initially build a single stone string by
* setting next_stone[pos] pointing to itself.
*/
board[pos] = color;
next_stone[pos] = pos;
/* If we have friendly neighbor strings we need to link the strings
* together.
*/
for (k = 0; k < 4; k++) {
int ai = i + deltai[k];
int aj = j + deltaj[k];
int pos2 = POS(ai, aj);
/* Make sure that the stones are not already linked together. This
* may happen if the same string neighbors the new stone in more
* than one direction.
*/
if (on_board(ai, aj) && board[pos2] == color && !same_string(pos, pos2)) {
/* The strings are linked together simply by swapping the the
* next_stone pointers.
*/
int tmp = next_stone[pos2];
next_stone[pos2] = next_stone[pos];
next_stone[pos] = tmp;
}
}
/* If we have captured exactly one stone and the new string is a
* single stone it may have been a ko capture.
*/
if (captured_stones == 1 && next_stone[pos] == pos) {
int ai, aj;
/* Check whether the new string has exactly one liberty. If so it
* would be an illegal ko capture to play there immediately. We
* know that there must be a liberty immediately adjacent to the
* new stone since we captured one stone.
*/
for (k = 0; k < 4; k++) {
ai = i + deltai[k];
aj = j + deltaj[k];
if (on_board(ai, aj) && get_board(ai, aj) == EMPTY)
break;
}
if (!has_additional_liberty(i, j, ai, aj)) {
ko_i = ai;
ko_j = aj;
}
}
}
示例3: pegue_palitos
int pegue_palitos(struct jogad jogador[] , int num, int rodadas, int total_palitos )
{
int i;
int palitos;
do { // pegar a quantidade de palitos do jogador humano
// posicao inicial das mensagens
i=18;
JANELA2();
POS (i++,5);
printf ("Você possui [%d] palitos, há [%2d] palitos em jogo", jogador[0].tpalitos, total_palitos);
POS (i++,5);
printf ("Jogador, digite quantos palitos quer jogar, para sair [-1]: ");
// muda palitos antes do condicional,
// isto previne sair do programa quando palitos == -1
scanf("%d", &palitos);
// caso se escolha -1, isto eh sair do jogo
if ( palitos == -1) {
tela_saida(); //mostra tela de saída
exit(0); //saí do jogo
}
if ( (palitos < 0) || ( palitos > jogador[0].tpalitos) ) {
STATUS();
printf("Quantidade inválida de palitos");
}
;;
if ((rodadas == 1) && (palitos == 0)) {
STATUS();
printf("Na primeira rodada a quantidade de palitos deve ser maior que 0");
palitos= -1; // para não sair no laço pois continue não funcionou
}
;;
} while ( (palitos < 0) || ( palitos > jogador[0].tpalitos) );
;;
jogador[0].palitos = palitos;
for (i = 1; i < num + 1; i++) {
// gera um numero de palitos a jogar por numeros aleatorios
// inteligencia=0.
jogador[i].palitos = aleatorio(jogador[i].tpalitos);
if ((rodadas == 1) && (jogador[i].palitos == 0))
i--; // decrementa i para permanecer no mesmo jogador
;;
}
;;
palitos = 0;
for (i = 0; i <= num ; i++)
palitos += jogador[i].palitos; //total de palitos
;;
return(palitos);
}
示例4: POS
//-----------------------------------------------------------------------------------------------
void CRenderCamera::GetPos ( tVect3& vOutPos )const
{
vOutPos = POS(m_TM);
}
示例5: compute_surroundings
//.........这里部分代码省略.........
&& sd[i] < sd[dpos]
&& square_dist(i, dpos) < sd[dpos]) {
for (j = i + 1; j < BOARDMAX; j++)
if (ON_BOARD(j) && mn[j] && j != dpos
&& sd[j] < sd[dpos]
&& square_dist(j, dpos) < sd[dpos]
&& square_dist(i, j) < sd[dpos]) {
mn[dpos] = 0;
found_some = 1;
break;
}
if (mn[dpos] == 0)
break;
}
}
} while (found_some);
/* prepare corner array */
for (dpos = BOARDMIN; dpos < BOARDMAX; dpos++)
if (ON_BOARD(dpos) && mn[dpos])
corner[corners++] = dpos;
/* compute gravity center of the goal */
for (dpos = BOARDMIN; dpos < BOARDMAX; dpos++)
if (ON_BOARD(dpos) && mf[dpos]) {
gi += I(dpos);
gj += J(dpos);
stones++;
}
gi /= stones;
gj /= stones;
gg = POS(gi, gj);
/* sort the corner array */
gg_sort(corner, corners, sizeof(int), compare_angles);
/* if apos is not NO_MOVE, mark it. */
if (apos != NO_MOVE) {
ASSERT_ON_BOARD1(apos);
mn[apos] = 1;
}
if (showboard == 1) {
show_surround_map(mf, mn);
}
/* find top row of surrounding polyhedron */
top_row = -1;
for (m = 0; m < board_size; m++) {
if (top_row != -1)
break;
for (n = 0; n < board_size; n++)
if (mn[POS(m, n)]) {
left_corner[0] = POS(m, n);
top_row = m;
break;
}
}
/* find bottom row */
示例6: FUNC
//.........这里部分代码省略.........
pixel *left = left_array + 1;
pixel *top = top_array + 1;
pixel *filtered_left = filtered_left_array + 1;
pixel *filtered_top = filtered_top_array + 1;
int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb - 1, y_tb + size_in_tbs_v);
int cand_left = lc->na.cand_left;
int cand_up_left = lc->na.cand_up_left;
int cand_up = lc->na.cand_up;
int cand_up_right = lc->na.cand_up_right && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb + size_in_tbs_h, y_tb - 1);
int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, s->sps->height) -
(y0 + size_in_luma_v)) >> vshift;
int top_right_size = (FFMIN(x0 + 2 * size_in_luma_h, s->sps->width) -
(x0 + size_in_luma_h)) >> hshift;
if (s->pps->constrained_intra_pred_flag == 1) {
int size_in_luma_pu_v = PU(size_in_luma_v);
int size_in_luma_pu_h = PU(size_in_luma_h);
int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_bottom_pu = PU(y0 + size_in_luma_v);
int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_bottom_pu);
cand_bottom_left = 0;
for (i = 0; i < max; i += 2)
cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i).pred_flag == PF_INTRA);
}
if (cand_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_left_pu = PU(y0);
int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_left_pu);
cand_left = 0;
for (i = 0; i < max; i += 2)
cand_left |= (MVF(x_left_pu, y_left_pu + i).pred_flag == PF_INTRA);
}
if (cand_up_left == 1) {
int x_left_pu = PU(x0 - 1);
int y_top_pu = PU(y0 - 1);
cand_up_left = MVF(x_left_pu, y_top_pu).pred_flag == PF_INTRA;
}
if (cand_up == 1 && on_pu_edge_y) {
int x_top_pu = PU(x0);
int y_top_pu = PU(y0 - 1);
int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_top_pu);
cand_up = 0;
for (i = 0; i < max; i += 2)
cand_up |= (MVF(x_top_pu + i, y_top_pu).pred_flag == PF_INTRA);
}
if (cand_up_right == 1 && on_pu_edge_y) {
int y_top_pu = PU(y0 - 1);
int x_right_pu = PU(x0 + size_in_luma_h);
int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_right_pu);
cand_up_right = 0;
for (i = 0; i < max; i += 2)
cand_up_right |= (MVF(x_right_pu + i, y_top_pu).pred_flag == PF_INTRA);
}
memset(left, 128, 2 * MAX_TB_SIZE*sizeof(pixel));
memset(top , 128, 2 * MAX_TB_SIZE*sizeof(pixel));
top[-1] = 128;
}
if (cand_up_left) {
left[-1] = POS(-1, -1);
top[-1] = left[-1];
}
if (cand_up)
memcpy(top, src - stride, size * sizeof(pixel));
if (cand_up_right) {
memcpy(top + size, src - stride + size, size * sizeof(pixel));
EXTEND(top + size + top_right_size, POS(size + top_right_size - 1, -1),
size - top_right_size);
}
if (cand_left)
for (i = 0; i < size; i++)
left[i] = POS(-1, i);
if (cand_bottom_left) {
for (i = size; i < size + bottom_left_size; i++)
left[i] = POS(-1, i);
EXTEND(left + size + bottom_left_size, POS(-1, size + bottom_left_size - 1),
size - bottom_left_size);
}
if (s->pps->constrained_intra_pred_flag == 1) {
if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) {
int size_max_x = x0 + ((2 * size) << hshift) < s->sps->width ?
2 * size : (s->sps->width - x0) >> hshift;
int size_max_y = y0 + ((2 * size) << vshift) < s->sps->height ?
2 * size : (s->sps->height - y0) >> vshift;
int j = size + (cand_bottom_left? bottom_left_size: 0) -1;
if (!cand_up_right) {
size_max_x = x0 + ((size) << hshift) < s->sps->width ?
size : (s->sps->width - x0) >> hshift;
}
if (!cand_bottom_left) {
size_max_y = y0 + (( size) << vshift) < s->sps->height ?
size : (s->sps->height - y0) >> vshift;
}
示例7: if
/**
* Create the adjacency list for each position on the board. An example of the
* board for size of 15 is shown below. The edges are created for a position in
* a clockwise manner.
* *---*---*---*---*
* |0 |1 |2 |3 |
* *---*---*---*---*
* |4 |5 |6 |7 |
* *---*---*---*---*
* |8 |9 |10 |11 |
* *---*---*---*---*
* |12 |13 |14 |15 |
* *---*---*---*---*
* @param row
* @param col
*/
void GemPuzzleState::MakeEdges(int row, int col,vector<int>& list) {
if (row == 0) {
if (col == 0) {
list.push_back(POS((row), (col + 1), _dim));
list.push_back(POS((row + 1), (col), _dim));
} else if (col == _dim - 1) {
list.push_back(POS((row + 1), (col), _dim));
list.push_back(POS((row), (col - 1), _dim));
} else {
list.push_back(POS(row, (col + 1), _dim));
list.push_back(POS((row + 1), col, _dim));
list.push_back(POS(row, (col - 1), _dim));
}
} else if (row == _dim - 1) {
if (col == 0) {
list.push_back(POS((row-1), (col), _dim));
list.push_back(POS((row), (col+1), _dim));
} else if (col == _dim - 1) {
list.push_back(POS((row), (col-1), _dim));
list.push_back(POS((row-1), (col), _dim));
} else {
list.push_back(POS((row), (col-1), _dim));
list.push_back(POS((row-1), (col), _dim));
list.push_back(POS((row), (col+1), _dim));
}
} else {
if (col == 0) {
list.push_back(POS((row-1), (col), _dim));
list.push_back(POS((row), (col+1), _dim));
list.push_back(POS((row+1), (col), _dim));
} else if (col == _dim - 1) {
list.push_back(POS((row+1), (col), _dim));
list.push_back(POS((row), (col-1), _dim));
list.push_back(POS((row-1), (col), _dim));
} else {
list.push_back(POS((row-1), (col), _dim));
list.push_back(POS((row), (col+1), _dim));
list.push_back(POS((row+1), (col), _dim));
list.push_back(POS((row), (col-1), _dim));
}
}
}
示例8: set_hchar
static inline void set_hchar(struct part *p, int x, int y, unsigned c)
{
xpand_lines(p, y);
xpand_line(p, y, x);
POS(x, y) = c;
}
示例9: aftermath_genmove
//.........这里部分代码省略.........
}
else if (d > 0 && board[pos] == color) {
distance[pos] = d + 1;
if (closest_own == NO_MOVE)
closest_own = pos;
}
else if (board[pos] == EMPTY) {
distance[pos] = d + 1;
something_found = 1;
}
break;
}
}
}
}
d++;
} while (something_found);
if (under_control) {
for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
if (!ON_BOARD(pos))
continue;
else if (distance[pos] == -1)
under_control[pos] = 0;
else
under_control[pos] = 1;
}
}
if (debug & DEBUG_AFTERMATH) {
int m, n;
for (m = 0; m < board_size; m++) {
for (n = 0; n < board_size; n++) {
pos = POS(m, n);
if (distance[pos] > 0)
fprintf(stderr, "%2d", distance[pos]);
else if (distance[pos] == 0) {
if (board[pos] == WHITE)
gprintf(" o");
else if (board[pos] == BLACK)
gprintf(" x");
else
gprintf(" ?");
}
else {
if (board[pos] == WHITE)
gprintf(" O");
else if (board[pos] == BLACK)
gprintf(" X");
else
gprintf(" .");
}
}
gprintf("\n");
}
gprintf("Closest opponent %1m", closest_opponent);
if (closest_opponent != NO_MOVE)
gprintf(", distance %d\n", distance[closest_opponent]);
else
gprintf("\n");
gprintf("Closest own %1m", closest_own);
if (closest_own != NO_MOVE)
gprintf(", distance %d\n", distance[closest_own]);
else
示例10: weibo_user_create_json
pweibo_user weibo_user_create_json(json_t* pJson)
{
if (!pJson) {
PERR("could not parse json!\n");
return NULL;
}
void *iter = json_object_iter(pJson);
pweibo_user pUser = weibo_user_init();
while (iter) {
const char* key = json_object_iter_key(iter);
//DEBUG("%s\n", key);
json_t *value = json_object_iter_value(iter);
if(!value) {
iter = json_object_iter_next(pJson, iter);
continue;
}
//DEBUG("%d\n", value->type);
if (0 == strcmp("id", key)) {
pUser->m_szID = g_string_new("");
g_string_printf(pUser->m_szID, "%"JSON_INTEGER_FORMAT, json_integer_value(value));
} else if (0 == strcmp("screen_name", key)) {
pUser->m_szScreenName = g_string_new(json_string_value(value));
} else if (0 == strcmp("name", key)) {
pUser->m_szName = g_string_new(json_string_value(value));
} else if (0 == strcmp("province", key)) {
pUser->m_nProvince = json_integer_value(value);
} else if (0 == strcmp("city", key)) {
pUser->m_nCity = json_integer_value(value);
} else if (0 == strcmp("location", key)) {
pUser->m_szLocation = g_string_new(json_string_value(value));
} else if (0 == strcmp("description", key)) {
pUser->m_szDescription = g_string_new(json_string_value(value));
} else if (0 == strcmp("url", key)) {
pUser->m_szUrl = g_string_new(json_string_value(value));
} else if (0 == strcmp("profile_image_url", key)) {
pUser->m_szProfileImageUrl = g_string_new(json_string_value(value));
} else if (0 == strcmp("domain", key)) {
pUser->m_szDomain = g_string_new(json_string_value(value));
} else if (0 == strcmp("gender", key)) {
pUser->m_szGender = g_string_new(json_string_value(value));
} else if (0 == strcmp("followers_count", key)) {
pUser->m_nFollowersCount = json_integer_value(value);
} else if (0 == strcmp("friends_count", key)) {
pUser->m_nFriendsCount = json_integer_value(value);
} else if (0 == strcmp("statuses_count", key)) {
pUser->m_nStatusesCount = json_integer_value(value);
} else if (0 == strcmp("favourites_count", key)) {
pUser->m_nFavouritesCount = json_integer_value(value);
} else if (0 == strcmp("created_at", key)) {
pUser->m_szCreatedAt = g_string_new(json_string_value(value));
} else if (0 == strcmp("following", key)) {
pUser->m_bFollowing = json_is_true(value) ? TRUE : FALSE;
} else if (0 == strcmp("allow_all_act_msg", key)) {
pUser->m_bAllowAllActMsg = json_is_true(value) ? TRUE : FALSE;
} else if (0 == strcmp("geo_enabled", key)) {
pUser->m_bGeoEnabled = json_is_true(value) ? TRUE : FALSE;
} else if (0 == strcmp("verified", key)) {
pUser->m_bVerified = json_is_true(value) ? TRUE : FALSE;
} else if (0 == strcmp("status", key)) {
PERR("%s-->%d\n", key, value->type);
POS();
pUser->m_pFeed = weibo_feed_create_json(value);
PERR("%d\n", pUser->m_pFeed);
PERR("%s\n", ((pweibo_feed)(pUser->m_pFeed))->m_szID->str);
}
iter = json_object_iter_next(pJson, iter);
}
json_decref(pJson);
return pUser;
}
示例11: showchar
static void
showchar(int i, int j, int empty, int xo)
{
struct dragon_data *d; /* dragon data at (i, j) */
struct dragon_data2 *d2;
int x;
ASSERT_ON_BOARD2(i, j);
x = BOARD(i, j);
d = &(dragon[POS(i, j)]);
d2 = &(dragon2[d->id]);
if (x == EMPTY) {
if (xo != 2)
fprintf(stderr, " %c", empty);
else {
int empty_color;
char empty_char;
if (black_eye[POS(i, j)].color == BLACK) {
if (white_eye[POS(i, j)].color == WHITE)
empty_color = domain_colors[3];
else
empty_color = domain_colors[1];
if (black_eye[POS(i, j)].marginal)
empty_char = '!';
else
empty_char = 'x';
}
else if (white_eye[POS(i, j)].color == WHITE) {
empty_color = domain_colors[2];
if (white_eye[POS(i, j)].marginal)
empty_char = '!';
else
empty_char = 'o';
}
else {
empty_color = domain_colors[0];
empty_char = '.';
}
write_color_char(empty_color, empty_char);
}
}
else {
int w;
if (xo == 0 || ! ON_BOARD1(d->origin)) {
fprintf(stderr, " %c", BOARD(i, j) == BLACK ? 'X' : 'O');
return;
}
/* Figure out ascii character for this dragon. This is the
* dragon number allocated to the origin of this worm. */
w = dragon_num[d->origin];
if (!w) {
/* Not yet allocated - allocate next one. */
/* Count upwards for black, downwards for white to reduce confusion. */
if (BOARD(i, j) == BLACK)
w = dragon_num[d->origin] = next_black++;
else
w = dragon_num[d->origin] = next_white--;
}
w = w%26 + (BOARD(i, j) == BLACK ? 'A' : 'a');
/* Now draw it. */
if (xo == 1)
write_color_char(colors[BOARD(i, j)][d->crude_status], w);
else if (xo == 2) {
if (BOARD(i, j) == BLACK)
write_color_char(domain_colors[1], 'X');
else
write_color_char(domain_colors[2], 'O');
}
else if (xo == 3)
write_color_char(colors[BOARD(i, j)][d2->owl_status], w);
else if (xo == 4)
write_color_char(colors[BOARD(i, j)][d->status], w);
}
}
示例12: play_solo
void
play_solo(Gameinfo *gameinfo, int moves)
{
SGFTree sgftree;
int passes = 0; /* num. consecutive passes */
float move_value;
double t1, t2;
int save_moves = moves;
struct stats_data totalstats;
int total_owl_count = 0;
/* It tends not to be very imaginative in the opening,
* so we scatter a few stones randomly to start with.
* We add two random numbers to reduce the probability
* of playing stones near the edge.
*/
int n = 6 + 2*gg_rand()%5;
int i, j;
komi = 5.5;
sgftree_clear(&sgftree);
sgftreeCreateHeaderNode(&sgftree, board_size, komi, handicap);
sgf_write_header(sgftree.root, 1, get_random_seed(), 5.5, handicap,
get_level(), chinese_rules);
/* Generate some random moves. */
if (board_size > 6) {
do {
do {
i = (gg_rand() % 4) + (gg_rand() % (board_size - 4));
j = (gg_rand() % 4) + (gg_rand() % (board_size - 4));
} while (!is_allowed_move(POS(i, j), gameinfo->to_move));
gnugo_play_move(POS(i, j), gameinfo->to_move);
sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j);
sgftreeAddComment(&sgftree, "random move");
gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
} while (--n > 0);
}
t1 = gg_cputime();
memset(&totalstats, '\0', sizeof(totalstats));
while (passes < 2 && --moves >= 0) {
int move;
reset_owl_node_counter();
move = genmove(gameinfo->to_move, &move_value, NULL);
gnugo_play_move(move, gameinfo->to_move);
sgffile_add_debuginfo(sgftree.lastnode, move_value);
sgftreeAddPlay(&sgftree, gameinfo->to_move, I(move), J(move));
sgffile_output(&sgftree);
gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
if (move == PASS_MOVE) {
passes++;
printf("%s(%d): Pass\n", gameinfo->to_move == BLACK ? "Black" : "White",
movenum);
}
else {
passes = 0;
gprintf("%s(%d): %1m\n", gameinfo->to_move == BLACK ? "Black" : "White",
movenum, move);
}
totalstats.nodes += stats.nodes;
totalstats.read_result_entered += stats.read_result_entered;
totalstats.read_result_hits += stats.read_result_hits;
totalstats.trusted_read_result_hits += stats.trusted_read_result_hits;
total_owl_count += get_owl_node_counter();
}
t2 = gg_cputime();
/* Two passes and it's over. (EMPTY == BOTH) */
who_wins(EMPTY, stdout);
{
float score = gnugo_estimate_score(NULL, NULL);
sgfWriteResult(sgftree.root, score, 1);
}
sgffile_output(&sgftree);
printf("%10d moves played in %0.3f seconds\n", save_moves-moves, t2-t1);
if (save_moves != moves)
printf("%10.3f seconds/move\n", (t2-t1)/(save_moves-moves));
printf("%10d nodes\n", totalstats.nodes);
printf("%10d read results entered\n", totalstats.read_result_entered);
printf("%10d read result hits\n", totalstats.read_result_hits);
printf("%10d trusted read result hits\n",
totalstats.trusted_read_result_hits);
printf("%10d owl nodes\n", total_owl_count);
}
示例13: if
bool stone::empty_redistribution()
{
int except = -1;
int target;
if (s_influence > 0){ target = BLACK; }
else if (s_influence < 0){ target = WHITE; }
else {
if (stone_block == NULL) return 1;
else
{
stone_block->empty.remove(this);
stone_block = NULL;
return 1;
}
}
//BFS
int visited[BOARD_SIZE*BOARD_SIZE];
memset(visited, 0, sizeof(visited));
queue <int> q;
q.push(POS(row, col));
visited[POS(row, col)] = 1;
while (!q.empty())
{
int top;
int mark = 0;
top = q.front();
q.pop();
for (int k = 0; k < 4; k++)
{
if (stone_board->on_board(I(top) + deltai[k], J(top) + deltaj[k]))
{
int index = POS(I(top) + deltai[k], J(top) + deltaj[k]);
if (stone_board->main_board[index]->color == EMPTY)
{
if (visited[index] == 0) {
visited[index] = 1;
q.push(index);
}
}
else if (stone_board->main_board[index]->color == OTHER_COLOR(target) && color == EMPTY && mark == 0)
{
except = index;
mark = 1;
continue;
}
else if (stone_board->main_board[index]->color == OTHER_COLOR(target) && color == EMPTY && mark == 1)
{
continue;
}
else if (stone_board->main_board[index]->color == target && color == EMPTY)
{
//IF: check if it is already in
for (std::list<stone*>::iterator itor2 = stone_board->main_board[index]->stone_block->empty.begin(); itor2 != stone_board->main_board[index]->stone_block->empty.end(); ++itor2)
{
if (POS((*itor2)->row, (*itor2)->col) == POS(row, col)){
return 1;
}
}
//ELSE: delete the orignial term, add to the new list
if (this->stone_block != NULL)
{
for (std::list<stone*>::iterator itor = this->stone_block->empty.begin(); itor != this->stone_block->empty.end(); itor++)
{
if (POS((*itor)->row, (*itor)->col) == POS(row, col))
{
this->stone_block->empty.erase(itor);
break;
}
}
}
stone_board->main_board[index]->stone_block->empty.push_back(this);
//mark the stone block
this->stone_block = stone_board->main_board[index]->stone_block;
return 1;
}
}
}
}
if (except == -1)
{
return 0;
} //Impossible
//except: the influence is negative, but it's surrounded by blacks
//It's already in the "except" black block
for (std::list<stone*>::iterator itor = stone_board->main_board[except]->stone_block->empty.begin(); itor != stone_board->main_board[except]->stone_block->empty.end(); ++itor)
{
if (POS((*itor)->row, (*itor)->col) == POS(row, col)){ return 1; }
}
//ELSE: delete the orignial term, add to the new list
this->stone_block->empty.remove(this);
stone_board->main_board[except]->stone_block->empty.push_back(this);
//mark the stone block
this->stone_block = stone_board->main_board[except]->stone_block;
return 1;
}
示例14: draw_planet
void draw_planet(HDC hDC, planetstruct *planet)
{
HBRUSH hbrColor, hbrOld;
gravstruct *gp = &gravs;
double D; // a DX variable to work with
unsigned char cmpt;
D = POS(X) * POS(X) + POS(Y) * POS(Y) + POS(Z) * POS(Z);
if (D < COLLIDE)
D = COLLIDE;
D = sqrt(D);
D = D * D * D;
for (cmpt = X; cmpt < DIMENSIONS; cmpt++) {
ACC(cmpt) = POS(cmpt) * GRAV / D;
if (iDamping) {
if (ACC(cmpt) > MaxA)
ACC(cmpt) = MaxA;
else if (ACC(cmpt) < -MaxA)
ACC(cmpt) = -MaxA;
VEL(cmpt) = VEL(cmpt) + ACC(cmpt);
VEL(cmpt) *= DAMP;
} else {
// update velocity
VEL(cmpt) = VEL(cmpt) + ACC(cmpt);
}
// update position
POS(cmpt) = POS(cmpt) + VEL(cmpt);
}
gp->x = planet->xi;
gp->y = planet->yi;
if (POS(Z) > -ALMOST) {
planet->xi = (unsigned int)
((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
planet->yi = (unsigned int)
((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
}
else
planet->xi = planet->yi = -1;
// Mask
hbrOld = (HBRUSH)SelectObject(hDC, (HBRUSH)GetStockObject(BLACK_BRUSH));
Planet(gp->x, gp->y);
if (iTrails)
SetPixel(hDC, gp->x, gp->y, PALETTEINDEX(100));
// Move
gp->x = planet->xi;
gp->y = planet->yi;
planet->ri = RADIUS;
if (iColorCycle) {
if (planet->colors++ > (PALSIZE-21))
planet->colors = 1;
}
// Redraw
hbrColor = CreateSolidBrush(PALETTEINDEX(planet->colors));
SelectObject(hDC, hbrColor);
Planet(gp->x, gp->y);
SelectObject(hDC, hbrOld);
DeleteObject(hbrColor);
}
示例15: set_hchars
static inline void set_hchars(struct part *p, int x, int y, int xl, unsigned c)
{
xpand_lines(p, y);
xpand_line(p, y, x+xl-1);
for (; xl; xl--, x++) POS(x, y) = c;
}