Esempio n. 1
0
void Window::blackGetThinkingResult()
{
    int r1 = -1, c1 = -1, r2 = -1, c2 = -1;
    if (!aiBlack.getThinkingResult(r1, c1, r2, c2)) {
        QTimer::singleShot(500, this, SLOT(blackGetThinkingResult()));
    } else {
        putStone(r1, c1);
        putStone(r2, c2);
    }
}
Esempio n. 2
0
void Window::boardWidgetCellClicked(int row, int col)
{
    WhichPlayer player = gameLogic.whichPlayersTurn();

    if ((player == WhitePlayer && whiteUseAI) ||
            (player == BlackPlayer && blackUseAI)) {
        return;
    }

    putStone(row, col);
}
void manager::playMove() {
    if (game_.nowWinner()==Player::None()) {
        Player current_ = game_.CurrentPlayer();
        Move m = game_.GenMove();
        putStone(m);
        if (auto_reply)
            auto_player = current_;
    }
    else {
        std::cout << "Game has already finished." << std::endl;
    }
}
Esempio n. 4
0
    void operator()(Cells &cells, const Board &board, CellState color, const Eval &eval) noexcept {
        std::array<i64, 64> order;
        auto nextColor = switchCellState(color);
        for (const auto &cell : cells) {
            auto nextBoard = board;
            nextBoard.putStone(color, cell);
            order[cell.toInt()] = nextBoard.getReversibleCount(nextColor);
        }

        std::sort(cells.begin(), cells.end(),
            [order](const CellType &cell1, const CellType &cell2) {
            return order[cell1.toInt()] < order[cell2.toInt()];
        });
    }
Esempio n. 5
0
void putWrapper(Score *best, Stone *stones, int n, const int *map, int x1, int y1, int x2, int y2, int *original_stones)
{
	// Score
	int i;
	Stone sorted[256];
	static int counter = 0;

	switch(counter++) {
	case 0:
		for (i=0; i<n; i++) stones[i].score = ((double)(n - i) / (double)n);
		break;
	case 1:
		for (i=0; i<n; i++) stones[i].score = (((double)(n - i) / (double)n) * (double)stones[i].len) * 0.0625;
		break;
	case 2:
		for (i=0; i<n; i++) stones[i].score = ((double)(n - i) / (double)n) * -1;
		break;
	case 3:
		for (i=0; i<n; i++) stones[i].score = (((double)(n - i) / (double)n) * (double)stones[i].len) * -0.0625;
		break;
	default:
		srand((unsigned)time(NULL));
		for (i=0; i<n; i++) stones[i].score = rand();
	}

	memcpy(sorted, stones, sizeof(Stone) * 256);
	qsort(sorted, n, sizeof(Stone), sortByScore);

	// Put
	int tmpmap[1024];
	for (i=0; i<n; i++) {
		memcpy(tmpmap, map, sizeof(int) * 1024);
		putStone(sorted, sorted[i].id, n, tmpmap, x1, y1, x2, y2);
		if (bestScore(best, tmpmap)) {
			printf("Update best score: (%d, %d)\n", best->score, best->zk);
			sendMsg("S");
			sendAnswer(best->map, stones, original_stones, n);
			if (sendMsg("E") == EXIT_FAILURE) return;
		}
	}
}
void manager::handleLeftClick(int x, int y) {
/*  switch (m_index) {
    m_boardScene->addBlackStone(x, y);
    m_boardScene->addWhiteStone(x, y);
    m_boardScene->addMark(x, y);
    m_boardScene->addCircle(x, y);
    m_boardScene->addSquare(x, y);
    m_boardScene->addTriangle(x, y);
    m_boardScene->addLabel(x, y, m_label);
    qDebug() << "wrong combobox current index";
  }*/
    std::cout << "LeftClick on (" << x << ", " << y << ")." << std::endl;

    if (game_.nowWinner()==Player::None()) {
        Move m(game_.CurrentPlayer(), Location(x, y));
        bool ok = putStone(m);

        if (ok && auto_reply && auto_player!=Player::None())
            playMove();
    }
    else {
        std::cout << "Game has already finished." << std::endl;
    }
}
Esempio n. 7
0
void backTracking(int id, int *map, int nowscore, int first_flg)
{
	int len;

	if (id >= global_n) return;
	if (bestScore2(&global_best, map, &len)) {
		printf("Update best score: (%d, %d)\n", global_best.score, global_best.zk);
		sendMsg("S");
		sendAnswer(global_best.map, global_stones, global_original_stones, global_n);
		if (sendMsg("E") == EXIT_FAILURE) return;
	}
	if ((nowscore - global_sumlen[id]) > global_best.score) return;
	//if (isTraveled(map, id, global_x1, global_y1, global_x2, global_y2, len)) return;

	if (len == 0) return;
	if (len >= global_stones[id].len) {
		int x, y, i, j;

		for (y=global_y1; y<global_y2; y++) {
			for (x=global_x1; x<global_x2; x++) {
				int bidx = (y << 5) + x;
				if (map[bidx] == -2 || map[bidx] >= 0) continue;

				int *p = &global_operation[id << 8];
				len = *p;

				for (i=0; i<len; i++) {
					int xy[32];
					int *pp = &p[i << 5];
					int flg = first_flg || (map[bidx] < -2);

					for (j=1; j<global_stones[id].len; j++) {
						int xx = x + pp[j << 1];
						int yy = y + pp[(j << 1) + 1];
						if (isInValid(xx, yy, global_x1, global_y1, global_x2, global_y2)) goto DAMEDESU;

						int idx = (yy << 5) + xx;
						if (map[idx] == -2 || map[idx] >= 0) goto DAMEDESU;

						xy[j << 1] = xx;
						xy[(j << 1) + 1] = yy;
						flg |= (map[idx] < -2);
					}
					if (!flg) continue;

					// Put
					xy[0] = x;
					xy[1] = y;
					int org[16];

					putStone(map, xy, global_stones[id].len, id, org, global_x1, global_y1, global_x2, global_y2);

					// Recursive
					backTracking(id+1, map, nowscore - global_stones[id].len, 0);

					// Restore
					restoreStone(map, xy, global_stones[id].len, id, org, global_x1, global_y1, global_x2, global_y2);
				DAMEDESU:
					continue;	// noop
				}
			}
		}
	}

	backTracking(id+1, map, nowscore, first_flg);
}