Skip to content

Commit 8ea3735

Browse files
authored
Merge pull request #139 from HaliteChallenge/profile-engine
Reduce CPU usage, fix compilation
2 parents 93f2561 + 13a5bcd commit 8ea3735

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

apiserver/apiserver/login/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ def google_login_init():
7070
@cross_origin(methods=["GET"], origins=config.CORS_ORIGINS, supports_credentials=True)
7171
def me():
7272
if config.SESSION_COOKIE in flask.session:
73-
return flask.jsonify({
74-
"user_id": flask.session[config.SESSION_COOKIE],
75-
})
73+
with model.read_conn() as conn:
74+
user = conn.execute(sqlalchemy.sql.select([
75+
model.users.c.id.label("user_id"),
76+
]).where((model.users.c.id == flask.session[config.SESSION_COOKIE]) &
77+
(model.users.c.session_secret == flask.session[config.SESSION_SECRET]))).first()
78+
79+
if user:
80+
return flask.jsonify({
81+
"user_id": flask.session[config.SESSION_COOKIE],
82+
})
7683
else:
7784
user = util.validate_api_key(
7885
flask.request.headers.get(config.API_KEY_HEADER))
@@ -195,7 +202,7 @@ def generic_login_callback(email, oauth_provider, oauth_id, default_username=Non
195202
flask.session[config.SESSION_SECRET] = session_secret
196203
flask.session[config.SESSION_COOKIE] = new_user_id[0]
197204
except sqlalchemy.exc.IntegrityError:
198-
raise util.APIError(400, message="User already exists with this email.")
205+
raise util.APIError(400, message="User already exists with this email. If you would like to change your login method, reach out to [email protected] with this token: " + str(oauth_id))
199206

200207
if default_username:
201208
# Try to use default username, but give up if taken.

apiserver/worker/compiler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ def compile(self, bot_dir, globs, errors, timelimit):
377377
"Julia": [
378378
["JULIA_DEPOT_PATH=\$(pwd) julia -e 'using Pkg; Pkg.activate(\\\".\\\"); Pkg.instantiate()'"],
379379
],
380+
"Kotlin": [
381+
["kotlinc", "-include-runtime", "-d", BOT + ".jar"],
382+
],
380383
"Haskell": [
381384
["ghc", "--make", BOT + ".hs", "-O", "-v0", "-rtsopts"],
382385
],
@@ -568,6 +571,13 @@ def compile(self, bot_dir, globs, errors, timelimit):
568571
(["*.jl"], ChmodCompiler("Julia")),
569572
]
570573
),
574+
Language("Kotlin", BOT +".jar", "MyBot.kt",
575+
"java -Xmx" + str(MEMORY_LIMIT) + "m -cp MyBot.jar MyBot",
576+
["*.class, *.jar"],
577+
[
578+
(["*.kt"], ExternalCompiler(comp_args["Kotlin"][0])),
579+
]
580+
),
571581
Language("Lisp", BOT, "MyBot.lisp",
572582
"./MyBot --dynamic-space-size " + str(MEMORY_LIMIT),
573583
[BOT],

apiserver/worker/worker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def executeCompileTask(user_id, bot_id, backend):
160160
try:
161161
if didCompile:
162162
logging.debug("Bot did compile\n")
163+
164+
# Make things group-readable
165+
subprocess.call([
166+
"sudo", "-H", "-u", "bot_compilation", "-s",
167+
"chmod", "-R", "g+r", temp_dir,
168+
], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
163169
archive_path = os.path.join(temp_dir, str(user_id)+".zip")
164170
archive.zipFolder(temp_dir, archive_path)
165171
backend.storeBotRemotely(user_id, bot_id, archive_path)

game_engine/core/HaliteImpl.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -412,30 +412,21 @@ void HaliteImpl::update_inspiration() {
412412
}
413413

414414
// Explore locations around this ship
415-
std::unordered_set<Location> visited_locs{};
416-
std::unordered_set<Location> to_visit_locs{location};
417-
while (!to_visit_locs.empty()) {
418-
const Location cur = *to_visit_locs.begin();
419-
visited_locs.emplace(cur);
420-
to_visit_locs.erase(to_visit_locs.begin());
421-
422-
const auto &cur_cell = game.map.at(cur);
423-
if (cur_cell.entity != Entity::None) {
415+
for (auto dx = -inspiration_radius; dx <= inspiration_radius; dx++) {
416+
for (auto dy = -inspiration_radius; dy <= inspiration_radius; dy++) {
417+
const auto cur = Location{
418+
(((location.x + dx) % game.map.width) + game.map.width) % game.map.width,
419+
(((location.y + dy) % game.map.height) + game.map.height) % game.map.height
420+
};
421+
422+
const auto &cur_cell = game.map.at(cur);
423+
if (cur_cell.entity == Entity::None ||
424+
game.map.distance(location, cur) > inspiration_radius) {
425+
continue;
426+
}
424427
const auto &other_entity = game.store.get_entity(cur_cell.entity);
425428
ships_in_radius[other_entity.owner]++;
426429
}
427-
428-
for (const Location &neighbor : game.map.get_neighbors(cur)) {
429-
if((visited_locs.find(neighbor) == visited_locs.end())
430-
&& (to_visit_locs.find(neighbor) == to_visit_locs.end())) {
431-
if (game.map.distance(location, neighbor) <= inspiration_radius) {
432-
to_visit_locs.emplace(neighbor);
433-
}
434-
else {
435-
visited_locs.emplace(neighbor);
436-
}
437-
}
438-
}
439430
}
440431

441432
// Total up ships of other player

website/learn-programming-challenge/downloads.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Our community creates and shares a wide variety of tools for developing Halite b
9999

100100
* [Reloader Script](https://forums.halite.io/t/halite-3-reloader-script/120) displays the difference a bot's output and a given replay file.
101101
* [Alternative Local Replay Viewer](https://forums.halite.io/t/fluorine-a-halite-3-replay-viewer/99)
102-
* [Match Manager](https://gitlab.com/smiley1983/halite3-match-manager)
102+
* [Match Manager (smiley1983)](https://gitlab.com/smiley1983/halite3-match-manager)
103+
* [Match Manager (ported from Halite I)](https://github.com/HaliteChallenge/Halite-III/tree/master/tools/manager)
103104

104105
<br/>

0 commit comments

Comments
 (0)