Coord_t random_adjacent_coord(const Table_t *shots_table, const ProbTable_t *prob_table, const Coord_t *coord) { Coord_t temp; int rowShift[] = {-1, 0, 1, 0}; int colShift[] = {0, 1, 0, -1}; int highest_prob = 0; int index; for (index = 0; index < 4; index++) { temp.row = coord->row + rowShift[index]; temp.col = coord->col + colShift[index]; if (is_valid_coord(&temp, shots_table->dim) && shots_table->grid[temp.row][temp.col] == UNKNOWN && prob_table->table[temp.row][temp.col] > highest_prob) highest_prob = prob_table->table[temp.row][temp.col]; } do { index = rand() % 4; temp.row = coord->row + rowShift[index]; temp.col = coord->col + colShift[index]; } while (!is_valid_coord(&temp, shots_table->dim) || shots_table->grid[temp.row][temp.col] != UNKNOWN || prob_table->table[temp.row][temp.col] < highest_prob); return temp; }
/* tries to create move from coords. if either coord is not in the correct format (e.g. B4), return FALSE */ BOOLEAN try_create_move_from_coords(struct move *move, char *start_coord, char *end_coord) { if (is_valid_coord(start_coord) && is_valid_coord(end_coord)) { move->start = create_position_from_coord(start_coord); move->end = create_position_from_coord(end_coord); return TRUE; } else return FALSE; }
bool coord_eq (struct coord *_c0, struct coord *_c1) { assert (is_valid_coord (_c0) && is_valid_coord (_c1)); struct coord c0, c1; ncoord (_c0, &c0); ncoord (_c1, &c1); return c0.l == c1.l && c0.room == c1.room && c0.x == c1.x && c0.y == c1.y; }
void create_right_communication(){ int send_to_coords[2]; int send_to_rank; int recv_from_coords[2]; int recv_from_rank; send_to_coords[0] = my_coords[0]; send_to_coords[1] = my_coords[1] + 1; recv_from_coords[0] = my_coords[0]; recv_from_coords[1] = my_coords[1] - 1; if(is_valid_coord(send_to_coords)){ MPI_Cart_rank( grid_comm, send_to_coords, &send_to_rank ); MPI_Send_init( &grid[n], 1, column_t, send_to_rank, TAG, grid_comm, &horizontal_reqs[horizontal_req_index++] ); } recv_right_buffer = (int*) calloc(m+2, sizeof(int)); //initialize to 0 if(is_valid_coord(recv_from_coords)){ MPI_Cart_rank( grid_comm, recv_from_coords, &recv_from_rank ); MPI_Recv_init( recv_right_buffer, m + 2, MPI_INT, recv_from_rank, TAG, grid_comm, &horizontal_reqs[horizontal_req_index++] ); } }
void create_up_communication(){ int send_to_coords[2]; int send_to_rank; int recv_from_coords[2]; int recv_from_rank; send_to_coords[0] = my_coords[0] - 1; send_to_coords[1] = my_coords[1]; recv_from_coords[0] = my_coords[0] + 1; recv_from_coords[1] = my_coords[1]; if(is_valid_coord(send_to_coords)){ MPI_Cart_rank( grid_comm, send_to_coords, &send_to_rank ); MPI_Send_init( &grid[n+3], n, MPI_INT, send_to_rank, TAG, grid_comm, &vertical_reqs[vertical_req_index++] ); } if(is_valid_coord(recv_from_coords)){ MPI_Cart_rank( grid_comm, recv_from_coords, &recv_from_rank ); MPI_Recv_init( &grid[((n+2)*(m+2)) - (n+1)], n, MPI_INT, recv_from_rank, TAG, grid_comm, &vertical_reqs[vertical_req_index++] ); } }
struct pos * get_mouse_pos (struct pos *p) { struct mouse_coord m; get_mouse_coord (&m); if (! is_valid_coord (&m.c)) { invalid_pos (p); return p; } int ry = (m.c.y - 3) % PLACE_HEIGHT; pos_gen (&m.c, p, 0, 3); if (edit == EDIT_NONE) { invalid_pos (p); return p; } struct pos p0; switch (fake (p)) { case MIRROR: case CHOPPER: case WALL: case PILLAR: case BIG_PILLAR_TOP: case BIG_PILLAR_BOTTOM: case ARCH_BOTTOM: case ARCH_TOP_MID: case ARCH_TOP_SMALL: case ARCH_TOP_LEFT: case ARCH_TOP_RIGHT: break; default: if (is_arch_top (prel (p, &p0, +0, -1))) break; if (ry >= 60) pos_gen (&m.c, p, 0, 3); else if (ry >= 50) pos_gen (&m.c, p, 23 - 2.5 * (ry - 50), 3); else pos_gen (&m.c, p, 23, 3); break; } struct pos np; npos (p, &np); if (! np.room) { invalid_pos (p); return p; } return p; }