Created
July 2, 2016 15:06
-
-
Save Vratislav/75a65998569f9aef1e9c6bac4e95a854 to your computer and use it in GitHub Desktop.
Ruby warrior RG 2016
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
| class Player | |
| def enemey_ahead?(warrior) | |
| spaces = warrior.look | |
| return true if spaces[0].enemy? | |
| return false if !spaces[0].empty? | |
| return true if spaces[1].enemy? | |
| return false if !spaces[1].empty? | |
| return true if spaces[2].enemy? | |
| return false if !spaces[2].empty? | |
| end | |
| def play_turn(warrior) | |
| @direction ||= :backward | |
| @last_health ||= 20 | |
| @amok ||= false | |
| @retreated_count ||= 0 | |
| if warrior.health == 20 && @retreated_count > 2 | |
| @amok = true | |
| end | |
| if @amok == false | |
| if warrior.health < 20 and !warrior.feel.enemy? and warrior.health >= @last_health | |
| warrior.rest! | |
| elsif warrior.health < @last_health && !warrior.feel.enemy? | |
| @retreated_count = @retreated_count + 1 | |
| warrior.walk! :backward | |
| elsif enemey_ahead?(warrior) | |
| warrior.shoot! @direction | |
| elsif warrior.feel(@direction).captive? | |
| warrior.rescue! @direction | |
| else | |
| warrior.walk! @direction | |
| end | |
| if warrior.feel(@direction).wall? | |
| @direction = :forward | |
| end | |
| else | |
| if warrior.feel(:forward).enemy? | |
| warrior.attack! :forward | |
| else | |
| warrior.walk! :forward | |
| end | |
| end | |
| @last_health = warrior.health | |
| # cool code goes here | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment