spy_alley_application 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +92 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +39 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/spy_alley_application.rb +6 -0
  13. data/lib/spy_alley_application/actions/buy_equipment.rb +31 -0
  14. data/lib/spy_alley_application/actions/choose_new_spy_identity.rb +26 -0
  15. data/lib/spy_alley_application/actions/choose_space_to_move.rb +21 -0
  16. data/lib/spy_alley_application/actions/confiscate_materials.rb +58 -0
  17. data/lib/spy_alley_application/actions/generate_new_game.rb +70 -0
  18. data/lib/spy_alley_application/actions/make_accusation.rb +40 -0
  19. data/lib/spy_alley_application/actions/pass.rb +21 -0
  20. data/lib/spy_alley_application/actions/roll_die.rb +25 -0
  21. data/lib/spy_alley_application/actions/use_move_card.rb +28 -0
  22. data/lib/spy_alley_application/execute_action.rb +20 -0
  23. data/lib/spy_alley_application/injection_container.rb +596 -0
  24. data/lib/spy_alley_application/models/acquisition_method/by_confiscation.rb +22 -0
  25. data/lib/spy_alley_application/models/acquisition_method/by_free_gift.rb +20 -0
  26. data/lib/spy_alley_application/models/acquisition_method/by_passing_start.rb +20 -0
  27. data/lib/spy_alley_application/models/acquisition_method/by_purchase.rb +21 -0
  28. data/lib/spy_alley_application/models/acquisition_method/by_selling_top_secret_information.rb +21 -0
  29. data/lib/spy_alley_application/models/board_spaces/black_market.rb +24 -0
  30. data/lib/spy_alley_application/models/board_spaces/border_crossing.rb +24 -0
  31. data/lib/spy_alley_application/models/board_spaces/buy_equipment.rb +26 -0
  32. data/lib/spy_alley_application/models/board_spaces/buy_password.rb +26 -0
  33. data/lib/spy_alley_application/models/board_spaces/confiscate_materials.rb +24 -0
  34. data/lib/spy_alley_application/models/board_spaces/draw_free_gift.rb +24 -0
  35. data/lib/spy_alley_application/models/board_spaces/draw_move_card.rb +24 -0
  36. data/lib/spy_alley_application/models/board_spaces/embassy.rb +26 -0
  37. data/lib/spy_alley_application/models/board_spaces/move_back.rb +25 -0
  38. data/lib/spy_alley_application/models/board_spaces/sold_top_secret_information.rb +27 -0
  39. data/lib/spy_alley_application/models/board_spaces/spy_alley_entrance.rb +38 -0
  40. data/lib/spy_alley_application/models/board_spaces/spy_eliminator.rb +24 -0
  41. data/lib/spy_alley_application/models/board_spaces/start.rb +36 -0
  42. data/lib/spy_alley_application/models/board_spaces/take_another_turn.rb +24 -0
  43. data/lib/spy_alley_application/models/equipment.rb +42 -0
  44. data/lib/spy_alley_application/models/game_board.rb +23 -0
  45. data/lib/spy_alley_application/models/game_board/black_market_option_state.rb +59 -0
  46. data/lib/spy_alley_application/models/game_board/buy_equipment_option_state.rb +52 -0
  47. data/lib/spy_alley_application/models/game_board/buy_password_option_state.rb +39 -0
  48. data/lib/spy_alley_application/models/game_board/confiscate_materials_option_state.rb +68 -0
  49. data/lib/spy_alley_application/models/game_board/eliminate_player.rb +91 -0
  50. data/lib/spy_alley_application/models/game_board/embassy_victory.rb +23 -0
  51. data/lib/spy_alley_application/models/game_board/equipment_bought.rb +42 -0
  52. data/lib/spy_alley_application/models/game_board/equipment_confiscated.rb +67 -0
  53. data/lib/spy_alley_application/models/game_board/free_gift_drawn.rb +39 -0
  54. data/lib/spy_alley_application/models/game_board/money_gained_or_lost.rb +22 -0
  55. data/lib/spy_alley_application/models/game_board/move_card_drawn.rb +31 -0
  56. data/lib/spy_alley_application/models/game_board/move_card_used.rb +30 -0
  57. data/lib/spy_alley_application/models/game_board/move_options.rb +23 -0
  58. data/lib/spy_alley_application/models/game_board/new_spy_identity_chosen.rb +37 -0
  59. data/lib/spy_alley_application/models/game_board/next_game_state.rb +70 -0
  60. data/lib/spy_alley_application/models/game_board/player_moved.rb +24 -0
  61. data/lib/spy_alley_application/models/game_board/spy_eliminator_options.rb +41 -0
  62. data/lib/spy_alley_application/models/game_state/buy_equipment.rb +26 -0
  63. data/lib/spy_alley_application/models/game_state/choose_new_spy_identity.rb +29 -0
  64. data/lib/spy_alley_application/models/game_state/confiscate_materials.rb +29 -0
  65. data/lib/spy_alley_application/models/game_state/game_over.rb +27 -0
  66. data/lib/spy_alley_application/models/game_state/move_option.rb +25 -0
  67. data/lib/spy_alley_application/models/game_state/spy_eliminator.rb +25 -0
  68. data/lib/spy_alley_application/models/game_state/start_of_turn.rb +23 -0
  69. data/lib/spy_alley_application/models/game_state/victory_reason/by_elimination.rb +22 -0
  70. data/lib/spy_alley_application/models/game_state/victory_reason/by_embassy.rb +22 -0
  71. data/lib/spy_alley_application/models/move_card.rb +26 -0
  72. data/lib/spy_alley_application/models/player.rb +37 -0
  73. data/lib/spy_alley_application/models/sell_top_secret_information.rb +24 -0
  74. data/lib/spy_alley_application/models/validator/buying_equipment.rb +35 -0
  75. data/lib/spy_alley_application/models/validator/choosing_new_spy_identity.rb +33 -0
  76. data/lib/spy_alley_application/models/validator/confiscating_materials.rb +50 -0
  77. data/lib/spy_alley_application/models/validator/making_accusation.rb +31 -0
  78. data/lib/spy_alley_application/models/validator/moving.rb +30 -0
  79. data/lib/spy_alley_application/models/validator/passing.rb +24 -0
  80. data/lib/spy_alley_application/models/validator/rolling_die.rb +29 -0
  81. data/lib/spy_alley_application/models/validator/using_move_card.rb +31 -0
  82. data/lib/spy_alley_application/models/wild_card.rb +25 -0
  83. data/lib/spy_alley_application/new_game.rb +18 -0
  84. data/lib/spy_alley_application/new_game/assign_seats.rb +21 -0
  85. data/lib/spy_alley_application/new_game/assign_spy_identities.rb +24 -0
  86. data/lib/spy_alley_application/results/nodes/buy_equipment_option_node.rb +23 -0
  87. data/lib/spy_alley_application/results/nodes/choose_new_spy_identity_option_node.rb +23 -0
  88. data/lib/spy_alley_application/results/nodes/confiscate_materials_option_node.rb +22 -0
  89. data/lib/spy_alley_application/results/nodes/die_rolled_node.rb +21 -0
  90. data/lib/spy_alley_application/results/nodes/eliminated_player_node.rb +22 -0
  91. data/lib/spy_alley_application/results/nodes/equipment_gained_node.rb +28 -0
  92. data/lib/spy_alley_application/results/nodes/game_over_node.rb +24 -0
  93. data/lib/spy_alley_application/results/nodes/make_accusation_option_node.rb +20 -0
  94. data/lib/spy_alley_application/results/nodes/money_gained_node.rb +25 -0
  95. data/lib/spy_alley_application/results/nodes/money_lost_node.rb +21 -0
  96. data/lib/spy_alley_application/results/nodes/move_back_node.rb +21 -0
  97. data/lib/spy_alley_application/results/nodes/move_card_drawn_node.rb +22 -0
  98. data/lib/spy_alley_application/results/nodes/move_card_used_node.rb +22 -0
  99. data/lib/spy_alley_application/results/nodes/move_option_node.rb +20 -0
  100. data/lib/spy_alley_application/results/nodes/new_spy_identity_chosen_node.rb +21 -0
  101. data/lib/spy_alley_application/results/nodes/next_player_node.rb +20 -0
  102. data/lib/spy_alley_application/results/nodes/pass_option_node.rb +16 -0
  103. data/lib/spy_alley_application/results/nodes/player_movement_node.rb +21 -0
  104. data/lib/spy_alley_application/results/nodes/player_passed_node.rb +19 -0
  105. data/lib/spy_alley_application/results/nodes/reached_embassy_with_all_equipment_node.rb +20 -0
  106. data/lib/spy_alley_application/results/nodes/result_game_board_node.rb +21 -0
  107. data/lib/spy_alley_application/results/nodes/roll_die_option_node.rb +16 -0
  108. data/lib/spy_alley_application/results/nodes/use_move_card_option_node.rb +20 -0
  109. data/lib/spy_alley_application/results/nodes/wild_card_gained_node.rb +27 -0
  110. data/lib/spy_alley_application/results/process_buy_equipment_options.rb +25 -0
  111. data/lib/spy_alley_application/results/process_eliminating_player.rb +36 -0
  112. data/lib/spy_alley_application/results/process_landing_on_space.rb +232 -0
  113. data/lib/spy_alley_application/results/process_move_options.rb +65 -0
  114. data/lib/spy_alley_application/results/process_next_turn_options.rb +87 -0
  115. data/lib/spy_alley_application/results/process_passing_spaces.rb +68 -0
  116. data/lib/spy_alley_application/results/process_proceeding_to_next_state.rb +23 -0
  117. data/lib/spy_alley_application/types/array_of_equipment.rb +7 -0
  118. data/lib/spy_alley_application/types/array_of_free_gifts.rb +7 -0
  119. data/lib/spy_alley_application/types/array_of_move_cards.rb +6 -0
  120. data/lib/spy_alley_application/types/array_of_players.rb +6 -0
  121. data/lib/spy_alley_application/types/board_space.rb +4 -0
  122. data/lib/spy_alley_application/types/coercible_integer_one_to_six.rb +9 -0
  123. data/lib/spy_alley_application/types/equipment.rb +32 -0
  124. data/lib/spy_alley_application/types/equipment_type.rb +9 -0
  125. data/lib/spy_alley_application/types/free_gift.rb +22 -0
  126. data/lib/spy_alley_application/types/game_board.rb +52 -0
  127. data/lib/spy_alley_application/types/game_state.rb +19 -0
  128. data/lib/spy_alley_application/types/move_card.rb +21 -0
  129. data/lib/spy_alley_application/types/nationality.rb +5 -0
  130. data/lib/spy_alley_application/types/player.rb +123 -0
  131. data/lib/spy_alley_application/types/validation_builder.rb +21 -0
  132. data/lib/spy_alley_application/types/validator/non_admin.rb +21 -0
  133. data/lib/spy_alley_application/types/wild_card.rb +14 -0
  134. data/lib/spy_alley_application/validator/builder.rb +119 -0
  135. data/lib/spy_alley_application/validator/buy_equipment.rb +39 -0
  136. data/lib/spy_alley_application/validator/choose_new_spy_identity.rb +24 -0
  137. data/lib/spy_alley_application/validator/confiscate_materials.rb +22 -0
  138. data/lib/spy_alley_application/validator/confiscate_materials/full_validator.rb +39 -0
  139. data/lib/spy_alley_application/validator/confiscate_materials/validate_target_player_id.rb +24 -0
  140. data/lib/spy_alley_application/validator/make_accusation.rb +24 -0
  141. data/lib/spy_alley_application/validator/move.rb +24 -0
  142. data/lib/spy_alley_application/validator/new_game.rb +35 -0
  143. data/lib/spy_alley_application/validator/new_game_builder.rb +32 -0
  144. data/lib/spy_alley_application/validator/no_options.rb +7 -0
  145. data/lib/spy_alley_application/validator/use_move_card.rb +23 -0
  146. data/lib/spy_alley_application/version.rb +3 -0
  147. data/spy_alley_application.gemspec +40 -0
  148. metadata +343 -0
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/models/acquisition_method/by_passing_start'
5
+ require 'spy_alley_application/models/acquisition_method/by_selling_top_secret_information'
6
+
7
+ module SpyAlleyApplication
8
+ module Results
9
+ module Nodes
10
+ class MoneyGainedNode < Dry::Struct
11
+ @@can_handle_money_gained = ::Types.Interface(:handle_money_gained)
12
+ attribute :player_id, ::Types::Coercible::Integer
13
+ attribute :money_gained, ::Types::CoercibleNonnegativeInteger
14
+ attribute :reason, SpyAlleyApplication::Models::AcquisitionMethod::ByPassingStart |
15
+ SpyAlleyApplication::Models::AcquisitionMethod::BySellingTopSecretInformation
16
+
17
+ def accept(visitor, **args)
18
+ @can_handle_money_gained.(visitor)
19
+ visitor.handle_money_gained(self, args)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class MoneyLostNode < Dry::Struct
9
+ @@can_handle_money_lost = ::Types.Interface(:handle_money_lost)
10
+ attribute :player_id, ::Types::Coercible::Integer
11
+ attribute :money_lost, ::Types::CoercibleNonnegativeInteger
12
+
13
+ def accept(visitor, **args)
14
+ @can_handle_money_lost.(visitor)
15
+ visitor.handle_money_lost(self, args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class MoveBackNode < Dry::Struct
9
+ @@can_handle_money_gained = ::Types.Interface(:handle_move_back)
10
+ attribute :player_id, ::Types::Coercible::Integer
11
+ attribute :player_moved, ::Types.Interface(:accept)
12
+
13
+ def accept(visitor, **args)
14
+ @can_handle_move_back.(visitor)
15
+ visitor.handle_move_back(self, args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/types/coercible_integer_one_to_six'
5
+
6
+ module SpyAlleyApplication
7
+ module Results
8
+ module Nodes
9
+ class MoveCardDrawnNode < Dry::Struct
10
+ @@can_handle_move_card_drawn = ::Types.Interface(:handle_move_card_drawn)
11
+ attribute :player_id, ::Types::Coercible::Integer
12
+ attribute :card, SpyAlleyApplication::Types::CoercibleIntegerOneToSix
13
+
14
+ def accept(visitor, **args)
15
+ @can_handle_move_card_drawn.(visitor)
16
+ visitor.handle_card_card_drawn(self, args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/types/coercible_integer_one_to_six'
5
+
6
+ module SpyAlleyApplication
7
+ module Results
8
+ module Nodes
9
+ class MoveCardUsedNode < Dry::Struct
10
+ @@can_handle_move_card_used = ::Types.Interface(:handle_move_card_used)
11
+ attribute :player_id, ::Types::Coercible::Integer
12
+ attribute :card, SpyAlleyApplication::Types::CoercibleIntegerOneToSix
13
+
14
+ def accept(visitor, **args)
15
+ @can_handle_move_card_used.(visitor)
16
+ visitor.handle_card_card_used(self, args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class MoveOptionNode < Dry::Struct
9
+ @@can_handle_move_option = ::Types.Interface(:handle_move_option)
10
+ attribute :options, ::Types::ArrayOfStrictInteger
11
+
12
+ def accept(visitor, **args)
13
+ @can_handle_move_option.(visitor)
14
+ visitor.handle_move_option(self, args)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/types/nationality'
5
+
6
+ module SpyAlleyApplication
7
+ module Results
8
+ module Nodes
9
+ class NewSpyIdentityChosenNode < Dry::Struct
10
+ @@can_handle_move_option = ::Types.Interface(:handle_new_spy_identity_chosen)
11
+ attribute :nationality, SpyAlleyApplication::Types::Nationality
12
+
13
+ def accept(visitor, **args)
14
+ @can_handle_new_spy_identity_chosen.(visitor)
15
+ visitor.handle_new_spy_identity_chosen(self, args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class NextPlayerNode < Dry::Struct
9
+ @@can_handle_next_player = ::Types.Interface(:handle_next_player)
10
+ attribute :player_id, ::Types::Strict::Integer
11
+
12
+ def accept(visitor, **args)
13
+ @@can_handle_next_player.(visitor)
14
+ visitor.handle_next_player(self, args)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyAlleyApplication
4
+ module Results
5
+ module Nodes
6
+ class PassOptionNode
7
+ @@can_handle_roll_die_option = ::Types.Interface(:handle_roll_die_option)
8
+ def accept(visitor, **args)
9
+ @@can_handle_roll_die_option.(visitor)
10
+ visitor.handle_roll_die_option(self, args)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class PlayerMovementNode < Dry::Struct
9
+ @@can_handle_player_movement = ::Types.Interface(:handle_player_movement)
10
+ attribute :player_id, ::Types::Strict::Integer
11
+ attribute :space_id, ::Types::Strict::Integer
12
+
13
+ def accept(visitor, **args)
14
+ @can_handle_player_movement.(visitor)
15
+ visitor.handle_player_movement(self, args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class PlayerPassedNode < Dry::Struct
9
+ @@can_handle_player_passed = ::Types.Interface(:handle_player_passed)
10
+
11
+ def accept(visitor, **args)
12
+ @can_handle_player_passed.(visitor)
13
+ visitor.handle_player_passed(self, args)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class ReachedEmbassyWithAllEquipmentNode < Dry::Struct
9
+ @@can_handle_reaced_embassy_with_all_equipment =
10
+ ::Types.Interface(:handle_reaced_embassy_with_all_equipment)
11
+
12
+ def accept(visitor, **args)
13
+ @can_handle_reached_embassy_with_all_equipment.(visitor)
14
+ visitor.handle_reached_embassy_with_all_equipment(self, args)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/models/game_board'
5
+
6
+ module SpyAlleyApplication
7
+ module Results
8
+ module Nodes
9
+ class ResultGameBoardNode < Dry::Struct
10
+ @@can_handle_result_game_board = ::Types.Interface(:handle_result_game_board)
11
+ attribute :game_board, SpyAlleyApplication::Models::GameBoard
12
+
13
+ def accept(visitor, **args)
14
+ @@can_handle_result_game_board.(visitor)
15
+ visitor.handle_result_game_board(self, args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyAlleyApplication
4
+ module Results
5
+ module Nodes
6
+ class RollDieOptionNode
7
+ @@can_handle_roll_die_option = ::Types.Interface(:handle_roll_die_option)
8
+ def accept(visitor, **args)
9
+ @@can_handle_roll_die_option.(visitor)
10
+ visitor.handle_roll_die_option(self, args)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ module Nodes
8
+ class UseMoveCardOptionNode < Dry::Struct
9
+ @@can_handle_use_move_card = ::Types.Interface(:handle_use_move_card)
10
+ attribute :card_list, ::Types::ArrayOfStrictInteger
11
+
12
+ def accept(visitor, **args)
13
+ @@can_handle_use_move_card.(visitor)
14
+ visitor.handle_use_move_card(self, args)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'spy_alley_application/models/acquisition_method/by_confiscation'
5
+ require 'spy_alley_application/models/acquisition_method/by_free_gift'
6
+ require 'spy_alley_application/models/acquisition_method/by_purchase'
7
+
8
+ module SpyAlleyApplication
9
+ module Results
10
+ module Nodes
11
+ class WildCardGainedNode < Dry::Struct
12
+ @@can_handle_wild_card_gained = ::Types.Interface(:handle_wild_card_gained)
13
+ attribute :player_id, ::Types::Coercible::Integer
14
+ attribute :number_gained, ::Types::CoercibleNonnegativeInteger
15
+ attribute :reason, SpyAlleyApplication::Models::AcquisitionMethod::ByConfiscation |
16
+ SpyAlleyApplication::Models::AcquisitionMethod::ByFreeGift |
17
+ SpyAlleyApplication::Models::AcquisitionMethod::ByPurchase
18
+
19
+ def accept(visitor, **args)
20
+ @can_handle_wild_card_gained.(visitor)
21
+ visitor.handle_wild_card_gained(self, args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+ require 'spy_alley_application/models/game_state/buy_equipment'
5
+
6
+ module SpyAlleyApplication
7
+ module Results
8
+ class ProcessBuyEquipmentOptions
9
+ include Dry::Initializer.define -> do
10
+ option :get_buy_equipment_option_node, type: ::Types::Callable, reader: :private
11
+ option :get_next_player_node, type: ::Types::Callable, reader: :private
12
+ option :get_pass_option_node, type: ::Types::Callable, reader: :private
13
+ end
14
+
15
+ def call(game_board:, change_orders:)
16
+ next_player = game_board.players.find{|p| p.seat.eql?(game_board.game_state.seat)}
17
+ node = SpyAlleyApplication::Models::GameState::BuyEquipment.call(game_board.game_state)
18
+ change_orders.push(get_next_player_node.(player_id: next_player.id))
19
+ .push(get_buy_equipment_node.(options: node.options, limit: node.limit))
20
+ .push(get_pass_option_node.())
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module SpyAlleyApplication
6
+ module Results
7
+ class ProcessEliminatingPlayer
8
+ include Dry::Initializer.define -> do
9
+ option :get_eliminated_player_node, type: ::Types::Callable, reader: :private
10
+ option :get_game_over_node, type: ::Types::Callable, reader: :private
11
+ option :get_result_game_board_node, type: ::Types::Callable, reader: :private
12
+ option :eliminate_player, type: ::Types::Callable, reader: :private
13
+ option :process_next_turn_options, type: ::Types::Callable, reader: :private
14
+ end
15
+
16
+ def call(game_board:, change_orders:, eliminating_player:, eliminated_player:)
17
+ change_orders = change_orders.push(get_eliminated_player_node.(
18
+ eliminating_player: eliminating_player,
19
+ eliminated_player: eliminated_player))
20
+ game_board = eliminate_player.(
21
+ game_board: game_board,
22
+ eliminating_player: eliminating_player,
23
+ eliminated_player: eliminated_player)
24
+ if game_board.players.count(&:active) < 2
25
+ change_orders = change_orders.push(get_game_over_node.(
26
+ winning_player_id: eliminating_player.id,
27
+ reason: {name: 'by_elimination'}))
28
+ end
29
+ process_next_turn_options.(
30
+ game_board: game_board,
31
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,232 @@
1
+ # require 'dry-initializer'
2
+
3
+ module SpyAlleyApplication
4
+ module Results
5
+ class ProcessLandingOnSpace
6
+ include Dry::Initializer.define -> do
7
+ option :black_market_option_state, type: ::Types::Callable, reader: :private
8
+ option :buy_equipment_option_state, type: ::Types::Callable, reader: :private
9
+ option :buy_password_option_state, type: ::Types::Callable, reader: :private
10
+ option :confiscate_materials_option_state, type: ::Types::Callable, reader: :private
11
+ option :embassy_victory, type: ::Types::Callable, reader: :private
12
+ option :free_gift_drawn, type: ::Types::Callable, reader: :private
13
+ option :get_equipment_gained_node, type: ::Types::Callable, reader: :private
14
+ option :get_game_over_node, type: ::Types::Callable, reader: :private
15
+ option :get_money_gained_node, type: ::Types::Callable, reader: :private
16
+ option :get_money_lost_node, type: ::Types::Callable, reader: :private
17
+ option :get_move_card_drawn_node, type: ::Types::Callable, reader: :private
18
+ option :get_player_movement_node, type: ::Types::Callable, reader: :private
19
+ option :get_result_game_board_node, type: ::Types::Callable, reader: :private
20
+ option :get_wild_card_gained_node, type: ::Types::Callable, reader: :private
21
+ option :money_gained_or_lost, type: ::Types::Callable, reader: :private
22
+ option :move_card_drawn, type: ::Types::Callable, reader: :private
23
+ option :next_game_state, type: ::Types::Callable, reader: :private
24
+ option :player_moved, type: ::Types::Callable, reader: :private
25
+ option :process_next_turn_options, type: ::Types::Callable, reader: :private
26
+ option :process_proceeding_to_next_state, type: ::Types::Callable, reader: :private
27
+ option :spy_eliminator_options, type: ::Types::Callable, reader: :private
28
+ end
29
+
30
+ def call(game_board:, change_orders:, space_id:)
31
+ player = game_board.current_player
32
+ change_orders = change_orders.push(get_player_movement_node.(
33
+ player_id: player.id,
34
+ space_id: space_id))
35
+ game_board = player_moved.(game_board: game_board, new_location: {id: space_id})
36
+ board_space = game_board.current_player.location
37
+ board_space.accept(self, game_board: game_board, change_orders: change_orders)
38
+ end
39
+
40
+ # ///////////////
41
+
42
+ def handle_black_market(board_space, game_board:, change_orders:)
43
+ game_board = black_market_option_state.(game_board: game_board)
44
+ process_next_turn_options.(
45
+ game_board: game_board,
46
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
47
+ end
48
+
49
+ # ///////////////
50
+
51
+ def handle_border_crossing(board_space, game_board:, change_orders:)
52
+ change_orders = change_orders.push(get_money_lost_node.(
53
+ player_id: game_board.current_player.id,
54
+ money_lost: 5))
55
+ game_board = money_gained_or_lost.(
56
+ game_board: game_board,
57
+ money_adjustment: -5)
58
+ process_proceeding_to_next_state.(
59
+ game_board: game_board,
60
+ change_orders: change_orders)
61
+ end
62
+
63
+ # ///////////////
64
+
65
+ def handle_buy_equipment(board_space, game_board:, change_orders:)
66
+ game_board = buy_equipment_option_state.(
67
+ game_board: game_board,
68
+ equipment_type: board_space.equipment_type)
69
+ process_next_turn_options.(
70
+ game_board: game_board,
71
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
72
+ end
73
+
74
+ # ///////////////
75
+
76
+ def handle_buy_password(board_space, game_board:, change_orders:)
77
+ game_board = buy_password_option_state.(
78
+ game_board: game_board,
79
+ nationality: board_space.nationality)
80
+ process_next_turn_options.(
81
+ game_board: game_board,
82
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
83
+ end
84
+
85
+ # ///////////////
86
+
87
+ def handle_confiscate_materials(board_space, game_board:, change_orders:)
88
+ game_board = confiscate_materials_option_state.(game_board: game_board)
89
+ process_next_turn_options.(
90
+ game_board: game_board,
91
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
92
+ end
93
+
94
+ # ///////////////
95
+
96
+ def handle_draw_free_gift(board_space, game_board:, change_orders:)
97
+ change_orders = game_board.free_gift_pile.first.accept(self,
98
+ change_orders: change_orders,
99
+ player_id: game_board.current_player.id)
100
+ game_board = free_gift_drawn.(game_board: game_board)
101
+ process_proceeding_to_next_state.(
102
+ game_board: game_board,
103
+ change_orders: change_orders)
104
+ end
105
+
106
+ def handle_equipment(equipment, change_orders:, player_id:)
107
+ change_orders.push(get_equipment_gained_node.(
108
+ player_id: player_id,
109
+ equipment: [equipment],
110
+ reason: {name: 'by_free_gift'}))
111
+ end
112
+
113
+ def handle_wild_card(wild_card, change_orders:, player_id:)
114
+ change_orders.push(get_wild_card_gained_node.(
115
+ player_id: player_id,
116
+ number_gained: 1,
117
+ reason: {name: 'by_free_gift'}))
118
+ end
119
+
120
+ # ///////////////
121
+
122
+ def handle_draw_move_card(board_space, game_board:, change_orders:)
123
+ change_orders = change_orders.push(get_move_card_drawn_node.(
124
+ player_id: game_board.current_player.id,
125
+ card: game_board.move_card_pile.first.value))
126
+ game_board = move_card_drawn.(game_board: game_board)
127
+ process_proceeding_to_next_state.(
128
+ game_board: game_board,
129
+ change_orders: change_orders)
130
+ end
131
+
132
+ # ///////////////
133
+
134
+ def handle_embassy(board_space, game_board:, change_orders:)
135
+ player = game_board.current_player
136
+ spy_identity = player.spy_identity
137
+ equipment_total = player.equipment.select{|e| e.nationality.eql?(spy_identity)}.size
138
+ equipment_total += player.wild_cards
139
+ if equipment_total >= 4
140
+ change_orders
141
+ .push(get_game_over_node.(winning_player_id: player.id, reason: {name: 'by_embassy'}))
142
+ .push(get_result_game_board_node.(
143
+ game_board: embassy_victory.(game_board: game_board)))
144
+ else
145
+ process_proceeding_to_next_state.(
146
+ game_board: game_board,
147
+ change_orders: change_orders)
148
+ end
149
+ end
150
+
151
+ # ///////////////
152
+
153
+ def handle_move_back(board_space, game_board:, change_orders:)
154
+ game_board = game_board = player_moved.(
155
+ game_board: game_board,
156
+ new_location: board_space.move_back_space)
157
+ change_orders = change_orders.push(get_player_movement_node.(
158
+ player_id: game_board.current_player.id,
159
+ space_id: board_space.move_back_space.id))
160
+ game_board = game_board = player_moved.(game_board: game_board, new_location: board_space)
161
+ process_proceeding_to_next_state.(
162
+ game_board: game_board,
163
+ change_orders: change_orders)
164
+ end
165
+
166
+ # ///////////////
167
+
168
+ def handle_sold_top_secret_information(board_space, game_board:, change_orders:)
169
+ current_player = game_board.current_player
170
+
171
+ game_board = money_gained_or_lost.(
172
+ game_board: game_board,
173
+ money_adjustment: board_space.money_gained)
174
+
175
+ process_proceeding_to_next-state.(
176
+ game_board: game_board,
177
+ change_orders: change_orders
178
+ .push(get_money_gained_node.(
179
+ player_id: current_player.id,
180
+ money_gained: board_space.money_gained,
181
+ reason: {name: 'by_selling_top_secret_information'})))
182
+ end
183
+
184
+ # ///////////////
185
+
186
+ def handle_spy_alley_entrance(board_space, game_board:, change_orders:)
187
+ process_proceeding_to_next_state.(
188
+ game_board: game_board,
189
+ change_orders: change_orders)
190
+ end
191
+
192
+ # ///////////////
193
+
194
+ def handle_spy_eliminator(board_space, game_board:, change_orders:)
195
+ game_board = spy_eliminator_options.(game_board: game_board)
196
+
197
+ process_next_turn_options.(
198
+ game_board: next_game_state.(game_board: game_board),
199
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
200
+ end
201
+
202
+ # ///////////////
203
+
204
+ def handle_start(board_space, game_board:, change_orders:)
205
+ current_player = game_board.current_player
206
+
207
+ game_board = money_gained_or_lost.(
208
+ game_board: game_board,
209
+ money_adjustment: 15,
210
+ &next_game_state)
211
+
212
+ process_next_turn_options.(
213
+ game_board: game_board,
214
+ change_orders: change_orders
215
+ .push(get_money_gained_node.(
216
+ player_id: current_player.id,
217
+ money_gained: 15,
218
+ reason: {name: 'by_passing_start'}))
219
+ .push(get_result_game_board_node.(game_board: game_board)))
220
+ end
221
+
222
+ # ///////////////
223
+
224
+ def handle_take_another_turn(board_space, game_board:, change_orders:)
225
+ process_next_turn_options.(
226
+ game_board: game_board,
227
+ change_orders: change_orders.push(get_result_game_board_node.(game_board: game_board)))
228
+ end
229
+ end
230
+ end
231
+ end
232
+