Implement ActionList::Entry#clear.
[kaya.git] / lib / executor.rb
blob05a8b44f34b0168bee63786cd6fe1d4a3dd55d4a
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 module Executor
9   def execute_move(src, dst, opts = { })
10     state = match.history.state
11     move = policy.new_move(state, src, dst)
12     validate = match.game.validator.new(state)
13     if validate[move]
14       perform!(move, opts)
15       move
16     end
17   end
19   def execute_drop(item, dst, opts = { })
20     state = match.history.state
21     move = policy.new_move(state, nil, dst,
22                             :dropped => item.name)
23     validate = match.game.validator.new(state)
24     if validate[move]
25       perform! move, opts.merge(:adjust => true, :dropped => item)
26       move
27     end
28   end
29   
30   def execute_direct_drop(color, index, dst, opts = { })
31     state = match.history.state
32     item = @pools[color].items[index]
33     if item
34       move = policy.new_move(state, nil, dst,
35                              :dropped => item.name)
36       validate = match.game.validator.new(state)
37       if validate[move]
38         perform! move, opts
39         move
40       end
41     end
42   end
43 end