{"action":"created","issue":{"url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/86","repository_url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine","labels_url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/86/labels{/name}","comments_url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/86/comments","events_url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/86/events","html_url":"https://github.com/TeamPorcupine/ProjectPorcupine/issues/86","id":171729802,"number":86,"title":"Using GOAP system for jobs","user":{"login":"NogginBops","id":3778357,"avatar_url":"https://avatars.githubusercontent.com/u/3778357?v=3","gravatar_id":"","url":"https://api.github.com/users/NogginBops","html_url":"https://github.com/NogginBops","followers_url":"https://api.github.com/users/NogginBops/followers","following_url":"https://api.github.com/users/NogginBops/following{/other_user}","gists_url":"https://api.github.com/users/NogginBops/gists{/gist_id}","starred_url":"https://api.github.com/users/NogginBops/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NogginBops/subscriptions","organizations_url":"https://api.github.com/users/NogginBops/orgs","repos_url":"https://api.github.com/users/NogginBops/repos","events_url":"https://api.github.com/users/NogginBops/events{/privacy}","received_events_url":"https://api.github.com/users/NogginBops/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-08-17T18:39:03Z","updated_at":"2016-08-17T19:30:14Z","closed_at":null,"body":"So this is what we came up with after a long discussion in #75 and #63.\r\n\r\nThe plan for the new job system and really the new AI system is to use GOAP (Goal Oriented Action Planning).\r\n\r\nI won't go into the finer workings of GOAP but there are some great resources out there:\r\n[A GOAP rescource website](http://alumni.media.mit.edu/~jorkin/goap.html)\r\n[TheHappieCats video](https://www.youtube.com/watch?v=n6vn7d5R_2c)\r\n[Quill18s video](https://www.youtube.com/watch?v=bc86es4YOoc)\r\n[A paper on applying GOAP in practice](http://alumni.media.mit.edu/~jorkin/GOAP_draft_AIWisdom2_2003.pdf)\r\n\r\nThe general gist is to not worry about dependencies and special/edge cases and only worry about the end goal.\r\n\r\nSo all the programmer has to do is just specify the desired end result and the system will figure out what needs to be done for the goal to be reached.\r\n\r\nThis is done by defining actions that a character can take. A action contains what dependencies that action takes (e.g Building a wall requires building materials) and what outcome that action results in (e.g the wall being built). In addition to this a action contains a cost function that is used to calculate what the cost of a action is. This can be in either in respects to resources or time (Efficiency vs. time).\r\n\r\nSo when a goal is specified it goes through all the available actions that result in the desired result and chooses the least costly solution.\r\n\r\nThis is a good solution because it allows modders to easily create cross mod support. For example consider the following scenario:\r\n\r\nModder x creates a mod that creates a machine that creates steel plates super efficiently. \r\nAnd modder y creates a mod that requires steel plates to craft a really cool weapon. \r\n\r\nUsing some kind of other system, a specific case for the other mods machine might be needed. \r\nBut with GOAP this is a non issue. The machine in modder xs mod would just specify an action to create steel plates and modder ys mod would specify a goal that requires steel pates. The system would then figure out that crafting the steel plates is the cheapest way to create steel plates and create the steel plates that way. \r\nAnd just like that, Done!"},"comment":{"url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/comments/240520973","html_url":"https://github.com/TeamPorcupine/ProjectPorcupine/issues/86#issuecomment-240520973","issue_url":"https://api.github.com/repos/TeamPorcupine/ProjectPorcupine/issues/86","id":240520973,"user":{"login":"lameox","id":13168856,"avatar_url":"https://avatars.githubusercontent.com/u/13168856?v=3","gravatar_id":"","url":"https://api.github.com/users/lameox","html_url":"https://github.com/lameox","followers_url":"https://api.github.com/users/lameox/followers","following_url":"https://api.github.com/users/lameox/following{/other_user}","gists_url":"https://api.github.com/users/lameox/gists{/gist_id}","starred_url":"https://api.github.com/users/lameox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lameox/subscriptions","organizations_url":"https://api.github.com/users/lameox/orgs","repos_url":"https://api.github.com/users/lameox/repos","events_url":"https://api.github.com/users/lameox/events{/privacy}","received_events_url":"https://api.github.com/users/lameox/received_events","type":"User","site_admin":false},"created_at":"2016-08-17T19:30:14Z","updated_at":"2016-08-17T19:30:14Z","body":"We define an interface that our Goals will implement, i.e. \r\n```\r\npublic interface IGoal {\r\n    List<Item> Requires  { get; }\r\n    List<Item> Produces { get; }\r\n    List<Condition> Proconditions { get; }\r\n}\r\n\r\nclass Goal : IGoal {\r\n //implementation\r\n}\r\n```\r\n\r\nThis will be our object that we use in the GOAP. For example we may need stuff like the Requires, Produces and Procodition fields. This will be the interface we program against. This means that in our GOAP implementation we will only ever call Methods and access fields defined in IGoal. Then when we want to write unit tests we can provide a dummy implementation of that interface and use it in our tests. by doing so we can easily test specific parts of the code without having to setup a huge net of dependencies we would have in a normal run.\r\n\r\nIf you want to read up on it:\r\n[MSDN Interfaces](https://msdn.microsoft.com/en-us/library/ms173156.aspx)\r\n[Unit testing](https://msdn.microsoft.com/en-us/library/hh694602.aspx)\r\n[Stubbing](https://msdn.microsoft.com/en-us/library/hh549174.aspx)\r\n\r\n\r\n"}}
{"actor":{"display_login":"lameox"}}