<commit_before>module TWG
  class Game

    attr_reader :participants
    attr_reader :state
    attr_reader :live_wolves
    attr_reader :live_norms
    attr_reader :votes
    attr_reader :game_wolves
    attr_reader :min_part
    attr_reader :iteration

    def initialize
      reset
    end

    def reset
      @state = :signup
      @iteration = 0
      @participants = {}
      @min_part = 6
      @wolf_ratio = (1.0/5.0)
      @game_wolves = []
      @live_wolves = 0
      @live_norms = 0
      @votes = {}
    end

    def start
      if @participants.length >= @min_part
        assign_roles
        start = Haps.new(:action => :channel, :code => :gamestart, :message => "Game started!")
        @state = :night
        @iteration = 1
        state_transition_in
        return start
      else
        @state = nil
        return Haps.new(:action => :channel, :code => :notenoughplayers, :message => "Not enough players to start game: #{@participants.length}/#{@min_part}")
      end
    end

    def register(nick)
      if @state == :signup
        unless @participants.keys.include?(nick)
          @participants.merge!({nick => :normal})
          return Haps.new(:action => :channel, :code => :confirmplayer, :message => "#{nick} registered successfully")
        else
          return Haps.new(:action => :channel, :code => :alreadyplayer, :message => "#{nick} already registered")
        end
      else
        return Haps.new(:action => :none, :code => :unregisterablestate, :message => "Can't register during #{@state}")
      end
    end

    def nickchange(oldnick, newnick)

      # replace player
      role = @participants.delete(oldnick)
      @participants.merge!({newnick => role})

      # Change special characters
      if @game_wolves.include?(oldnick)
        @game_wolves.delete(oldnick)
        @game_wolves << newnick
      end

      # Replace votes for and by the player
      tvotes = @votes.dup
      tvotes.each do |votee,voters|
        if votee == oldnick
          @voters[newnick] = voters
          @voters[oldnick] = nil
        end
        if voters.include?(oldnick)
          @voters[votee].delete(oldnick)
          @voters[votee] << newnick
        end
      end
      tvotes = nil

    end

    # Advances the game to the next state
    def next_state<commit_msg>Fix silly mistake in nickchange vote reassignment<commit_after>module TWG
  class Game

    attr_reader :participants
    attr_reader :state
    attr_reader :live_wolves
    attr_reader :live_norms
    attr_reader :votes
    attr_reader :game_wolves
    attr_reader :min_part
    attr_reader :iteration

    def initialize
      reset
    end

    def reset
      @state = :signup
      @iteration = 0
      @participants = {}
      @min_part = 6
      @wolf_ratio = (1.0/5.0)
      @game_wolves = []
      @live_wolves = 0
      @live_norms = 0
      @votes = {}
    end

    def start
      if @participants.length >= @min_part
        assign_roles
        start = Haps.new(:action => :channel, :code => :gamestart, :message => "Game started!")
        @state = :night
        @iteration = 1
        state_transition_in
        return start
      else
        @state = nil
        return Haps.new(:action => :channel, :code => :notenoughplayers, :message => "Not enough players to start game: #{@participants.length}/#{@min_part}")
      end
    end

    def register(nick)
      if @state == :signup
        unless @participants.keys.include?(nick)
          @participants.merge!({nick => :normal})
          return Haps.new(:action => :channel, :code => :confirmplayer, :message => "#{nick} registered successfully")
        else
          return Haps.new(:action => :channel, :code => :alreadyplayer, :message => "#{nick} already registered")
        end
      else
        return Haps.new(:action => :none, :code => :unregisterablestate, :message => "Can't register during #{@state}")
      end
    end

    def nickchange(oldnick, newnick)

      # replace player
      role = @participants.delete(oldnick)
      @participants.merge!({newnick => role})

      # Change special characters
      if @game_wolves.include?(oldnick)
        @game_wolves.delete(oldnick)
        @game_wolves << newnick
      end

      # Replace votes for and by the player
      tvotes = @votes.dup
      tvotes.each do |votee,voters|
        if votee == oldnick
          @votes[newnick] = voters
          @votes[oldnick] = nil
        end
        if voters.include?(oldnick)
          @votes[votee].delete(oldnick)
          @votes[votee] << newnick
        end
      end
      tvotes = nil

    end

    # Advances the game to the next state
    def next_state
{'fraction_non_alphanumeric': 0.10925449871465295, 'fraction_numerical': 0.0038560411311053984, 'mean_word_length': 2.2401110340041637, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7081012', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1430, 'n_words': 365}