Пример #1
0
int main(int argc, char** argv) {

  struct Tile* t = Tile_new('f');
  printf("tile %c\n", t->color);

  struct Board* b = Board_new(9,9);
  struct Tile* t2 = Board_get(b,0,0);
  
  printf("tile %c\n", t2->color);


  Board_print(b);

  Board_randomize(b);

  Board_print(b);

  struct Board* b2 = Board_clone(b);

  int matches;

  matches = Board_check_matching_at(b2, 0, 4);

  printf("board matches %i\n", matches);

  return 0;
}
Пример #2
0
int evalBoard(const Board* board, int color){
    int x;
    int y;
    int eval = 0;

    for(x = 0; x < OTHELLO_X_MAX; x++){
        for(y = 0; y < OTHELLO_Y_MAX; y++){
            if(Board_get(board, x, y) == color){
                eval++;
            }
        }
    }

    return eval;
}
Пример #3
0
void Board_set(struct Board* board, int x, int y, char color) {
  struct Tile* t = Board_get(board, x, y);
  t->color = color;
}
Пример #4
0
int Board_check_matching_at(struct Board* board, int x, int y) {
  // check if 3 or more in a row here, or other special patterns

  int colorhere = Board_get(board, x, y)->color;

  int match_up = 0;
  int match_down = 0;
  int match_left = 0;
  int match_right = 0;

  int cx;
  int cy;

  cx = x;
  while (1) {
    cx--;
    if (cx < 0 || cx >= board->width) {
      break;
    }
    if (colorhere == Board_get(board, cx, y)->color) {
      match_left++;
    } else {
      break;
    }
  }

  cx = x;
  while (1) {
    cx++;
    if (cx < 0 || cx >= board->width) {
      break;
    }
    printf("colors %c %c\n", colorhere, Board_get(board, cx, y)->color);
    if (colorhere == Board_get(board, cx, y)->color) {
      match_right++;
    } else {
      break;
    }
  }

  cy = y;
  while (1) {
    cy--;
    if (cy < 0 || cy >= board->height) {
      break;
    }
    if (colorhere == Board_get(board, x, cy)->color) {
      match_up++;
    } else {
      break;
    }
  }

  cy = y;
  while (1) {
    cy++;
    if (cy < 0 || cy >= board->height) {
      break;
    }
    if (colorhere == Board_get(board, x, cy)->color) {
      match_down++;
    } else {
      break;
    }
  }


  printf("matching %i %i %i %i\n", match_left, match_right, match_up, match_down);

  return 
    (match_left + match_right >= 2)
    || (match_up + match_down >= 2);
}