love_letter_application 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +91 -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/love_letter_application.rb +7 -0
- data/lib/love_letter_application/action_creator.rb +16 -0
- data/lib/love_letter_application/actions/clown.rb +45 -0
- data/lib/love_letter_application/actions/general.rb +29 -0
- data/lib/love_letter_application/actions/knight.rb +31 -0
- data/lib/love_letter_application/actions/marquess.rb +28 -0
- data/lib/love_letter_application/actions/play_card.rb +33 -0
- data/lib/love_letter_application/actions/priestess.rb +36 -0
- data/lib/love_letter_application/actions/princess.rb +32 -0
- data/lib/love_letter_application/actions/soldier.rb +47 -0
- data/lib/love_letter_application/actions/wizard.rb +31 -0
- data/lib/love_letter_application/execute_action.rb +21 -0
- data/lib/love_letter_application/love_letter_imports.rb +641 -0
- data/lib/love_letter_application/models/card.rb +23 -0
- data/lib/love_letter_application/models/effects/discard_and_draw.rb +51 -0
- data/lib/love_letter_application/models/effects/eliminate_player.rb +43 -0
- data/lib/love_letter_application/models/effects/make_player_not_targetable.rb +44 -0
- data/lib/love_letter_application/models/effects/next_player_draw_card.rb +45 -0
- data/lib/love_letter_application/models/effects/play_card.rb +48 -0
- data/lib/love_letter_application/models/effects/round_complete.rb +29 -0
- data/lib/love_letter_application/models/effects/switch_hands.rb +50 -0
- data/lib/love_letter_application/models/game_board.rb +28 -0
- data/lib/love_letter_application/models/player.rb +36 -0
- data/lib/love_letter_application/results/eliminate_player.rb +43 -0
- data/lib/love_letter_application/results/nodes/card_played_node.rb +15 -0
- data/lib/love_letter_application/results/nodes/card_viewed_node.rb +21 -0
- data/lib/love_letter_application/results/nodes/discard_card_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/drawn_card_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/eliminated_player_node.rb +19 -0
- data/lib/love_letter_application/results/nodes/hands_switched_node.rb +22 -0
- data/lib/love_letter_application/results/nodes/knight_drawn_node.rb +15 -0
- data/lib/love_letter_application/results/nodes/knight_victory_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/log_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/next_player_node.rb +19 -0
- data/lib/love_letter_application/results/nodes/play_card_with_no_args_option_node.rb +19 -0
- data/lib/love_letter_application/results/nodes/play_card_with_player_id_and_card_id_option_node.rb +21 -0
- data/lib/love_letter_application/results/nodes/play_card_with_player_id_option_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/player_not_targetable_node.rb +14 -0
- data/lib/love_letter_application/results/nodes/player_victory_node.rb +20 -0
- data/lib/love_letter_application/results/nodes/players_and_scores_node.rb +44 -0
- data/lib/love_letter_application/results/nodes/princess_discarded_node.rb +19 -0
- data/lib/love_letter_application/results/nodes/result_game_board_node.rb +19 -0
- data/lib/love_letter_application/results/process_correct_guess.rb +22 -0
- data/lib/love_letter_application/results/process_draw_after_discard.rb +26 -0
- data/lib/love_letter_application/results/process_incorrect_guess.rb +20 -0
- data/lib/love_letter_application/results/process_knight_showdown.rb +50 -0
- data/lib/love_letter_application/results/process_next_player_turn.rb +57 -0
- data/lib/love_letter_application/results/process_next_turn_options.rb +53 -0
- data/lib/love_letter_application/results/process_princess_discarded.rb +23 -0
- data/lib/love_letter_application/results/process_resolve_wizard.rb +36 -0
- data/lib/love_letter_application/results/process_round_complete_by_depleted_deck.rb +50 -0
- data/lib/love_letter_application/results/process_round_complete_by_elimination.rb +26 -0
- data/lib/love_letter_application/results/process_switch_hands.rb +51 -0
- data/lib/love_letter_application/results/yield_to_block.rb +12 -0
- data/lib/love_letter_application/types/card.rb +20 -0
- data/lib/love_letter_application/types/game_board.rb +59 -0
- data/lib/love_letter_application/types/player.rb +25 -0
- data/lib/love_letter_application/validator/base.rb +19 -0
- data/lib/love_letter_application/validator/builder.rb +50 -0
- data/lib/love_letter_application/validator/get_legal_card_ids.rb +23 -0
- data/lib/love_letter_application/validator/get_legal_card_ids/marquess.rb +18 -0
- data/lib/love_letter_application/validator/play_card.rb +21 -0
- data/lib/love_letter_application/validator/play_card/builder.rb +23 -0
- data/lib/love_letter_application/validator/play_card/no_options.rb +19 -0
- data/lib/love_letter_application/validator/play_card/select_target_player.rb +30 -0
- data/lib/love_letter_application/validator/play_card/select_target_player/builder.rb +44 -0
- data/lib/love_letter_application/validator/play_card/soldier.rb +39 -0
- data/lib/love_letter_application/validator/play_card/soldier/builder.rb +49 -0
- data/lib/love_letter_application/validator/validate_card_id.rb +23 -0
- data/lib/love_letter_application/version.rb +3 -0
- data/love_letter_application.gemspec +43 -0
- metadata +278 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class CardPlayedNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
attribute :card_id, ::Types::Strict::Integer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class CardViewedNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
attribute :target_player_id, ::Types::Strict::Integer
|
11
|
+
attribute :card_id, ::Types::Strict::Integer
|
12
|
+
|
13
|
+
def accept(visitor, **args)
|
14
|
+
visitor = ::Types.Interface(:handle_card_viewed).call(visitor)
|
15
|
+
visitor.handle_card_viewed(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 LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class DiscardCardNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
attribute :card_id, ::Types::Strict::Integer
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = ::Types.Interface(:handle_discard_card).call(visitor)
|
14
|
+
visitor.handle_discard_card(self, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class DrawnCardNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
attribute :card_id, ::Types::Strict::Integer
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = ::Types.Interface(:handle_drawn_card).call(visitor)
|
14
|
+
visitor.handle_drawn_card(self, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class EliminatedPlayerNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
|
11
|
+
def accept(visitor, **args)
|
12
|
+
visitor = ::Types.Interface(:handle_eliminated_player).call(visitor)
|
13
|
+
visitor.handle_eliminated_player(self, args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class HandsSwitchedNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
attribute :target_player_id, ::Types::Strict::Integer
|
11
|
+
attribute :card_id_given, ::Types::Strict::Integer
|
12
|
+
attribute :card_id_taken, ::Types::Strict::Integer
|
13
|
+
|
14
|
+
def accept(visitor, **args)
|
15
|
+
visitor = ::Types.Interface(:handle_hands_switched).call(visitor)
|
16
|
+
visitor.handle_hands_switched(self, args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LoveLetterApplication
|
4
|
+
module Results
|
5
|
+
module Nodes
|
6
|
+
class KnightDrawnNode
|
7
|
+
def accept(visitor, **args)
|
8
|
+
visitor = ::Types.Interface(:handle_knight_drawn).call(visitor)
|
9
|
+
visitor.handle_knight_drawn(self, args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class KnightVictoryNode < Dry::Struct
|
9
|
+
attribute :winning_player_id, ::Types::Strict::Integer
|
10
|
+
attribute :losing_player_id, ::Types::Strict::Integer
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = ::Types.Interface(:handle_knight_victory).call(visitor)
|
14
|
+
visitor.handle_knight_victory(self, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class LogNode
|
9
|
+
extend Dry::Initializer
|
10
|
+
option :message, type: ::Types::Coercible::String
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = Types.Interface(:handle_log_message).call(visitor)
|
14
|
+
visitor.handle_log_message(self, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class NextPlayerNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
|
11
|
+
def accept(visitor, **args)
|
12
|
+
visitor = ::Types.Interface(:handle_next_player).call(visitor)
|
13
|
+
visitor.handle_next_player(self, args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PlayCardWithNoOptionsNode < Dry::Struct
|
9
|
+
attribute :card_id, ::Types::Strict::Integer
|
10
|
+
|
11
|
+
def accept(visitor, **args)
|
12
|
+
visitor = ::Types.Interface(:handle_play_card_with_no_options).call(visitor)
|
13
|
+
visitor.handle_play_card_with_no_options(self, args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/love_letter_application/results/nodes/play_card_with_player_id_and_card_id_option_node.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PlayCardWithPlayerIdAndCardIdOptionNode < Dry::Struct
|
9
|
+
attribute :card_id, ::Types::Strict::Integer
|
10
|
+
attribute :player_id_list, ::Types::ArrayOfStrictInteger
|
11
|
+
attribute :card_id_list, ::Types::ArrayOfStrictInteger
|
12
|
+
|
13
|
+
def accept(visitor, **args)
|
14
|
+
visitor = ::Types.Interface(:handle_play_card_with_player_id_option).call(visitor)
|
15
|
+
visitor.handle_play_card_with_player_id_option(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 LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PlayCardWithPlayerIdOptionNode < Dry::Struct
|
9
|
+
attribute :card_id, ::Types::Strict::Integer
|
10
|
+
attribute :player_id_list, ::Types::ArrayOfStrictInteger
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = ::Types.Interface(:handle_play_card_with_player_id_option).call(visitor)
|
14
|
+
visitor.handle_play_card_with_player_id_option(self, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PlayerVictoryNode
|
9
|
+
extend Dry::Initializer
|
10
|
+
option :player_id, type: ::Types::Array::of(::Types::Strict::Integer)
|
11
|
+
|
12
|
+
def accept(visitor, **args)
|
13
|
+
visitor = ::Types.Interface(:handle_player_victory).call(visitor)
|
14
|
+
visitor.handle_player_victory(self, **args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PlayersAndScoresNode
|
9
|
+
class PlayerScore < Dry::Struct
|
10
|
+
attribute :hand_card_value
|
11
|
+
attribute :played_cards_value
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(players_and_scores:)
|
15
|
+
@players_and_scores = players_and_scores
|
16
|
+
.sort
|
17
|
+
.reverse
|
18
|
+
.map{|k, v| [k, get_inner_node_for(v)]}
|
19
|
+
.freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def players_and_scores
|
23
|
+
@players_and_scores
|
24
|
+
end
|
25
|
+
|
26
|
+
def accept(visitor, **args)
|
27
|
+
visitor = ::Types.Interface(:handle_players_and_scores).call(visitor)
|
28
|
+
visitor.handle_players_and_scores(self, args)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def get_inner_node_for(score)
|
33
|
+
hand_card_value = score / 100
|
34
|
+
played_cards_value = score % 100
|
35
|
+
|
36
|
+
PlayerScore::new(
|
37
|
+
hand_card_value: hand_card_value,
|
38
|
+
played_cards_value: played_cards_value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class PrincessDiscardedNode < Dry::Struct
|
9
|
+
attribute :player_id, ::Types::Strict::Integer
|
10
|
+
|
11
|
+
def accept(visitor, **args)
|
12
|
+
visitor = ::Types.Interface(:handle_princess_discarded).call(visitor)
|
13
|
+
visitor.handle_princess_discarded(self, args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
module Nodes
|
8
|
+
class ResultGameBoardNode < Dry::Struct
|
9
|
+
attribute :game_board, LoveLetterApplication::Types::GameBoard
|
10
|
+
|
11
|
+
def accept(visitor, **args)
|
12
|
+
visitor = ::Types.Interface(:handle_result_game_board).call(visitor)
|
13
|
+
visitor.handle_result_game_board(self, args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
class ProcessCorrectGuess
|
8
|
+
include Dry::Initializer.define -> do
|
9
|
+
option :log_correct_guess_node, type: ::Types.Interface(:accept), reader: :private
|
10
|
+
option :eliminate_player, type: ::Types::Callable, reader: :private
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(target_player_id:, game_board:, change_orders:)
|
14
|
+
eliminate_player.(
|
15
|
+
target_player_id: target_player_id,
|
16
|
+
game_board: game_board,
|
17
|
+
change_orders: change_orders.push(log_correct_guess_node))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
|
5
|
+
module LoveLetterApplication
|
6
|
+
module Results
|
7
|
+
class ProcessDrawAfterDiscard
|
8
|
+
include Dry::Initializer.define -> do
|
9
|
+
option :get_drawn_card_node, type: ::Types::Callable
|
10
|
+
option :discard_and_draw, ::Types::Callable
|
11
|
+
option :process_next_player_turn, ::Types::Callable
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(target_player_id:, game_board:, change_orders:)
|
15
|
+
drawn_card_id = game_board.draw_pile.first&.id&.to_i || set_aside_card.id.to_i
|
16
|
+
game_board = discard_and_draw.(game_board: game_board, player_id: target_player_id)
|
17
|
+
process_next_player_turn.(
|
18
|
+
game_board: game_board,
|
19
|
+
change_orders: change_orders.push(get_drawn_card_node.(
|
20
|
+
player_id: target_player_id,
|
21
|
+
card_id: drawn_card_id)))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|