{"id":29286,"date":"2023-12-19T20:11:30","date_gmt":"2023-12-19T14:41:30","guid":{"rendered":"https:\/\/tocxten.com\/?page_id=29286"},"modified":"2023-12-19T20:12:57","modified_gmt":"2023-12-19T14:42:57","slug":"simple-vacuum-cleaner-reflex-agent","status":"publish","type":"page","link":"https:\/\/tocxten.com\/index.php\/simple-vacuum-cleaner-reflex-agent\/","title":{"rendered":"Simple Vacuum Cleaner Reflex Agent"},"content":{"rendered":"\n<p class=\"has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background\"><strong>Source Code<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class SimpleReflexVacuumAgent:\r\n    def __init__(self):\r\n        self.location = \"A\"\r\n        self.percept_sequence = &#91;]\r\n        self.actions = &#91;]\r\n\r\n    def add_percept(self, location, is_dirty):\r\n        self.percept_sequence.append((location, is_dirty))\r\n\r\n    def add_action(self, action):\r\n        self.actions.append(action)\r\n\r\n    def execute_actions(self):\r\n        for action in self.actions:\r\n            print(f\"Percept: {self.percept_sequence.pop(0)} - Action: {action}\")\r\n            if action == \"Suck\":\r\n                print(\"Vacuuming dirt.\")\r\n            elif action == \"MoveLeft\":\r\n                self.location = \"A\"\r\n                print(\"Moving left to location A.\")\r\n            elif action == \"MoveRight\":\r\n                self.location = \"B\"\r\n                print(\"Moving right to location B.\")\r\n            elif action == \"DoNothing\":\r\n                print(\"Doing nothing.\")\r\n\r\ndef simple_reflex_vacuum_agent(percept_sequence):\r\n    agent = SimpleReflexVacuumAgent()\r\n\r\n    for percept in percept_sequence:\r\n        location, is_dirty = percept\r\n        agent.add_percept(location, is_dirty)\r\n\r\n        if is_dirty:\r\n            agent.add_action(\"Suck\")\r\n        else:\r\n            if location == \"A\":\r\n                agent.add_action(\"MoveRight\")\r\n            elif location == \"B\":\r\n                agent.add_action(\"MoveLeft\")\r\n\r\n    return agent\r\n\r\n# Example percept sequence\r\npercept_sequence = &#91;(\"A\", True), (\"A\", False), (\"B\", True), (\"B\", False)]\r\n\r\n# Create and run the agent\r\nagent = simple_reflex_vacuum_agent(percept_sequence)\r\nagent.execute_actions()\r\n<\/code><\/pre>\n\n\n\n<p class=\"has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background has-medium-font-size\"><strong>Output <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Percept: ('A', True) - Action: Suck\r\nVacuuming dirt.\r\nPercept: ('A', False) - Action: MoveRight\r\nMoving right to location B.\r\nPercept: ('B', True) - Action: Suck\r\nVacuuming dirt.\r\nPercept: ('B', False) - Action: MoveLeft\r\nMoving left to location A.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source Code Output<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-29286","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/29286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/comments?post=29286"}],"version-history":[{"count":1,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/29286\/revisions"}],"predecessor-version":[{"id":29288,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/29286\/revisions\/29288"}],"wp:attachment":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/media?parent=29286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}