Sha256: 3f9431a15d6079a17bad4e7aab843f87e58ea5f52b6fb28dcaa2b63e88f2ff5b
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
# frozen string_literal: true require 'dry-initializer' require 'dry-struct' require 'spy_alley_application/types/game_board' module SpyAlleyApplication module Models class GameBoard < Dry::Struct class SpyEliminatorOptions include Dry::Initializer.define -> do option :next_game_state, type: ::Types::Callable, reader: :private end def call(game_board:) player = game_board.players.find{|p| p.seat.eql?(game_board.game_state.seat)} targetable_seats = game_board.players .select(&:in_spy_alley?) .reject{|p| p.equal?(player)} .map(&:seat) .sort .freeze if targetable_seats.empty? return next_game_state.(game_board: game_board) end game_state = { name: 'spy_eliminator', seat: game_board.game_state.seat, targetable_seats: targetable_seats, parent: game_board.game_state } SpyAlleyApplication::Types::GameBoard.call( game_board.to_h.tap{|g| g[:game_state] = game_state}) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems