我是 Ruby 的新手,并且将国际象棋构建为一种学习练习。我正在尝试重构一些代码,但我遇到了阻碍。
为什么会这样:
@available_moves = []
#part of castling logic
@available_moves << "c1" if empty?("b1") && empty?("c1") && empty?("d1")
def empty?(position)
get_space(position).token =~ /_/
end
# sample tokens: "_e4", "ka2", "_b3"
...这不是吗?:
@available_moves = []
@available_moves << "c1" if emptyii?("b1", "c1", "d1")
def emptyii?(*positions)
positions.each { |position| get_space(position).token =~ /_/ }
end
这可能是非常愚蠢的事情,但我无法弄清楚我做错了什么。