Group Details Private

[Alliance] Overlords

  • RE: PTR Changelog 2018-01-18: isolated VM

    Great news, nice to see this implemented.

    It seems like you currently need to save your code after switching to isolated mode, in order to force a code reload to the new virtual machine.

    I already found a first bug, Game.shard seems to be undefined.

    posted in Public Test Realm
  • RE: StructureLink.transferEnergy(...) shows deprecated warning message

    The transferEnergy method is only deprecated when targetting a creep, in that case you should use Creep.withdraw instead.

    In your example this means that you have to replace l.transferEnergy(receiver) with receiver.withdraw(l). Keep in mind that it's still possible to use link.transferEnergy(anotherLink) though.

    posted in Technical Issues and Bugs
  • RE: Discussion: Contract system

    From discussions in slack I came to the conclusion that contracts are most useful to check for conditions instead of executing code that queues intents.

    This way contracts require an implementation from the person fulfilling the contract, which not only allows the contractor to solve it in their own way and optimize it for stuff like CPU, they can be seen as some kind of quest or mission.

    I completely understand the need for manual review, but even though I'm repeating myself, limiting it to manual interaction only is a mistake in my opinion.

    When going for parameterized contracts you could easily create a checksum of the module and require to review the module at least once, after that your code is free to accept any contracts with the same checksum. Additionally your code can verify whether it actually wants to accept a contract based on those parameters.

    In the long term it would be nice being able to accept a contract without manual review, either by a well established list of tested contracts or by adding the exact same contract module to your own code.

    Example contract

    Following is a scenario of how I expect the process to look like when working with contracts.

    Player A: contractee Player B: contractor

    1. The contractee create a contract module, in this case it's a module that requires a nuke to be sent by the contractor to a specific position:
    const { x, y, roomName } = Game.contract.parameters;
    const pos = new RoomPosition(x, y, room);
    
    const hasVision = roomName => roomName in Game.rooms;
    const isMyRoom = roomName => _.get(Game.rooms, [roomName, 'controller', 'my'], false);
    
    module.exports.loop = function() {
    	if (!hasVision(roomName)) {
    		return false;
    	}
    	const nukes = pos.lookFor(LOOK_NUKE);
    	if (!nukes) {
    		return false;
    	}
    	return nukes.some(({ launchRoomName }) => isMyRoom(launchRoomName));
    }
    
    
    1. The contractee creates a contract based on this module:
    function requestNuke(pos, reward) {
    	const { x, y, roomName } = pos;
    	return Game.contracts.create('contract-nuke.js', reward, { x, y, roomName });
    }
    
    requestNuke(new RoomPosition(25, 25, 'N0E0'), 100000);
    
    1. The potential contractor ( Player B ) views all of the available contracts in the UI, reviews the contract's code and approves it, the checksum is then added to their list of allowed contracts.

    2. Player B's code views a list of available contracts and chooses appropriately, afterwards every accepted contract is getting executed (contracts won't be accepted until the next tick). If the contract hasn't been reviewed yet an appropriate error code will get returned.

    const CHECKSUM = '1b1774169003e863931fa3c5ddbfa7f1';
    const MINIMUM_REWARD = 80000;
    
    const myRoom = room => _.get(room, ['controller', 'my'], false);
    const getNuker = room => room.find(FIND_STRUCTURES, { filter: { structureType: STRUCTURE_NUKER }});
    const hasNuker = room => !!getNuker(room);
    const inNukeRange = (room, target) => Game.map.getRoomLinearDistance(room.name, target) <= NUKE_RANGE;
    
    function getFirstNukerInRange(targetRoom) {
    	return _.first(_.values(Game.rooms), room => myRoom(room) && hasNuker(room) && inNukeRange(room, targetRoom));
    }
    
    const isNukeContract = contract => contract.checksum === CHECKSUM;
    const isNukeContractValuable = contract => contract.reward >= MINIMUM_REWARD;
    const isNukeContractInRange = contract => !!getFirstNukerInRange(contract.parameters.roomName);
    
    function acceptNukeContracts(contract) {
    	if (!isNukeContract(contract)) {
    		return;
    	}
    	if (!isNukeContractValuable(contract)) {
    		return;
    	}
    	if (!isNukeContractInRange(contract)) {
    		return;
    	}
    	Game.contracts.accept(contract.id);
    }
    
    function executeNukeContracts(contract) {
    	if (!isNukeContract(contract)) {
    		return;
    	}
    	const { x, y, roomName } = contract.parameters;
    	const nuker = getFirstNukerInRange(roomName);
    	nuker.launchNuke(new RoomPosition(x, y, roomName));
    }
    
    module.exports.loop = function loop() {
    	_.forEach(Game.contracts.available, acceptNukeContracts);
    	
    	_.forEach(Game.contracts.accepted, executeNukeContracts);
    }
    

    This is a fairly simple implementation (but devastating none the less!) but I hope this example shows how automation would be able to handle contracts.

    Contracts API Draft

    The following is a little draft of how the contract API could look like, it's probably a good idea to replace the properties under Game.contracts with a function similar to Game.market.getAllOrders.

    • Contract object
    property type description
    id string A unique identifier, can be used to interact with a contract
    checksum string Checksum of the contained code, each checksum will have to be allowed manually once by reviewing the associated code
    contractee string The player of which the contract was created
    contractor optional string The player that accepted the contract, might not be set yet
    reward number The amount of credits that the contractee pays the contractor once the contract has been fulfilled
    parameters otpional object Any valid json object that can be used to modify the modules behaviour
    • Game.constract: Is only available from within a contract, contains the currently executed Contract object.

    • Game.contracts.available: Array of available Contract objects.

    • Game.contracts.accepted: Array of Contract objects that you accepted.

    • Game.contracts.created: Array of Contract objects that you created but are not accepted yet.

    • Game.contracts.running: Array of Contract objects that you created any were accepted by someone else.

    • Game.contracts.create(moduleName, reward, [parameters]): Create a new contract

    parameter type description
    moduleName string Name of the module you want to create as a contract
    reward number The amount of credits that the contractee pays the contractor once the contract has been fulfilled
    parameters otpional object Any valid json object that can be used to modify the modules behaviour
    • Game.contracts.accept(id): Accept an available contract
    parameter type description
    id string A unique identifier of the contract you want to accept
    posted in General Discussion
  • RE: Discussion: Contract system

    @artch said in Discussion: Contract system:

    @postcrafter We won't have API for automatic contracts acceptance/creation, so environment variables don't make a lot of difference.

    I seem to have missed that part about no automatic creation and acceptance of contracts earlier. Unfortunately this makes it a non-feature for me, I think you do at least need to be able to create contracts automatically, accepting them is a bit riskier for obvious reasons, but it's a problem that's absolutely solveable.

    posted in General Discussion
  • RE: Discussion: Contract system

    @artch said in Discussion: Contract system:

    @postcrafter

    Taking your example from above, if someone wants to setup two contracts for different sourceIds, he will have to copy the module's code and change the constant's value for each of them. It doesn't make any sense to copy an entire file just to change a single value. This would not only be bad coding practice (DRY), it would be impossible or at least impractical to automate.

    Oh, I see. Well, it's just how the system works basically - every contract consists of some code. You can use an external template (e.g. from GitHub) to create that code, but essentialy it will be a separate script in the database. In the same way as how we have a lot of players running identical open source code base - it's also suboptimal, but it is how it works.

    When two independent players want to use the same contract template that's an entirely different story and saving the contracts separately in the database once they've been created is absolutely fine.

    Would you be open to accept pull requests to add some sort of parameter/environment variable/contract memory when the feature is actually added to the game?

    This would also make automatic accepting of contracts a lot easier, add a checksum of the module to the contract and let your code decide whether it wants to accept it or not based on the parameters. This will only work for "well written" contract code, but that's something we as the community are responsible for.

    posted in General Discussion
  • RE: Discussion: Contract system

    @artch said in Discussion: Contract system:

    Even with this functionality, which is awesome by the way, this won't solve the problem of reusing the same code for multiple contracts.

    What is the problem here exactly?

    Taking your example from above, if someone wants to setup two contracts for different sourceIds, he will have to copy the module's code and change the constant's value for each of them. It doesn't make any sense to copy an entire file just to change a single value. This would not only be bad coding practice (DRY), it would be impossible or at least impractical to automate.

    posted in General Discussion
  • RE: Discussion: Contract system

    @artch So a contract can consist of multiple modules which will simply run in the context of another player? Even with this functionality, which is awesome by the way, this won't solve the problem of reusing the same code for multiple contracts.

    posted in General Discussion
  • RE: Discussion: Contract system

    @artch To my understanding a contract is a fully isolated module without the ability to require other modules. In order to setup a new contract I would have to create a new module every time (which is impossible for my code to do) or fall back to string concatenation/manipulation - depending on the implementation -, which means the potential loss of IDE support.

    posted in General Discussion
  • RE: Discussion: Contract system

    Will we be able to provide parameters to a contract, sort of like environment variables? This can be used to use the same code but targeted at different rooms, ticks or players. Otherwise we would have to modify the code and/or use string modification for each contract which seems kind of bad.

    In the example above, both sourceId and dropPosition would be provided with these parameters instead of putting them directly into the code.

    posted in General Discussion
  • RE: Shard2 (and future) claimed corner rooms

    Its 20 Rooms to the nearest open space so I'd need to do that twice.

    This would make inter-shard play something that only players near the middle can do.

    posted in General Discussion

Looks like your connection to Screeps Forum was lost, please wait while we try to reconnect.