love_letter_application 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +91 -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/love_letter_application.rb +7 -0
  13. data/lib/love_letter_application/action_creator.rb +16 -0
  14. data/lib/love_letter_application/actions/clown.rb +45 -0
  15. data/lib/love_letter_application/actions/general.rb +29 -0
  16. data/lib/love_letter_application/actions/knight.rb +31 -0
  17. data/lib/love_letter_application/actions/marquess.rb +28 -0
  18. data/lib/love_letter_application/actions/play_card.rb +33 -0
  19. data/lib/love_letter_application/actions/priestess.rb +36 -0
  20. data/lib/love_letter_application/actions/princess.rb +32 -0
  21. data/lib/love_letter_application/actions/soldier.rb +47 -0
  22. data/lib/love_letter_application/actions/wizard.rb +31 -0
  23. data/lib/love_letter_application/execute_action.rb +21 -0
  24. data/lib/love_letter_application/love_letter_imports.rb +641 -0
  25. data/lib/love_letter_application/models/card.rb +23 -0
  26. data/lib/love_letter_application/models/effects/discard_and_draw.rb +51 -0
  27. data/lib/love_letter_application/models/effects/eliminate_player.rb +43 -0
  28. data/lib/love_letter_application/models/effects/make_player_not_targetable.rb +44 -0
  29. data/lib/love_letter_application/models/effects/next_player_draw_card.rb +45 -0
  30. data/lib/love_letter_application/models/effects/play_card.rb +48 -0
  31. data/lib/love_letter_application/models/effects/round_complete.rb +29 -0
  32. data/lib/love_letter_application/models/effects/switch_hands.rb +50 -0
  33. data/lib/love_letter_application/models/game_board.rb +28 -0
  34. data/lib/love_letter_application/models/player.rb +36 -0
  35. data/lib/love_letter_application/results/eliminate_player.rb +43 -0
  36. data/lib/love_letter_application/results/nodes/card_played_node.rb +15 -0
  37. data/lib/love_letter_application/results/nodes/card_viewed_node.rb +21 -0
  38. data/lib/love_letter_application/results/nodes/discard_card_node.rb +20 -0
  39. data/lib/love_letter_application/results/nodes/drawn_card_node.rb +20 -0
  40. data/lib/love_letter_application/results/nodes/eliminated_player_node.rb +19 -0
  41. data/lib/love_letter_application/results/nodes/hands_switched_node.rb +22 -0
  42. data/lib/love_letter_application/results/nodes/knight_drawn_node.rb +15 -0
  43. data/lib/love_letter_application/results/nodes/knight_victory_node.rb +20 -0
  44. data/lib/love_letter_application/results/nodes/log_node.rb +20 -0
  45. data/lib/love_letter_application/results/nodes/next_player_node.rb +19 -0
  46. data/lib/love_letter_application/results/nodes/play_card_with_no_args_option_node.rb +19 -0
  47. data/lib/love_letter_application/results/nodes/play_card_with_player_id_and_card_id_option_node.rb +21 -0
  48. data/lib/love_letter_application/results/nodes/play_card_with_player_id_option_node.rb +20 -0
  49. data/lib/love_letter_application/results/nodes/player_not_targetable_node.rb +14 -0
  50. data/lib/love_letter_application/results/nodes/player_victory_node.rb +20 -0
  51. data/lib/love_letter_application/results/nodes/players_and_scores_node.rb +44 -0
  52. data/lib/love_letter_application/results/nodes/princess_discarded_node.rb +19 -0
  53. data/lib/love_letter_application/results/nodes/result_game_board_node.rb +19 -0
  54. data/lib/love_letter_application/results/process_correct_guess.rb +22 -0
  55. data/lib/love_letter_application/results/process_draw_after_discard.rb +26 -0
  56. data/lib/love_letter_application/results/process_incorrect_guess.rb +20 -0
  57. data/lib/love_letter_application/results/process_knight_showdown.rb +50 -0
  58. data/lib/love_letter_application/results/process_next_player_turn.rb +57 -0
  59. data/lib/love_letter_application/results/process_next_turn_options.rb +53 -0
  60. data/lib/love_letter_application/results/process_princess_discarded.rb +23 -0
  61. data/lib/love_letter_application/results/process_resolve_wizard.rb +36 -0
  62. data/lib/love_letter_application/results/process_round_complete_by_depleted_deck.rb +50 -0
  63. data/lib/love_letter_application/results/process_round_complete_by_elimination.rb +26 -0
  64. data/lib/love_letter_application/results/process_switch_hands.rb +51 -0
  65. data/lib/love_letter_application/results/yield_to_block.rb +12 -0
  66. data/lib/love_letter_application/types/card.rb +20 -0
  67. data/lib/love_letter_application/types/game_board.rb +59 -0
  68. data/lib/love_letter_application/types/player.rb +25 -0
  69. data/lib/love_letter_application/validator/base.rb +19 -0
  70. data/lib/love_letter_application/validator/builder.rb +50 -0
  71. data/lib/love_letter_application/validator/get_legal_card_ids.rb +23 -0
  72. data/lib/love_letter_application/validator/get_legal_card_ids/marquess.rb +18 -0
  73. data/lib/love_letter_application/validator/play_card.rb +21 -0
  74. data/lib/love_letter_application/validator/play_card/builder.rb +23 -0
  75. data/lib/love_letter_application/validator/play_card/no_options.rb +19 -0
  76. data/lib/love_letter_application/validator/play_card/select_target_player.rb +30 -0
  77. data/lib/love_letter_application/validator/play_card/select_target_player/builder.rb +44 -0
  78. data/lib/love_letter_application/validator/play_card/soldier.rb +39 -0
  79. data/lib/love_letter_application/validator/play_card/soldier/builder.rb +49 -0
  80. data/lib/love_letter_application/validator/validate_card_id.rb +23 -0
  81. data/lib/love_letter_application/version.rb +3 -0
  82. data/love_letter_application.gemspec +43 -0
  83. metadata +278 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 779df85beb66706f7a8a09cd4614ab31c91bad57b378e1817279db005efb0dd6
