Sha256: a97e9107bf09b5f3e753624920c4c2abe5d9ea6f3e06fdd97c9f8023f463509b

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen string_literal: true

require 'dry-struct'
require 'spy_alley_application/types/game_board'

module SpyAlleyApplication
  module Models
    class GameBoard < Dry::Struct
      class MoveCardUsed
        def call(game_board:, move_card_used:)
          player = game_board.current_player
          unaffected_players = game_board.players.reject{|p| p.equal?(player)}
          move_card_pile = game_board.move_card_pile
          # remove one copyof the move_card_used from the player's move card hand
          player = player.to_h.tap do |p|
            p[:move_cards].delete_at(p[:move_cards].index(move_card_used))
            p[:move_cards] = p[:move_cards].sort
          end
          # and place at the bottom (end) of the move card pile
          move_card_pile = (move_card_pile + [move_card_used]).freeze
          players = unaffected_players.push(player).sort{|p, q| p[:seat] <=> q[:seat]}

          SpyAlleyApplication::Types::GameBoard.call(
            game_board.to_h.tap{|g| g[:players] = players; g[:move_card_pile] = move_card_pile})
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spy_alley_application-0.3.2 lib/spy_alley_application/models/game_board/move_card_used.rb
spy_alley_application-0.3.1 lib/spy_alley_application/models/game_board/move_card_used.rb
spy_alley_application-0.3.0 lib/spy_alley_application/models/game_board/move_card_used.rb