Discussion: Contract system


  • YP

    I have thought a bit more about the feature and I'm not sure anymore how practical this will be. I think it might be hard to create code that works seamlessly beside other players codebases.

    for example spawning creeps... people have different ways to queue creeps to spawn.

    When you accept the contract, you're now obliged to execute the contract code. You cannot pause it, that would be a violation of the contract terms. So it's now your responsibility to ensure that the contract code is able to execute each tick.

    What if the code malfunctions? maybe not throwing errors, but spawning creeps every tick without moving them because of a wrong target id and blocking spawns.

    You can't enforce people to fulfill the contract anyways .. of course you can prevent the user to pause the code .. but you can't stop him to change memory of the contractor creeps, suiciding creeps or other more subtile sabotage like changing prototypes so the script won't work correctly.

    The code could also contain a bug that was not recognised in the code review ... maybe it's using a huge amount of cpu under certain circumstances.. then you will be stuck with it ?



  • I have a couple of questions/concerns here:

    Terminology: Client=Guy paying $$$, Contractor=Guy doing work.

    1. Is the code for a contract proposed by the contractor, or by the client?

    2. Is the client able to cancel his contract? If so, does the contractor get paid in any way when the client cancels?

    3. If a contractor is locked-in to a contract, and is unable to edit it, what happens if there is a bug that makes the contract unsatisfiable? Is the contractor doomed to waste CPU on a fruitless contract forever? In this case, I doubt that any rational person would ever accept a contract. It would make far more sense to me to allow players to break contracts (potentially with some kind of penalty system, such as credits kept in escrow or similar).

    4. What happens if the contractor runs out of CPU on a tick or encounters an error? Is the contract code still executed?

    5. What if a contract throws an exception? How is this handled?

    6. What happens if a player gets wiped out and needs to respawn? Many of his contracts may no longer be applicable to the new location, and it seems unreasonable to saddle players with obligations that may out-live their empire's lifetime.


  • Culture

    I really like this system- especially the custom part of it. I can see how this could be used for a number of things people have done manually, such as @Bovius paying players to build his art (and he even wrote scripts for them, so this would be a perfect tie in) or the "clear the edge" folks paying people to remove their rooms in specific sectors.

    I do think it would be possible to build a system that would also allow completely automated codebases to contribute (although I also agree that there's no way to completely automate this that wouldn't either be burdensome to the game admins or limiting on the community).

    You mentioned that a standardized list of contract templates would be more powerful and flexible when guided by the community, but for things to be completely automated there needs to be a way to verify that the code matches what the players expect. I think this can be done by making it so players can publish contract templates that other players can use. Then people can choose to trust a specific players public contracts when used by other players. For example, the LeagueOfAutomatedNations account could publish contracts from a repository on github. Players could then be reasonably sure that the contracts on the site that are "written by" LeagueOfAutomatedNations are what they expect (and the first time it gets abused everyone will stop trusting it and start trusting something else).

    👍

  • Culture

    @w4rl0ck said in Discussion: Contract system:

    for example spawning creeps... people have different ways to queue creeps to spawn.

    The example they used shows how to handle this- let them spawn what's needed and have your code search for creeps that have a specific memory value. Still, it might be a good idea to give the contract an api a way to expose desired creep builds.

    @w4rl0ck said in Discussion: Contract system:

    You can't enforce people to fulfill the contract anyways .. of course you can prevent the user to pause the code .. but you can't stop him to change memory of the contractor creeps, suiciding creeps or other more subtile sabotage like changing prototypes so the script won't work correctly.

    Presumably the contract would have a way to say that it's "satisfied". If the contract involved building a spawn, but the player accepts the contract and somehow sabotages it then the spawn never gets built and the contract keeps running.

    Presumably all the other issues could be resolved by allowing the person who took the contract on to cancel it without getting paid.


  • Dev Team

    @postcrafter

    @artch So a contract can consist of multiple modules which will simply run in the context of another player?

    A contract doesn't consist of multiple modules, it's just one long string of code, but yes, it is executed in the contractor's context.

    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?


  • Dev Team

    @w4rl0ck My only concern of what you have mentioned is modifying prototypes. We're still debating on how to handle that. All other things could (and should) be covered by contract conditions.



  • @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.


  • Dev Team

    @dignissi

    I have a couple of questions/concerns here:

    Terminology: Client=Guy paying $$$, Contractor=Guy doing work.

    1. Is the code for a contract proposed by the contractor, or by the client?

    Can be both. Code is proposed by the party creating the offer, and an offer can be created by any party. When you create an offer, you write code and choose one of two options:

    • I am the client (I pay)
    • I am the contractor (I execute the code)
    1. Is the client able to cancel his contract?

    Yes.

    If so, does the contractor get paid in any way when the client cancels?

    I think that would make sense.

    1. If a contractor is locked-in to a contract, and is unable to edit it, what happens if there is a bug that makes the contract unsatisfiable? Is the contractor doomed to waste CPU on a fruitless contract forever? In this case, I doubt that any rational person would ever accept a contract. It would make far more sense to me to allow players to break contracts (potentially with some kind of penalty system, such as credits kept in escrow or similar).

    Yes, both parties are able to break the contract on some terms.

    1. What happens if the contractor runs out of CPU on a tick or encounters an error? Is the contract code still executed?

    No, all your contracts won't be executed on this tick.

    1. What if a contract throws an exception? How is this handled?

    It is handled as usual, you will see an error in your console.


  • Dev Team

    @tedivm

    You mentioned that a standardized list of contract templates would be more powerful and flexible when guided by the community, but for things to be completely automated there needs to be a way to verify that the code matches what the players expect. I think this can be done by making it so players can publish contract templates that other players can use. Then people can choose to trust a specific players public contracts when used by other players. For example, the LeagueOfAutomatedNations account could publish contracts from a repository on github. Players could then be reasonably sure that the contracts on the site that are "written by" LeagueOfAutomatedNations are what they expect (and the first time it gets abused everyone will stop trusting it and start trusting something else).

    While I admit it sounds interesting and cool in theory, but implementing this is a lot of work, and I doubt very much that even a single deal using such a template-based automated convention will ever be made even once by anyone at all. Some people here express the opinion this entire mechanic will be used by 5 people, and automated variant of it will be used by literally nobody.


  • Dev Team

    @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.



  • @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.


  • Dev Team

    @postcrafter We won't have API for automatic contracts acceptance/creation, so environment variables don't make a lot of difference. And such a PR would require access to the official driver code which is not open sourced, and is much more sophisticated than the private server driver.


  • Culture

    @artch said in Discussion: Contract system:

    While I admit it sounds interesting and cool in theory, but implementing this is a lot of work, and I doubt very much that even a single deal using such a template-based automated convention will ever be made even once by anyone at all. Some people here express the opinion this entire mechanic will be used by 5 people, and automated variant of it will be used by literally nobody.

    I actually think having the "standard library" of player contracts will make it more likely to get used, not less.

    Let's use the LeagueOfAutomatedNations example. Assuming the system is workable, I would create templates for the following-

    • Build Spawn in Room
    • Destroy Structure in Room
    • Guard Portal

    Then players who want to make extra credits already have tasks that they can easily consume. Players could program the specifics for each bootstrapping each contract type once then scan for any players that are requesting them, rather than having to do a bunch of manual work and potentially having to write custom code for each project. People would still have the option of writing the more advanced/unique stuff, and since people would be able to get used to the system using the more "standard" stuff there could be more people willing to dive into those.

    I admit I could be wrong about this, but really think some system for standard contracts and identifying when they're in use would make the system more popular simply because it would make it easier for people to use it (assuming the community put the work into making the scripts, which I think is a reasonable assumption).


  • Culture

    There are probably other ways these same goals could be accomplished in different ways too. Another idea would be to separate out parameters (json blob defined by client) from code, and then give each code a unique signature when it's updated (SHA512?) that people can compare against to confirm it's the script they think it is.



  • @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.


  • Dev Team

    Standard library is definitely useful and would make the system easier, but only in a sense that it provides some ready-to-use code for your contracts somewhere. And this can be easily handled by a public GitHub repo like https://github.com/screeps/contract-templates, with a link advertising this repo in the Contracts creation UI.

    But automatic usage of contract templates is very unlikely. Both parties should be on the same page here, using the same conventions, agreeing on the same conditions, being neighbors in the game world, having very specific needs and demands matching each other. The chance of this happening in the real world is almost zero. Too much work for such exotic feature.


  • CoPS

    the other party would never accept a contract with such code

    We'll see.


  • Dev Team

    In order to create some "marketplace-like" behavior to popularize contracts usage, we can develop a public offer system, where you create an offer without a direct respondent, and all interested parties can view all such public offers via special UI. When someone accepts a public offer, you're notified (both via UI and API) and should finish the deal to start the contract (again, either via UI or API).

    Thus, creation and acceptance would be manual, but dealing could be both manual and automatic.

    To make it more clear:

    1. You write code, create a contract (manually).
    2. You set up this contract to be public rather than directly invited (manually).
    3. The contract is then listed in the Public Contracts UI.
    4. An interested party views your contract and accepts it (manually).
    5. You finish the deal (either manually or automatically).
    6. The contract starts, you track the progress (either manually or automatically).


  • My opinion is, that very few people will use it, if it needs that much "manual " work, so its wasted develop time. First it seems to be interesting, but ghe game is about making things automatically. This way its to much manual work to look at/find contracts. As runner of a "third" party script you need to review it veeery carefully, so finding a contract needs tons of time, first you need to consider if its worth it (how much credits for the effort?) and then you need to review all possbile contracts, which one is most cpu efficient and give enough credits, which can i fullfill with least effort etc. If some people are willing to take so much time for this, they can do similiar now just by chatting /messaging people near their aim ( spawn build maybe) and ask for help/give them a code snippet /transfer some ressources/ sell /buy with terminal.



  • @artch said in Discussion: Contract system:

    But automatic usage of contract templates is very unlikely. Both parties should be on the same page here, using the same conventions, agreeing on the same conditions, being neighbors in the game world, having very specific needs and demands matching each other. The chance of this happening in the real world is almost zero. Too much work for such exotic feature.

    I can see your point of view. I wonder if you know what percentage of players automatically trade on the market? Probably a hard-to-gather stat, but I imagine the number of people automatically doing contracts would be quite a bit lower, so if you wrote some clever auto-contract code, the chances of anybody else nearby having code that could understand that would be rather slim.

    On the other hand, what is the overhead of allowing automatic behaviour? I guess the traffic for a "getAllContracts" call would be quite high if it included the code string, so I guess it would probably have to just contain description/player/tick info. An one-tick-delayed call (like segments) that pulled a contract text string should work though, and I would have thought that'd be the only non-trivial thing to implement. Everything else, like checking the code against a third party template could be handled by the user. I do see drawnbacks in a system that only really works if you're also using a third party library, as I doubt many people would be able to do anything more complicated than a simple comparison but it seems like adding automation isn't a huge step having done all the work for non-automated contracts.