Created
January 4, 2017 14:30
-
-
Save sah4ez/dd73ca251b7114bfc1e6d813ec528350 to your computer and use it in GitHub Desktop.
Manual algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Calculate next action | |
| def act(self, observation): | |
| y = 0 | |
| for line in observation: | |
| x = 0 | |
| for pixel in line: | |
| color = RGB(pixel[0], pixel[1], pixel[2]) | |
| if color.__eq__(self.white) or color.__eq__(self.black): | |
| x += 1 | |
| continue | |
| if y < 90: | |
| self.get_skier(pixel, x, y) | |
| if y > 72: | |
| self.get_flag(pixel, x, y) | |
| x += 1 | |
| y += 1 | |
| self.calc_pos_skier() | |
| self.calc_pos_flag() | |
| return self.compare(self.pos_skier, self.pos_flags) | |
| Algorithm calculation next action. | |
| First calc position skier and flag. | |
| Next calc velocity skier. | |
| Next calc delta X between skier and flags. | |
| def compare(self, skier, flag): | |
| if flag[0] == 0: | |
| return 0 | |
| delta = flag[0] - skier[0] | |
| length = pow((pow(flag[0] - skier[0], 2) + pow(flag[1] - skier[1], 2)), 1 / 2) | |
| alfa = 0.09 | |
| if (1 - alfa) * skier[0] < flag[0] < (1 + alfa) * skier[0]: | |
| if (self.last_length - length) < self.velocity: | |
| return self.calc_velocity(delta, length) | |
| self.save(delta, length) | |
| print("between flag") | |
| return self.alignment() | |
| if (self.last_length - length) == self.velocity: | |
| return self.alignment() | |
| if (self.last_length - length) < self.velocity: | |
| return self.calc_velocity(delta, length) | |
| if abs(self.last_delta) > abs(delta): | |
| self.save(delta, length) | |
| print("need not turning") | |
| return 0 | |
| if delta > 0: | |
| self.save(delta, length) | |
| print("left turn") | |
| return self.left_turn() | |
| else: | |
| self.save(delta, length) | |
| print("right turn") | |
| return self.right_turn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment