spy_alley_application 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/spy_alley_application.rb +6 -0
- data/lib/spy_alley_application/actions/buy_equipment.rb +31 -0
- data/lib/spy_alley_application/actions/choose_new_spy_identity.rb +26 -0
- data/lib/spy_alley_application/actions/choose_space_to_move.rb +21 -0
- data/lib/spy_alley_application/actions/confiscate_materials.rb +58 -0
- data/lib/spy_alley_application/actions/generate_new_game.rb +70 -0
- data/lib/spy_alley_application/actions/make_accusation.rb +40 -0
- data/lib/spy_alley_application/actions/pass.rb +21 -0
- data/lib/spy_alley_application/actions/roll_die.rb +25 -0
- data/lib/spy_alley_application/actions/use_move_card.rb +28 -0
- data/lib/spy_alley_application/execute_action.rb +20 -0
- data/lib/spy_alley_application/injection_container.rb +596 -0
- data/lib/spy_alley_application/models/acquisition_method/by_confiscation.rb +22 -0
- data/lib/spy_alley_application/models/acquisition_method/by_free_gift.rb +20 -0
- data/lib/spy_alley_application/models/acquisition_method/by_passing_start.rb +20 -0
- data/lib/spy_alley_application/models/acquisition_method/by_purchase.rb +21 -0
- data/lib/spy_alley_application/models/acquisition_method/by_selling_top_secret_information.rb +21 -0
- data/lib/spy_alley_application/models/board_spaces/black_market.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/border_crossing.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/buy_equipment.rb +26 -0
- data/lib/spy_alley_application/models/board_spaces/buy_password.rb +26 -0
- data/lib/spy_alley_application/models/board_spaces/confiscate_materials.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/draw_free_gift.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/draw_move_card.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/embassy.rb +26 -0
- data/lib/spy_alley_application/models/board_spaces/move_back.rb +25 -0
- data/lib/spy_alley_application/models/board_spaces/sold_top_secret_information.rb +27 -0
- data/lib/spy_alley_application/models/board_spaces/spy_alley_entrance.rb +38 -0
- data/lib/spy_alley_application/models/board_spaces/spy_eliminator.rb +24 -0
- data/lib/spy_alley_application/models/board_spaces/start.rb +36 -0
- data/lib/spy_alley_application/models/board_spaces/take_another_turn.rb +24 -0
- data/lib/spy_alley_application/models/equipment.rb +42 -0
- data/lib/spy_alley_application/models/game_board.rb +23 -0
- data/lib/spy_alley_application/models/game_board/black_market_option_state.rb +59 -0
- data/lib/spy_alley_application/models/game_board/buy_equipment_option_state.rb +52 -0
- data/lib/spy_alley_application/models/game_board/buy_password_option_state.rb +39 -0
- data/lib/spy_alley_application/models/game_board/confiscate_materials_option_state.rb +68 -0
- data/lib/spy_alley_application/models/game_board/eliminate_player.rb +91 -0
- data/lib/spy_alley_application/models/game_board/embassy_victory.rb +23 -0
- data/lib/spy_alley_application/models/game_board/equipment_bought.rb +42 -0
- data/lib/spy_alley_application/models/game_board/equipment_confiscated.rb +67 -0
- data/lib/spy_alley_application/models/game_board/free_gift_drawn.rb +39 -0
- data/lib/spy_alley_application/models/game_board/money_gained_or_lost.rb +22 -0
- data/lib/spy_alley_application/models/game_board/move_card_drawn.rb +31 -0
- data/lib/spy_alley_application/models/game_board/move_card_used.rb +30 -0
- data/lib/spy_alley_application/models/game_board/move_options.rb +23 -0
- data/lib/spy_alley_application/models/game_board/new_spy_identity_chosen.rb +37 -0
- data/lib/spy_alley_application/models/game_board/next_game_state.rb +70 -0
- data/lib/spy_alley_application/models/game_board/player_moved.rb +24 -0
- data/lib/spy_alley_application/models/game_board/spy_eliminator_options.rb +41 -0
- data/lib/spy_alley_application/models/game_state/buy_equipment.rb +26 -0
- data/lib/spy_alley_application/models/game_state/choose_new_spy_identity.rb +29 -0
- data/lib/spy_alley_application/models/game_state/confiscate_materials.rb +29 -0
- data/lib/spy_alley_application/models/game_state/game_over.rb +27 -0
- data/lib/spy_alley_application/models/game_state/move_option.rb +25 -0
- data/lib/spy_alley_application/models/game_state/spy_eliminator.rb +25 -0
- data/lib/spy_alley_application/models/game_state/start_of_turn.rb +23 -0
- data/lib/spy_alley_application/models/game_state/victory_reason/by_elimination.rb +22 -0
- data/lib/spy_alley_application/models/game_state/victory_reason/by_embassy.rb +22 -0
- data/lib/spy_alley_application/models/move_card.rb +26 -0
- data/lib/spy_alley_application/models/player.rb +37 -0
- data/lib/spy_alley_application/models/sell_top_secret_information.rb +24 -0
- data/lib/spy_alley_application/models/validator/buying_equipment.rb +35 -0
- data/lib/spy_alley_application/models/validator/choosing_new_spy_identity.rb +33 -0
- data/lib/spy_alley_application/models/validator/confiscating_materials.rb +50 -0
- data/lib/spy_alley_application/models/validator/making_accusation.rb +31 -0
- data/lib/spy_alley_application/models/validator/moving.rb +30 -0
- data/lib/spy_alley_application/models/validator/passing.rb +24 -0
- data/lib/spy_alley_application/models/validator/rolling_die.rb +29 -0
- data/lib/spy_alley_application/models/validator/using_move_card.rb +31 -0
- data/lib/spy_alley_application/models/wild_card.rb +25 -0
- data/lib/spy_alley_application/new_game.rb +18 -0
- data/lib/spy_alley_application/new_game/assign_seats.rb +21 -0
- data/lib/spy_alley_application/new_game/assign_spy_identities.rb +24 -0
- data/lib/spy_alley_application/results/nodes/buy_equipment_option_node.rb +23 -0
- data/lib/spy_alley_application/results/nodes/choose_new_spy_identity_option_node.rb +23 -0
- data/lib/spy_alley_application/results/nodes/confiscate_materials_option_node.rb +22 -0
- data/lib/spy_alley_application/results/nodes/die_rolled_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/eliminated_player_node.rb +22 -0
- data/lib/spy_alley_application/results/nodes/equipment_gained_node.rb +28 -0
- data/lib/spy_alley_application/results/nodes/game_over_node.rb +24 -0
- data/lib/spy_alley_application/results/nodes/make_accusation_option_node.rb +20 -0
- data/lib/spy_alley_application/results/nodes/money_gained_node.rb +25 -0
- data/lib/spy_alley_application/results/nodes/money_lost_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/move_back_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/move_card_drawn_node.rb +22 -0
- data/lib/spy_alley_application/results/nodes/move_card_used_node.rb +22 -0
- data/lib/spy_alley_application/results/nodes/move_option_node.rb +20 -0
- data/lib/spy_alley_application/results/nodes/new_spy_identity_chosen_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/next_player_node.rb +20 -0
- data/lib/spy_alley_application/results/nodes/pass_option_node.rb +16 -0
- data/lib/spy_alley_application/results/nodes/player_movement_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/player_passed_node.rb +19 -0
- data/lib/spy_alley_application/results/nodes/reached_embassy_with_all_equipment_node.rb +20 -0
- data/lib/spy_alley_application/results/nodes/result_game_board_node.rb +21 -0
- data/lib/spy_alley_application/results/nodes/roll_die_option_node.rb +16 -0
- data/lib/spy_alley_application/results/nodes/use_move_card_option_node.rb +20 -0
- data/lib/spy_alley_application/results/nodes/wild_card_gained_node.rb +27 -0
- data/lib/spy_alley_application/results/process_buy_equipment_options.rb +25 -0
- data/lib/spy_alley_application/results/process_eliminating_player.rb +36 -0
- data/lib/spy_alley_application/results/process_landing_on_space.rb +232 -0
- data/lib/spy_alley_application/results/process_move_options.rb +65 -0
- data/lib/spy_alley_application/results/process_next_turn_options.rb +87 -0
- data/lib/spy_alley_application/results/process_passing_spaces.rb +68 -0
- data/lib/spy_alley_application/results/process_proceeding_to_next_state.rb +23 -0
- data/lib/spy_alley_application/types/array_of_equipment.rb +7 -0
- data/lib/spy_alley_application/types/array_of_free_gifts.rb +7 -0
- data/lib/spy_alley_application/types/array_of_move_cards.rb +6 -0
- data/lib/spy_alley_application/types/array_of_players.rb +6 -0
- data/lib/spy_alley_application/types/board_space.rb +4 -0
- data/lib/spy_alley_application/types/coercible_integer_one_to_six.rb +9 -0
- data/lib/spy_alley_application/types/equipment.rb +32 -0
- data/lib/spy_alley_application/types/equipment_type.rb +9 -0
- data/lib/spy_alley_application/types/free_gift.rb +22 -0
- data/lib/spy_alley_application/types/game_board.rb +52 -0
- data/lib/spy_alley_application/types/game_state.rb +19 -0
- data/lib/spy_alley_application/types/move_card.rb +21 -0
- data/lib/spy_alley_application/types/nationality.rb +5 -0
- data/lib/spy_alley_application/types/player.rb +123 -0
- data/lib/spy_alley_application/types/validation_builder.rb +21 -0
- data/lib/spy_alley_application/types/validator/non_admin.rb +21 -0
- data/lib/spy_alley_application/types/wild_card.rb +14 -0
- data/lib/spy_alley_application/validator/builder.rb +119 -0
- data/lib/spy_alley_application/validator/buy_equipment.rb +39 -0
- data/lib/spy_alley_application/validator/choose_new_spy_identity.rb +24 -0
- data/lib/spy_alley_application/validator/confiscate_materials.rb +22 -0
- data/lib/spy_alley_application/validator/confiscate_materials/full_validator.rb +39 -0
- data/lib/spy_alley_application/validator/confiscate_materials/validate_target_player_id.rb +24 -0
- data/lib/spy_alley_application/validator/make_accusation.rb +24 -0
- data/lib/spy_alley_application/validator/move.rb +24 -0
- data/lib/spy_alley_application/validator/new_game.rb +35 -0
- data/lib/spy_alley_application/validator/new_game_builder.rb +32 -0
- data/lib/spy_alley_application/validator/no_options.rb +7 -0
- data/lib/spy_alley_application/validator/use_move_card.rb +23 -0
- data/lib/spy_alley_application/version.rb +3 -0
- data/spy_alley_application.gemspec +40 -0
- metadata +343 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5f180d38117c8c362cc7651a65b3c3dd8fe7a6fa02ca7de34f257b5b4fb307e
|
4
|
+
data.tar.gz: 01b57093b11db24e91a5ef4be7c960894cd053a04da91de5a4da1499d760f898
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '088778f1b9a0d2987c1c92964ef8dc755861075948707bb88fa14ad9bad9c209553d7d033e07cb4530c610acecb1dd2248099e41f6ec1fd98c05609fdc696cda'
|
7
|
+
data.tar.gz: 534c52da2d311120b79e037e5439cf5c287483ead003ef903445ca5672fdd34badabe89c83aa5d9f0244a34dd437280d4230ba3b48801e14ddb2596df221fb32
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
spy_alley_application (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
change_orders (0.1.0)
|
10
|
+
concurrent-ruby (1.1.8)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
dry-auto_inject (0.7.0)
|
13
|
+
dry-container (>= 0.3.4)
|
14
|
+
dry-configurable (0.12.1)
|
15
|
+
concurrent-ruby (~> 1.0)
|
16
|
+
dry-core (~> 0.5, >= 0.5.0)
|
17
|
+
dry-container (0.7.2)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
20
|
+
dry-core (0.5.0)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
dry-equalizer (0.3.0)
|
23
|
+
dry-inflector (0.2.0)
|
24
|
+
dry-initializer (3.0.4)
|
25
|
+
dry-logic (1.1.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
dry-core (~> 0.5, >= 0.5)
|
28
|
+
dry-monads (1.3.5)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
dry-core (~> 0.4, >= 0.4.4)
|
31
|
+
dry-equalizer
|
32
|
+
dry-schema (1.6.1)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
dry-configurable (~> 0.8, >= 0.8.3)
|
35
|
+
dry-core (~> 0.5, >= 0.5)
|
36
|
+
dry-initializer (~> 3.0)
|
37
|
+
dry-logic (~> 1.0)
|
38
|
+
dry-types (~> 1.5)
|
39
|
+
dry-struct (1.4.0)
|
40
|
+
dry-core (~> 0.5, >= 0.5)
|
41
|
+
dry-types (~> 1.5)
|
42
|
+
ice_nine (~> 0.11)
|
43
|
+
dry-types (1.5.1)
|
44
|
+
concurrent-ruby (~> 1.0)
|
45
|
+
dry-container (~> 0.3)
|
46
|
+
dry-core (~> 0.5, >= 0.5)
|
47
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
48
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
49
|
+
dry-validation (1.6.0)
|
50
|
+
concurrent-ruby (~> 1.0)
|
51
|
+
dry-container (~> 0.7, >= 0.7.1)
|
52
|
+
dry-core (~> 0.4)
|
53
|
+
dry-equalizer (~> 0.2)
|
54
|
+
dry-initializer (~> 3.0)
|
55
|
+
dry-schema (~> 1.5, >= 1.5.2)
|
56
|
+
game_validator (0.6.1)
|
57
|
+
ice_nine (0.11.2)
|
58
|
+
rake (13.0.3)
|
59
|
+
rspec (3.10.0)
|
60
|
+
rspec-core (~> 3.10.0)
|
61
|
+
rspec-expectations (~> 3.10.0)
|
62
|
+
rspec-mocks (~> 3.10.0)
|
63
|
+
rspec-core (3.10.1)
|
64
|
+
rspec-support (~> 3.10.0)
|
65
|
+
rspec-expectations (3.10.1)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-mocks (3.10.2)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.10.0)
|
71
|
+
rspec-support (3.10.2)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
x64-mingw32
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
bundler (~> 2.0)
|
79
|
+
change_orders (~> 0.1.0)
|
80
|
+
dry-auto_inject
|
81
|
+
dry-initializer
|
82
|
+
dry-monads
|
83
|
+
dry-struct
|
84
|
+
dry-types
|
85
|
+
dry-validation
|
86
|
+
game_validator (~> 0.6.0)
|
87
|
+
rake (~> 13.0)
|
88
|
+
rspec (~> 3.0)
|
89
|
+
spy_alley_application!
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
2.2.15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 colin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Roda::SpyAlleyApplication
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/roda/spy_alley_application`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'roda-spy_alley_application'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install roda-spy_alley_application
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/roda-spy_alley_application.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'spy_alley_application'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen string literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module SpyAlleyApplication
|
6
|
+
module Actions
|
7
|
+
class BuyEquipment
|
8
|
+
include Dry::Initializer.define -> do
|
9
|
+
option :equipment_bought, type: ::Types::Callable, reader: :private
|
10
|
+
option :get_equipment_gained_node, type: ::Types::Callable, reader: :private
|
11
|
+
option :process_proceeding_to_next_state, type: ::Types::Callable, reader: :private
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(game_board:, change_orders:, equipment_to_buy:)
|
15
|
+
equipment_to_buy = equipment_to_buy.map{|e| SpyAlleyApplication::Models::Equipment.call(e)}
|
16
|
+
player = game_board.current_player
|
17
|
+
game_board = equipment_bought.(
|
18
|
+
game_board: game_board,
|
19
|
+
equipment_bought: equipment_to_buy)
|
20
|
+
total_cost = player.money - game_board.players.find{|p| p.seat.eql?(player.seat)}.money
|
21
|
+
process_proceeding_to_next_state.(
|
22
|
+
game_board: game_board,
|
23
|
+
change_orders: change_orders.push(get_equipment_gained_node.(
|
24
|
+
player_id: player.id,
|
25
|
+
equipment: equipment_to_buy,
|
26
|
+
reason: {name: 'by_purchase', amount_paid: total_cost})))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen string literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module SpyAlleyApplication
|
6
|
+
module Actions
|
7
|
+
class ChooseNewSpyIdentity
|
8
|
+
include Dry::Initializer.define -> do
|
9
|
+
option :get_new_spy_identity_chosen_node, type: ::Types::Callable, reader: :private
|
10
|
+
option :get_result_game_board_node, type: ::Types::Callable, reader: :private
|
11
|
+
option :new_spy_identity_chosen, type: ::Types::Callable, reader: :private
|
12
|
+
option :process_proceeding_to_next_state, type: ::Types::Callable, reader: :private
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(game_board:, change_orders:, nationality:)
|
16
|
+
change_orders = change_orders.push(get_new_spy_identity_chosen_node.(
|
17
|
+
nationality: nationality))
|
18
|
+
game_board = new_spy_identity_chosen.(
|
19
|
+
game_board: game_board,
|
20
|
+
new_spy_identity: nationality)
|
21
|
+
process_proceeding_to_next_state.(game_board: game_board, change_orders: change_orders)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen string literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module SpyAlleyApplication
|
6
|
+
module Actions
|
7
|
+
class ChooseSpaceToMove
|
8
|
+
include Dry::Initializer.define -> do
|
9
|
+
option :process_landing_on_space, type: ::Types::Callable, reader: :private
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(game_board:, change_orders:, space_id:)
|
13
|
+
process_landing_on_space.(
|
14
|
+
game_board: game_board,
|
15
|
+
change_orders: change_orders,
|
16
|
+
space_id: space_id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen string literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
require 'spy_alley_application/types/free_gift'
|
5
|
+
|
6
|
+
module SpyAlleyApplication
|
7
|
+
module Actions
|
8
|
+
class ConfiscateMaterials
|
9
|
+
include Dry::Initializer.define -> do
|
10
|
+
option :equipment_confiscated, type: ::Types::Callable, reader: :private
|
11
|
+
option :get_equipment_gained_node, type: ::Types::Callable, reader: :private
|
12
|
+
option :get_wild_card_gained_node, type: ::Types::Callable, reader: :private
|
13
|
+
option :process_proceeding_to_next_state, type: ::Types::Callable, reader: :private
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(game_board:, change_orders:, target_player_id:, equipment_to_confiscate:)
|
17
|
+
equipment_to_confiscate = SpyAlleyApplication::Models::Equipment.(equipment_to_confiscate)
|
18
|
+
player = game_board.current_player
|
19
|
+
target_player = game_board.players.find{|p| p.id.eql?(target_player_id)}
|
20
|
+
equipment = SpyAlleyApplication::Types::FreeGift.call(equipment_to_confiscate)
|
21
|
+
game_board = equipment_confiscated.(
|
22
|
+
game_board: game_board,
|
23
|
+
target_player: target_player,
|
24
|
+
equipment: equipment)
|
25
|
+
amount_paid = player.money - game_board.players.find{|p| p.seat.eql?(player.seat)}.money
|
26
|
+
change_orders = equipment.accept(self,
|
27
|
+
change_orders: change_orders,
|
28
|
+
amount_paid: amount_paid,
|
29
|
+
player: player,
|
30
|
+
target_player: target_player)
|
31
|
+
process_proceeding_to_next_state.(
|
32
|
+
game_board: game_board,
|
33
|
+
change_orders: change_orders)
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_equipment(equipment, change_orders:, amount_paid:, player:, target_player:)
|
37
|
+
change_orders.push(get_equipment_gained_node.(
|
38
|
+
player_id: player.id,
|
39
|
+
equipment: [equipment],
|
40
|
+
reason: {
|
41
|
+
name: 'by_confiscation',
|
42
|
+
target_player_id: target_player.id,
|
43
|
+
amount_paid: amount_paid}))
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_wild_card(equipment, change_orders:, amount_paid:, player:, target_player:)
|
47
|
+
change_orders.push(get_wild_card_gained_node.(
|
48
|
+
player_id: player.id,
|
49
|
+
number_gained: 1,
|
50
|
+
reason: {
|
51
|
+
name: 'by_confiscation',
|
52
|
+
target_player_id: target_player.id,
|
53
|
+
amount_paid: amount_paid}))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen string literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
require 'spy_alley_application/types/game_board'
|
5
|
+
|
6
|
+
module SpyAlleyApplication
|
7
|
+
module Actions
|
8
|
+
class GenerateNewGame
|
9
|
+
include Dry::Initializer.define -> do
|
10
|
+
option :get_result_game_board_node, type: ::Types::Callable, reader: :private
|
11
|
+
option :process_next_turn_options, type: ::Types::Callable, reader: :private
|
12
|
+
option :start_location, default: ->{{id: 0}}, reader: :private
|
13
|
+
end
|
14
|
+
def call(seat_assignments:, change_orders:)
|
15
|
+
cnt = seat_assignments.size
|
16
|
+
players = seat_assignments.map{|s| get_player(s[:id], s[:seat], s[:spy_identity], cnt)}
|
17
|
+
starting_player =
|
18
|
+
game_board = SpyAlleyApplication::Types::GameBoard.call(
|
19
|
+
players: players,
|
20
|
+
move_card_pile: generate_move_card_deck,
|
21
|
+
free_gift_pile: generate_free_gift_deck,
|
22
|
+
game_state: starting_state(players))
|
23
|
+
starting_player_id = players.find{|p| p[:seat].eql?(game_board.game_state.seat)}[:id]
|
24
|
+
other_ids = players.reject{|p| p[:seat].eql?(game_board.game_state.seat)}.map{|p| p[:id]}
|
25
|
+
|
26
|
+
process_next_turn_options.(game_board: game_board,
|
27
|
+
change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def get_player(id, seat, spy_identity, num_players)
|
32
|
+
{
|
33
|
+
id: id,
|
34
|
+
seat: seat,
|
35
|
+
location: start_location,
|
36
|
+
spy_identity: spy_identity,
|
37
|
+
money: 10 * num_players,
|
38
|
+
move_cards: [].freeze,
|
39
|
+
equipment: [].freeze,
|
40
|
+
wild_cards: 0,
|
41
|
+
active?: true
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_move_card_deck
|
46
|
+
move_cards = []
|
47
|
+
(1..6).to_a.each do |num|
|
48
|
+
move_cards = move_cards + ([num] * 6)
|
49
|
+
end
|
50
|
+
move_cards.shuffle
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_free_gift_deck
|
54
|
+
free_gifts = ['wild card'] * 4
|
55
|
+
['french', 'german', 'spanish', 'italian', 'american', 'russian'].each do |nationality|
|
56
|
+
['password', 'disguise', 'codebook', 'key'].each do |equipment_type|
|
57
|
+
free_gifts = free_gifts + (["#{nationality} #{equipment_type}"] * 2)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
free_gifts.shuffle
|
61
|
+
end
|
62
|
+
|
63
|
+
def starting_state(players)
|
64
|
+
starting_seat = players.map{|p| p[:seat]}.min
|
65
|
+
{name: 'start_of_turn', seat: starting_seat}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|