4
+ data.tar.gz: 54b0d892d5f01521bf08b202f27ea3d4bb66b554d45234dc830ecef112a2c5f4
5
+ SHA512:
6
+ metadata.gz: 6376cc5d1433c3fdd2e8a8855c5b1dd087ca8ca62d23b2de4099c571193098f9bd30f9e13593356f05e58621eafda9482c063e3bea5d2ce1fc57600c42ede16d
7
+ data.tar.gz: 17536eec4d38b8a8ad1754c5159ceafe8662932f905e49e47d54a32b43daf110bdbc809ec26cb932e39e889ae1e4afd26b613c5af198ac50fceeae93f6d025d9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in love_letter_application.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ love_letter_application (0.1.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.0)
57
+ ice_nine (0.11.2)
58
+ rake (10.5.0)
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
+
76
+ DEPENDENCIES
77
+ bundler (~> 2.0)
78
+ change_orders
79
+ dry-auto_inject
80
+ dry-initializer
81
+ dry-monads
82
+ dry-struct
83
+ dry-types
84
+ dry-validation
85
+ game_validator (~> 0.6.0)
86
+ love_letter_application!
87
+ rake (~> 10.0)
88
+ rspec (~> 3.0)
89
+
90
+ BUNDLED WITH
91
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Colin Horner
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
+ # LoveLetterApplication
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/love_letter_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 'love_letter_application'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install love_letter_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]/love_letter_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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "love_letter_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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'love_letter_application/version'
2
+ require 'game_validator'
3
+
4
+ module LoveLetterApplication
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ class ActionCreator
7
+ extend Dry::Initializer
8
+
9
+ option :actions, type: Types::Array.of(Types.Interface(:call))
10
+
11
+ def call(validation_result)
12
+ actions[validation_result.card_to_play]
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class Clown
8
+ include Dry::Initializer.define -> do
9
+ option :play_card, type: ::Types::Callable
10
+ option :get_card_played_node, type: ::Types::Callable
11
+ option :get_card_viewed_node, type: ::Types::Callable
12
+ option :process_next_player_turn, type: ::Types::Callable
13
+ end
14
+
15
+ def call(target_player_id:, game_board:, change_orders:)
16
+ game_board = play_card.(
17
+ game_board: game_board,
18
+ card_id: Clown::id)
19
+ change_orders = change_orders.push(get_card_played_node.(
20
+ player_id: game_board.current_player_id.to_i,
21
+ card_id: Clown::id))
22
+ process_next_player_turn.(
23
+ game_board: game_board,
24
+ change_orders: change_orders.push(get_card_viewed_node.(
25
+ player_id: game_board.current_player_id.to_i,
26
+ target_player_id: target_player_id.to_i,
27
+ card_id: get_card_id(game_board, target_player_id.to_i))))
28
+
29
+ end
30
+
31
+ def self.id;2;end
32
+
33
+ private
34
+ def get_card_id(game_board, target_player_id)
35
+ game_board.players
36
+ .find{|player| player.id.to_i.eql?(target_player_id)}
37
+ .hand
38
+ .first
39
+ .id
40
+ .to_i
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class General
8
+ include Dry::Initializer.define -> do
9
+ option :play_card, type: ::Types::Callable
10
+ option :get_card_played_node, type: ::Types::Callable
11
+ option :process_switch_hands, type: ::Types::Callable
12
+ end
13
+
14
+ def call(target_player_id:, game_board:, change_orders:)
15
+ game_board = play_card.(game_board: game_board, card_id: General::id)
16
+ change_orders = change_orders.push(get_card_played_node.(
17
+ player_id: game_board.current_player_id.to_i,
18
+ card_id: General::id))
19
+ process_switch_hands.(
20
+ target_player_id: target_player_id,
21
+ game_board: game_board,
22
+ change_orders: change_orders)
23
+ end
24
+
25
+ def self.id;6;end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class Knight
8
+ include Dry::Initializer.define -> do
9
+ option :play_card, type: ::Types::Callable
10
+ option :get_card_played_node, type: ::Types::Callable
11
+ option :process_knight_showdown, type: ::Types::Callable
12
+ end
13
+
14
+ def call(target_player_id:, game_board:, change_orders:)
15
+ game_board = play_card.(
16
+ game_board: game_board,
17
+ card_id: Knight::id)
18
+ change_orders = change_orders.push(get_card_played_node.(
19
+ player_id: game_board.current_player_id.to_i,
20
+ card_id: Knight::id))
21
+ process_knight_showdown.(
22
+ target_player_id: target_player_id.to_i,
23
+ game_board: game_board,
24
+ change_orders: change_orders)
25
+ end
26
+
27
+ def self.id;3;end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class Marquess
8
+ include Dry::Initializer.define -> do
9
+ option :play_card, type: ::Types::Callable
10
+ option :get_card_played_node, type: ::Types::Callable
11
+ option :process_next_player_turn, type: ::Types::Callable
12
+ end
13
+
14
+ def call(game_board:, change_orders:)
15
+ game_board = play_card.(game_board: game_board, card_id: Marquess::id)
16
+ change_orders = change_orders.push(get_card_played_node.(
17
+ player_id: game_board.current_player_id.to_i,
18
+ card_id: Marquess::id))
19
+ process_next_player_turn.(
20
+ game_board: game_board,
21
+ change_orders: change_orders)
22
+ end
23
+
24
+ def self.id;7;end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class PlayCard
8
+ extend Dry::Initializer
9
+ option :get_played_card_node, type: ::Types.Interface(:call)
10
+ oprion :get_game_board_with_played_card, type: ::Types.Interface(:call)
11
+ option :resolve_card_action_for, type: ::Types::Array::of(::Types.Interface(:call))
12
+ def call(**args)
13
+ card_id = args[:card_id].to_i
14
+ change_orders = args[:change_orders]
15
+ game_board = args[:game_board]
16
+ player_id = game_board.current_player_id.to_i
17
+ change_orders = change_orders.push(
18
+ get_played_card_node.(
19
+ player_id: player_id,
20
+ card_id: card_id))
21
+ game_board = get_game_board_with_played_card.(
22
+ game_board: game_board,
23
+ player_id: player_id,
24
+ card_id: card_id)
25
+ new_args = args.reject{|k, v| [:change_orders, :game_board].include?(k)}
26
+ new_args[:change_orders] = change_orders
27
+ new_args[:game_board] = game_board
28
+ resolve_card_action_for[card_id].(new_args)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module LoveLetterApplication
6
+ module Actions
7
+ class Priestess
8
+ include Dry::Initializer.define -> do
9
+ option :play_card, type: ::Types::Callable
10
+ option :get_card_played_node, type: ::Types::Callable
11
+ option :make_player_not_targetable, ::Types::Callable
12
+ option :get_player_not_targetable_node, type: ::Types::Callable
13
+ option :process_next_player_turn, type: ::Types::Callable
14
+ end
15
+
16
+ def call(game_board:, change_orders:)
17
+ game_board = play_card.(
18
+ game_board: game_board,
19
+ card_id: Priestess::id)
20
+ game_board = make_player_not_targetable.(
21
+ game_board: game_board,
22
+ player_id: game_board.current_player_id.to_i)
23
+ change_orders = change_orders.push(get_card_played_node.(
24
+ player_id: game_board.current_player_id.to_i,
25
+ card_id: Priestess::id))
26
+ process_next_player_turn.(
27
+ game_board: game_board,
28
+ change_orders: change_orders.push(get_player_not_targetable_node.(
29
+ player_id: game_board.current_player_id.to_i)))
30
+ end
31
+
32
+ def self.id;4;end
33
+ end
34
+ end
35
+ end
36
+