Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor deprecated isRoomAvailable function #191

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Overseer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import {
ROOMTYPE_SOURCEKEEPER
} from './utilities/Cartographer';
import {p} from './utilities/random';
import {canClaimAnotherRoom, getAllRooms, hasJustSpawned, minBy, onPublicServer} from './utilities/utils';
import {
canClaimAnotherRoom,
getAllRooms,
hasJustSpawned,
isRoomAvailable,
minBy,
onPublicServer
} from './utilities/utils';
import {MUON, MY_USERNAME, USE_TRY_CATCH} from './~settings';


Expand Down Expand Up @@ -378,7 +385,7 @@ export class Overseer implements IOverseer {
}
const neighboringRooms = _.values(Game.map.describeExits(roomName)) as string[];
const isReachableFromColony = _.any(neighboringRooms, r => colony.roomNames.includes(r));
return isReachableFromColony && Game.map.isRoomAvailable(roomName);
return isReachableFromColony && isRoomAvailable(roomName);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/overlords/scouting/randomWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Roles, Setups} from '../../creepSetups/setups';
import {OverlordPriority} from '../../priorities/priorities_overlords';
import {profile} from '../../profiler/decorator';
import {Tasks} from '../../tasks/Tasks';
import {isRoomAvailable} from '../../utilities/utils';
import {Zerg} from '../../zerg/Zerg';
import {Overlord} from '../Overlord';

Expand Down Expand Up @@ -40,7 +41,7 @@ export class RandomWalkerScoutOverlord extends Overlord {
// Pick a new room
const neighboringRooms = _.values(Game.map.describeExits(scout.pos.roomName)) as string[];
const roomName = _.sample(neighboringRooms);
if (Game.map.isRoomAvailable(roomName)) {
if (isRoomAvailable(roomName)) {
scout.task = Tasks.goToRoom(roomName);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/strategy/ExpansionPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Autonomy, getAutonomyLevel, Mem} from '../memory/Memory';
import {Pathing} from '../movement/Pathing';
import {profile} from '../profiler/decorator';
import {Cartographer} from '../utilities/Cartographer';
import {maxBy} from '../utilities/utils';
import {isRoomAvailable, maxBy} from '../utilities/utils';
import {MAX_OWNED_ROOMS, SHARD3_MAX_OWNED_ROOMS} from '../~settings';
import {MIN_EXPANSION_DISTANCE} from './ExpansionEvaluator';

Expand Down Expand Up @@ -123,7 +123,7 @@ export class ExpansionPlanner implements IExpansionPlanner {
}
}
// Update best choices
if (score > bestScore && Game.map.isRoomAvailable(roomName)) {
if (score > bestScore && isRoomAvailable(roomName)) {
bestScore = score;
bestRoom = roomName;
}
Expand Down
7 changes: 7 additions & 0 deletions src/utilities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,10 @@ export function rotatedMatrix<T>(matrix: T[][], clockwiseTurns: 0 | 1 | 2 | 3):
export function cyclicListPermutation<T>(list: T[], offset: number): T[] {
return list.slice(offset).concat(list.slice(0, offset));
}

export function isRoomAvailable(roomName: string) {
const roomStatus = Game.map.getRoomStatus(roomName);
const expiration = roomStatus.timestamp;
// TODO: cache result and only recheck after expiration
return roomStatus.status === 'normal';
}