Skip to content

Commit

Permalink
Update file
Browse files Browse the repository at this point in the history
  • Loading branch information
SXKA committed Jan 19, 2024
1 parent e44bf3a commit 320143f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
25 changes: 16 additions & 9 deletions Qt-Gomoku/src/gomoku/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@ Engine::Engine()
}
}

blackShapes.fill(std::string(15, '0'));
whiteShapes.fill(std::string(15, '0'));
std::fill_n(blackShapes.begin(), 30, std::string(15, '0'));
std::fill_n(whiteShapes.begin(), 30, std::string(15, '0'));

for (int i = 5; i <= 15; ++i) {
blackShapes[25 + i] = std::string(i, '0');
whiteShapes[25 + i] = std::string(i, '0');
blackShapes[35 + i] = std::string(20 - i, '0');
whiteShapes[35 + i] = std::string(20 - i, '0');
blackShapes[46 + i] = std::string(i, '0');
whiteShapes[46 + i] = std::string(i, '0');
blackShapes[56 + i] = std::string(20 - i, '0');
whiteShapes[56 + i] = std::string(20 - i, '0');
}
}

bool Engine::isLegal(const QPoint &point)
Expand Down Expand Up @@ -350,11 +361,7 @@ bool Engine::inCheck(const Stone &stone)
point.setY(qMax(0, line - 61) + index);
}

if (isLegal(point)) {
escapes.insert(point);
} else {
return false;
}
escapes.insert(point);
}

return true;
Expand All @@ -365,6 +372,8 @@ bool Engine::inCheck(const Stone &stone)

int Engine::evaluatePoint(const QPoint &point) const
{
const auto &x = point.x();
const auto &y = point.y();
int score = 0;

for (int i = 0; i < 4; ++i) {
Expand Down Expand Up @@ -451,8 +460,6 @@ int Engine::lineScore(const QPoint &point, const int &direction) const
blackLine[qMin(y, 14 - x)] = '1';
whiteLine[qMin(y, 14 - x)] = '1';

break;
default:
break;
}

Expand Down
12 changes: 8 additions & 4 deletions Qt-Gomoku/src/windows/gamewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ void GameWindow::mouseMoveEvent(QMouseEvent *event)
const auto x = event->pos().x();
const auto y = event->pos().y();

update((move.y() + 1) * 40 - 21, (move.x() + 1) * 40 - 1, 42, 42);

move.setX((y - 40) / 40);
move.setY((x - 20) / 40);

update((move.y() + 1) * 40 - 21, (move.x() + 1) * 40 - 1, 42, 42);

if (x < 20 || x >= 620 || y < 40 || y >= 640) {
setCursor(Qt::ArrowCursor);
} else {
Expand All @@ -31,8 +35,6 @@ void GameWindow::mouseMoveEvent(QMouseEvent *event)
setCursor(Qt::ArrowCursor);
}
}

update();
}

void GameWindow::mouseReleaseEvent(QMouseEvent *event)
Expand Down Expand Up @@ -62,11 +64,13 @@ void GameWindow::mouseReleaseEvent(QMouseEvent *event)
return;
}

update((last.y() + 1) * 40 - 21, (last.x() + 1) * 40 - 1, 42, 42);

ui.undo->setEnabled(true);
last = engine.lastMove();
++step;

repaint();
update((last.y() + 1) * 40 - 21, (last.x() + 1) * 40 - 1, 42, 42);

const auto gameState = engine.gameState(move, playerStone);

Expand All @@ -93,7 +97,7 @@ void GameWindow::mouseReleaseEvent(QMouseEvent *event)
if (gameType == PVC) {
ui.undo->setDisabled(true);

repaint();
repaint((last.y() + 1) * 40 - 21, (last.x() + 1) * 40 - 1, 42, 42);
setUpdatesEnabled(false);

future = QtConcurrent::run([ &, this]() {
Expand Down

0 comments on commit 320143f

Please sign in to comment.