{"action":"created","comment":{"url":"https://api.github.com/repos/freeorion/freeorion/pulls/comments/33899791","id":33899791,"diff_hunk":"@@ -1,30 +1,328 @@\n import freeOrionAIInterface as fo  # pylint: disable=import-error\n import FreeOrionAI as foAI\n-import TechsListsAI\n import AIDependencies\n import AIstate\n import traceback\n import ColonisationAI\n from freeorion_tools import tech_is_complete, chat_human\n \n-inProgressTechs = {}\n-\n-\n-def get_research_index():\n-    empire_id = fo.empireID()\n-    research_index = empire_id % 2\n-    if foAI.foAIstate.aggression >= fo.aggression.aggressive:  # maniacal\n-        research_index = 2 + (empire_id % 3)  # so indices [2,3,4]\n-    elif foAI.foAIstate.aggression >= fo.aggression.typical:\n-        research_index += 1\n+def get_empire_hash():\n+    \"\"\"Get hash for empire name, so to create random tech choices in every game, yet deterministic across loading of same game\n+    \"\"\"\n+    ename = fo.getEmpire().name\n+    hash = 0\n+    for char in ename:\n+        hash += ord(char)\n+    research_index = fo.getEmpire().empireID + hash\n     return research_index\n \n+def get_priority(tech_name, empire):\n+    \"\"\"Get tech priority. 1 is default. 0 if not useful (but doesn't hurt to research), < 0 to prevent AI to research it\n+    \"\"\"\n \n-def exclude_tech(tech_name):\n-    return ((foAI.foAIstate.aggression < AIDependencies.TECH_EXCLUSION_MAP_1.get(tech_name, fo.aggression.invalid)) or\n-            (foAI.foAIstate.aggression > AIDependencies.TECH_EXCLUSION_MAP_2.get(tech_name, fo.aggression.maniacal)) or\n-            tech_name in TechsListsAI.unusable_techs())\n-            \n+    index = get_empire_hash()\n+\n+    immediate = 999 # i.e. research this tech NOW!\n+    useless = 0 # useless for AI, mostly because the AI doesn't know how to use them\n+    default = 1\n+    unresearchable = -1 # anything unresearchable should use this TODO obtain this information from techs.txt\n+\n+    theory = 0 # theories has 0 priority as they don't unlock anything. If it ends up prereq for any other tech those tech will add the theories in.\n+\n+    growth = 2 # maximum population growth has higher priority.\n+    production_boost = 1.5 # production boosts have higher priority. This include buildings that boosts production\n+    research_boost = 2 # research boosts have higher priority. This include buildings that boosts research\n+    meter_boost = 1\n+    shield = 1.25 # shields are more powerful than armors or weapons\n+    defensive = 2 if foAI.foAIstate.aggression <= fo.aggression.cautious else (1 if fo.currentTurn() > 10 else 0.5)","path":"default/AI/ResearchAI.py","position":53,"original_position":53,"commit_id":"5a25001310fa523edbe8025dabf9870894005966","original_commit_id":"5a25001310fa523edbe8025dabf9870894005966","user":{"login":"Morlic-fo","id":11706951,"avatar_url":"https://avatars.githubusercontent.com/u/11706951?v=3","gravatar_id":"","url":"https://api.github.com/users/Morlic-fo","html_url":"https://github.com/Morlic-fo","followers_url":"https://api.github.com/users/Morlic-fo/followers","following_url":"https://api.github.com/users/Morlic-fo/following{/other_user}","gists_url":"https://api.github.com/users/Morlic-fo/gists{/gist_id}","starred_url":"https://api.github.com/users/Morlic-fo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morlic-fo/subscriptions","organizations_url":"https://api.github.com/users/Morlic-fo/orgs","repos_url":"https://api.github.com/users/Morlic-fo/repos","events_url":"https://api.github.com/users/Morlic-fo/events{/privacy}","received_events_url":"https://api.github.com/users/Morlic-fo/received_events","type":"User","site_admin":false},"body":"I do not think we want to work with static priorities. For example, if we do not expect to meet enemies soon due to a sparse galaxy and it being early in the game, military techs should have a reduced priority. Defense techs turn out only to be useful if attacked, too. Any RP spent on them too early cripples our economy. \r\n\r\nA reasonable approach thus would be to define functions ```calculate_defense_tech_priority()``` and so on which return reasonable priorities based on universe settings and the game state which then can be used in the following parts of the code.","created_at":"2015-07-05T22:40:20Z","updated_at":"2015-07-05T22:40:20Z","html_url":"https://github.com/freeorion/freeorion/pull/174#discussion_r33899791","pull_request_url":"https://api.github.com/repos/freeorion/freeorion/pulls/174","_links":{"self":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/comments/33899791"},"html":{"href":"https://github.com/freeorion/freeorion/pull/174#discussion_r33899791"},"pull_request":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/174"}}},"pull_request":{"url":"https://api.github.com/repos/freeorion/freeorion/pulls/174","id":39220558,"html_url":"https://github.com/freeorion/freeorion/pull/174","diff_url":"https://github.com/freeorion/freeorion/pull/174.diff","patch_url":"https://github.com/freeorion/freeorion/pull/174.patch","issue_url":"https://api.github.com/repos/freeorion/freeorion/issues/174","number":174,"state":"open","locked":false,"title":"Research AI","user":{"login":"luiges90","id":1821496,"avatar_url":"https://avatars.githubusercontent.com/u/1821496?v=3","gravatar_id":"","url":"https://api.github.com/users/luiges90","html_url":"https://github.com/luiges90","followers_url":"https://api.github.com/users/luiges90/followers","following_url":"https://api.github.com/users/luiges90/following{/other_user}","gists_url":"https://api.github.com/users/luiges90/gists{/gist_id}","starred_url":"https://api.github.com/users/luiges90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luiges90/subscriptions","organizations_url":"https://api.github.com/users/luiges90/orgs","repos_url":"https://api.github.com/users/luiges90/repos","events_url":"https://api.github.com/users/luiges90/events{/privacy}","received_events_url":"https://api.github.com/users/luiges90/received_events","type":"User","site_admin":false},"body":"Rewrite AI for researching to \r\n- automatically adapt to certain `techs.txt` changes (mostly research costs and adding techs)\r\n- adding a \"priority expression\" notion which allow easier modification when user changes their `techs.txt`\r\n- adding variation to AI research by probabilistically[1] include certain kind of techs (e.g. engines, fuels etc)\r\n- AI will specialize a certain hull in most cases (but may randomly use more than one hull)\r\n- AI will ignore those techs which it doesn't know how to use, for now\r\n- Last but not least, AI will attempt technological victory (i.e. researching Singularity of Transcendence) and do that before all techs it deemed useless, if the player is not fast enough :smile: \r\n\r\n[1]: Probabilistically: in fact, the script derives decisions from the Empire Name by computing some sort of hashcode of the name and then apply a seemingly magic modulo. This is done so that the same empire in the same game will behave consistently across the entire game, yet different empires across different game will have different results.\r\n\r\n### Algorithm overview ###\r\n\r\n- In every turn, all techs will have their priorities computed\r\n    - Priority = `intrinsic priority / total RP needed for this tech`\r\n    - `total RP needed for this tech` includes the RP needed to get this tech, as well as total RP costs of all unresearched prerequisites \r\n    - `intrinsic priority`: see below\r\n- Then, if there are RP remains after current queue, add the item of highest priority (that is not already in the queue) into the queue, and all the prerequisites the tech needs, until no more RP left\r\n\r\n### Intrinsic priority ###\r\n\r\nA \"priority expression\" for each tech, which \r\n- default returns to 1. \r\n- For example, techs that increase maximum population will have higher priority (a constant `2`) \r\n- While xenoarch will have a very high priority if the empire have ruins, while 0 priority if there is no ruins known\r\n- if priority returns negative number, the tech will not be researched\r\n- Theories are 0 because they don't unlock anything. However, if there are other useful techs which requires them, these theory techs will be added along with the useful tech (see above)\r\n\r\n### Migration of old researchAI ###\r\n\r\nAll enabled fast tracks in the old version of `research.py` are migrated, but disabled one do not. This includes\r\n- Xenoarcheology\r\n- asteroid / Gas giant techs (however, Asteroid hull related branch is not migrated due to new hull-specialization)\r\n- Xeno-genetics for lousy colonizers\r\n- Singularity-generation when having black hole (Currently it is implemented as only research Singularity-generation when empire have an access to a black hole colony)\r\n- Death ray cleanup (currently it does not dequeue prerequisites)\r\n\r\nDistributed thought fast track is not included because the research cost reduction when having telepathic species is already considered in the total cost calculation step.\r\n\r\n### Further Work ###\r\n\r\n- Priority expressions definitely need to be play-tested and tweaked\r\n- Include more randomization to priorities \r\n- Maybe dequeue everything and add the techs again every turn.\r\n- Some other TODOs as indicated in the source code","created_at":"2015-07-05T13:04:37Z","updated_at":"2015-07-05T22:40:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6afb7604f24291fa1943b0457fd8e9b77e6f9b8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/freeorion/freeorion/pulls/174/commits","review_comments_url":"https://api.github.com/repos/freeorion/freeorion/pulls/174/comments","review_comment_url":"https://api.github.com/repos/freeorion/freeorion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/freeorion/freeorion/issues/174/comments","statuses_url":"https://api.github.com/repos/freeorion/freeorion/statuses/5a25001310fa523edbe8025dabf9870894005966","head":{"label":"luiges90:master","ref":"master","sha":"5a25001310fa523edbe8025dabf9870894005966","user":{"login":"luiges90","id":1821496,"avatar_url":"https://avatars.githubusercontent.com/u/1821496?v=3","gravatar_id":"","url":"https://api.github.com/users/luiges90","html_url":"https://github.com/luiges90","followers_url":"https://api.github.com/users/luiges90/followers","following_url":"https://api.github.com/users/luiges90/following{/other_user}","gists_url":"https://api.github.com/users/luiges90/gists{/gist_id}","starred_url":"https://api.github.com/users/luiges90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luiges90/subscriptions","organizations_url":"https://api.github.com/users/luiges90/orgs","repos_url":"https://api.github.com/users/luiges90/repos","events_url":"https://api.github.com/users/luiges90/events{/privacy}","received_events_url":"https://api.github.com/users/luiges90/received_events","type":"User","site_admin":false},"repo":{"id":38556749,"name":"freeorion","full_name":"luiges90/freeorion","owner":{"login":"luiges90","id":1821496,"avatar_url":"https://avatars.githubusercontent.com/u/1821496?v=3","gravatar_id":"","url":"https://api.github.com/users/luiges90","html_url":"https://github.com/luiges90","followers_url":"https://api.github.com/users/luiges90/followers","following_url":"https://api.github.com/users/luiges90/following{/other_user}","gists_url":"https://api.github.com/users/luiges90/gists{/gist_id}","starred_url":"https://api.github.com/users/luiges90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luiges90/subscriptions","organizations_url":"https://api.github.com/users/luiges90/orgs","repos_url":"https://api.github.com/users/luiges90/repos","events_url":"https://api.github.com/users/luiges90/events{/privacy}","received_events_url":"https://api.github.com/users/luiges90/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/luiges90/freeorion","description":"Source code repository of the FreeOrion project.","fork":true,"url":"https://api.github.com/repos/luiges90/freeorion","forks_url":"https://api.github.com/repos/luiges90/freeorion/forks","keys_url":"https://api.github.com/repos/luiges90/freeorion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/luiges90/freeorion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/luiges90/freeorion/teams","hooks_url":"https://api.github.com/repos/luiges90/freeorion/hooks","issue_events_url":"https://api.github.com/repos/luiges90/freeorion/issues/events{/number}","events_url":"https://api.github.com/repos/luiges90/freeorion/events","assignees_url":"https://api.github.com/repos/luiges90/freeorion/assignees{/user}","branches_url":"https://api.github.com/repos/luiges90/freeorion/branches{/branch}","tags_url":"https://api.github.com/repos/luiges90/freeorion/tags","blobs_url":"https://api.github.com/repos/luiges90/freeorion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/luiges90/freeorion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/luiges90/freeorion/git/refs{/sha}","trees_url":"https://api.github.com/repos/luiges90/freeorion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/luiges90/freeorion/statuses/{sha}","languages_url":"https://api.github.com/repos/luiges90/freeorion/languages","stargazers_url":"https://api.github.com/repos/luiges90/freeorion/stargazers","contributors_url":"https://api.github.com/repos/luiges90/freeorion/contributors","subscribers_url":"https://api.github.com/repos/luiges90/freeorion/subscribers","subscription_url":"https://api.github.com/repos/luiges90/freeorion/subscription","commits_url":"https://api.github.com/repos/luiges90/freeorion/commits{/sha}","git_commits_url":"https://api.github.com/repos/luiges90/freeorion/git/commits{/sha}","comments_url":"https://api.github.com/repos/luiges90/freeorion/comments{/number}","issue_comment_url":"https://api.github.com/repos/luiges90/freeorion/issues/comments{/number}","contents_url":"https://api.github.com/repos/luiges90/freeorion/contents/{+path}","compare_url":"https://api.github.com/repos/luiges90/freeorion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/luiges90/freeorion/merges","archive_url":"https://api.github.com/repos/luiges90/freeorion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/luiges90/freeorion/downloads","issues_url":"https://api.github.com/repos/luiges90/freeorion/issues{/number}","pulls_url":"https://api.github.com/repos/luiges90/freeorion/pulls{/number}","milestones_url":"https://api.github.com/repos/luiges90/freeorion/milestones{/number}","notifications_url":"https://api.github.com/repos/luiges90/freeorion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/luiges90/freeorion/labels{/name}","releases_url":"https://api.github.com/repos/luiges90/freeorion/releases{/id}","created_at":"2015-07-05T04:32:26Z","updated_at":"2015-07-05T04:32:32Z","pushed_at":"2015-07-05T12:47:56Z","git_url":"git://github.com/luiges90/freeorion.git","ssh_url":"git@github.com:luiges90/freeorion.git","clone_url":"https://github.com/luiges90/freeorion.git","svn_url":"https://github.com/luiges90/freeorion","homepage":"http://www.freeorion.org/","size":491257,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"freeorion:master","ref":"master","sha":"8f3fbf21438c226f71bcb5fbfc0edf2fa8cfd872","user":{"login":"freeorion","id":1025550,"avatar_url":"https://avatars.githubusercontent.com/u/1025550?v=3","gravatar_id":"","url":"https://api.github.com/users/freeorion","html_url":"https://github.com/freeorion","followers_url":"https://api.github.com/users/freeorion/followers","following_url":"https://api.github.com/users/freeorion/following{/other_user}","gists_url":"https://api.github.com/users/freeorion/gists{/gist_id}","starred_url":"https://api.github.com/users/freeorion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeorion/subscriptions","organizations_url":"https://api.github.com/users/freeorion/orgs","repos_url":"https://api.github.com/users/freeorion/repos","events_url":"https://api.github.com/users/freeorion/events{/privacy}","received_events_url":"https://api.github.com/users/freeorion/received_events","type":"Organization","site_admin":false},"repo":{"id":33066062,"name":"freeorion","full_name":"freeorion/freeorion","owner":{"login":"freeorion","id":1025550,"avatar_url":"https://avatars.githubusercontent.com/u/1025550?v=3","gravatar_id":"","url":"https://api.github.com/users/freeorion","html_url":"https://github.com/freeorion","followers_url":"https://api.github.com/users/freeorion/followers","following_url":"https://api.github.com/users/freeorion/following{/other_user}","gists_url":"https://api.github.com/users/freeorion/gists{/gist_id}","starred_url":"https://api.github.com/users/freeorion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeorion/subscriptions","organizations_url":"https://api.github.com/users/freeorion/orgs","repos_url":"https://api.github.com/users/freeorion/repos","events_url":"https://api.github.com/users/freeorion/events{/privacy}","received_events_url":"https://api.github.com/users/freeorion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/freeorion/freeorion","description":"Source code repository of the FreeOrion project.","fork":false,"url":"https://api.github.com/repos/freeorion/freeorion","forks_url":"https://api.github.com/repos/freeorion/freeorion/forks","keys_url":"https://api.github.com/repos/freeorion/freeorion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/freeorion/freeorion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/freeorion/freeorion/teams","hooks_url":"https://api.github.com/repos/freeorion/freeorion/hooks","issue_events_url":"https://api.github.com/repos/freeorion/freeorion/issues/events{/number}","events_url":"https://api.github.com/repos/freeorion/freeorion/events","assignees_url":"https://api.github.com/repos/freeorion/freeorion/assignees{/user}","branches_url":"https://api.github.com/repos/freeorion/freeorion/branches{/branch}","tags_url":"https://api.github.com/repos/freeorion/freeorion/tags","blobs_url":"https://api.github.com/repos/freeorion/freeorion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/freeorion/freeorion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/freeorion/freeorion/git/refs{/sha}","trees_url":"https://api.github.com/repos/freeorion/freeorion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/freeorion/freeorion/statuses/{sha}","languages_url":"https://api.github.com/repos/freeorion/freeorion/languages","stargazers_url":"https://api.github.com/repos/freeorion/freeorion/stargazers","contributors_url":"https://api.github.com/repos/freeorion/freeorion/contributors","subscribers_url":"https://api.github.com/repos/freeorion/freeorion/subscribers","subscription_url":"https://api.github.com/repos/freeorion/freeorion/subscription","commits_url":"https://api.github.com/repos/freeorion/freeorion/commits{/sha}","git_commits_url":"https://api.github.com/repos/freeorion/freeorion/git/commits{/sha}","comments_url":"https://api.github.com/repos/freeorion/freeorion/comments{/number}","issue_comment_url":"https://api.github.com/repos/freeorion/freeorion/issues/comments{/number}","contents_url":"https://api.github.com/repos/freeorion/freeorion/contents/{+path}","compare_url":"https://api.github.com/repos/freeorion/freeorion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/freeorion/freeorion/merges","archive_url":"https://api.github.com/repos/freeorion/freeorion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/freeorion/freeorion/downloads","issues_url":"https://api.github.com/repos/freeorion/freeorion/issues{/number}","pulls_url":"https://api.github.com/repos/freeorion/freeorion/pulls{/number}","milestones_url":"https://api.github.com/repos/freeorion/freeorion/milestones{/number}","notifications_url":"https://api.github.com/repos/freeorion/freeorion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/freeorion/freeorion/labels{/name}","releases_url":"https://api.github.com/repos/freeorion/freeorion/releases{/id}","created_at":"2015-03-29T08:22:20Z","updated_at":"2015-07-01T11:33:26Z","pushed_at":"2015-07-05T21:08:52Z","git_url":"git://github.com/freeorion/freeorion.git","ssh_url":"git@github.com:freeorion/freeorion.git","clone_url":"https://github.com/freeorion/freeorion.git","svn_url":"https://github.com/freeorion/freeorion","homepage":"http://www.freeorion.org/","size":491257,"stargazers_count":55,"watchers_count":55,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":11,"forks":27,"open_issues":11,"watchers":55,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/174"},"html":{"href":"https://github.com/freeorion/freeorion/pull/174"},"issue":{"href":"https://api.github.com/repos/freeorion/freeorion/issues/174"},"comments":{"href":"https://api.github.com/repos/freeorion/freeorion/issues/174/comments"},"review_comments":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/174/comments"},"review_comment":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/174/commits"},"statuses":{"href":"https://api.github.com/repos/freeorion/freeorion/statuses/5a25001310fa523edbe8025dabf9870894005966"}}}}