0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

#14 【攻略】RubyWarrior Level5 ~中級編~

Posted at

今回はRubyWarrior中級編のLevel5です。
クリアしようと思えばすぐクリアできる配置ですね笑

また、今回の攻略はこちらの記事を参考にさせていただきました。
http://tumiki.hatenablog.jp/entry/2015/06/30/222625

概要

やることは前回と同じですが、敵や捕虜に近づこうとするとき階段が進行方向にあることがあります。
その場合、しっかりと階段を避けて進ませることが大事になってきます。

スクリプト

class Player

  def enemy?(warrior)
    dir = []
    if warrior.feel(:left).enemy?
      dir << (:left) 
    end
      
    if warrior.feel(:right).enemy?
      dir << (:right) 
    end

    if warrior.feel(:forward).enemy?
      dir << (:forward) 
    end

    if warrior.feel(:backward).enemy?
      dir << (:backward) 
    end
      return dir
  end

  def captive?(warrior)
    dir = []
    if warrior.feel(:left).captive?
      dir << (:left) 
    end
      
    if warrior.feel(:right).captive?
      dir << (:right) 
    end

    if warrior.feel(:forward).captive?
      dir << (:forward) 
    end

    if warrior.feel(:backward).captive?
      dir << (:backward) 
    end
      return dir
  end




  def empty?(warrior)
    dir = []
    dir << (:left) if warrior.feel(:left).empty? and not warrior.feel(:left).stairs?
    dir << (:right) if warrior.feel(:right).empty? and not warrior.feel(:right).stairs?
    dir << (:forward) if warrior.feel(:forward).empty? and not warrior.feel(:forward).stairs?
    dir << (:backwarwd) if warrior.feel(:backward).empty? and not warrior.feel(:backward).stairs?
    return dir
  end

      
  def play_turn(warrior)
    dir = enemy?(warrior)
    if dir.length == 1
      warrior.attack!(dir[0])
      return []
    elsif dir.length > 1
      warrior.bind!(dir[0])
      return []
    end
        
      
    if warrior.health < 20
      warrior.rest!
      return []
    end
          

    dir = captive?(warrior)
    if dir.length > 0
      warrior.rescue!(dir[0])
      return []
    end
        
        
    spaces = warrior.listen
    if spaces.length > 0
      dir = warrior.direction_of(spaces[0])

      if warrior.feel(dir).stairs?
        dir = empty?(warrior)[0]
      end
      warrior.walk!(dir)
      return []
    end
    

    dir = warrior.direction_of_stairs
    warrior.walk!(dir)
    return []
  end
end

解説

前回と同じことをするだけなのですが、「階段を避ける」という行動が入っただけでかなり難儀になります。
参考にした方は敵や捕虜の位置を配列に保存していました。とても参考になる使い方でした。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?