Пример #1
0
TEST(Record_Test, boardIterator) {
  // make this board
  // int init_array[][9] = {
  //   {0,1,1,1,0,0,0,0,0},
  //   {1,2,2,2,0,0,0,2,0},
  //   {0,1,2,2,1,0,0,0,0},
  //   {0,1,2,0,0,0,0,0,0},
  //   {0,0,1,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0}
  // };
  Record rec;
  rec.setBoardSize(9);

  vector<Record::Move> move_list;

  move_list.push_back(Record::Move(1,0));
  move_list.push_back(Record::Move(1,1));
  move_list.push_back(Record::Move(2,0));
  move_list.push_back(Record::Move(2,1));
  move_list.push_back(Record::Move(3,0));
  move_list.push_back(Record::Move(3,1));
  move_list.push_back(Record::Move(0,1));
  move_list.push_back(Record::Move(7,1));
  move_list.push_back(Record::Move(1,2));
  move_list.push_back(Record::Move(2,2));
  move_list.push_back(Record::Move(4,2));
  move_list.push_back(Record::Move(3,2));
  move_list.push_back(Record::Move(1,3));
  move_list.push_back(Record::Move(2,3));
  move_list.push_back(Record::Move(2,4));

  for (size_t i=0; i<move_list.size(); i++) {
    rec.addMove(move_list[i]);
  }

  Record::BoardIterator board_it = rec.createBoardIterator();
  EXPECT_EQ(9, board_it.getCurrentBoard().getSize());

  for (int x=0; x<9; x++) for (int y=0; y<9; y++) {
      EXPECT_EQ(FREE, board_it.getCurrentBoard().getStone(x,y));
  }

  int i=0;
  do {
    board_it.moveNext();
    Color c = i%2 == 0 ? BLACK : WHITE;

    const Board &board = board_it.getCurrentBoard();
    EXPECT_EQ(c, board.getStone(move_list[i].x, move_list[i].y));
    if (i+1 < (signed)move_list.size()) {
      EXPECT_EQ(FREE, board.getStone(move_list[i+1].x, move_list[i+1].y));
    }

    i++;
  } while (!board_it.isLast());

  board_it.getCurrentBoard().printToErr();
}
Пример #2
0
TEST(Record_Test, boardIterator_with_Handicap) {
  // make this board
  // int init_array[][9] = {
  //   {0,1,1,1,0,0,0,0,0},
  //   {1,2,2,2,0,0,0,2,0},
  //   {0,1,2,2,1,0,0,0,0},
  //   {0,1,2,0,0,0,0,0,0},
  //   {0,0,1,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0},
  //   {0,0,0,0,0,0,0,0,0}
  // };
  Record rec;
  rec.setBoardSize(9);
  rec.setHandicapCount(2);
  rec.addHandicapPoint(Record::Move(6,2));
  rec.addHandicapPoint(Record::Move(2,6));
  EXPECT_TRUE(rec.checkConsistencyForHandicap());

  vector<Record::Move> move_list;

  move_list.push_back(Record::Move(1,0));
  move_list.push_back(Record::Move(1,1));
  move_list.push_back(Record::Move(2,0));
  move_list.push_back(Record::Move(2,1));
  move_list.push_back(Record::Move(3,0));
  move_list.push_back(Record::Move(3,1));
  move_list.push_back(Record::Move(0,1));
  move_list.push_back(Record::Move(7,1));
  move_list.push_back(Record::Move(1,2));
  move_list.push_back(Record::Move(2,2));
  move_list.push_back(Record::Move(4,2));
  move_list.push_back(Record::Move(3,2));
  move_list.push_back(Record::Move(1,3));
  move_list.push_back(Record::Move(2,3));
  move_list.push_back(Record::Move(2,4));

  for (size_t i=0; i<move_list.size(); i++) {
    rec.addMove(move_list[i]);
  }

  Record::BoardIterator board_it = rec.createBoardIterator();
  EXPECT_EQ(9, board_it.getCurrentBoard().getSize());

  for (int x=0; x<9; x++) for (int y=0; y<9; y++) {
      if ((x==2 && y==6) || (x==6 && y==2)) {
        EXPECT_EQ(BLACK, board_it.getCurrentBoard().getStone(x,y));
      } else {
        EXPECT_EQ(FREE, board_it.getCurrentBoard().getStone(x,y));
      }
  }

  int i=0;
  do {
    board_it.moveNext();
    Color c = i%2 == 1 ? BLACK : WHITE;

    const Board &board = board_it.getCurrentBoard();
    EXPECT_EQ(c, board.getStone(move_list[i].x, move_list[i].y));
    if (i+1 < (signed)move_list.size()) {
      EXPECT_EQ(FREE, board.getStone(move_list[i+1].x, move_list[i+1].y));
    }

    i++;
  } while (!board_it.isLast());

  board_it.getCurrentBoard().printToErr();
}