<commit_before>// @flow
import {GameStage} from '../../game-stage'
import {computeScores} from './compute-scores'
import {toEndedState} from './converter'
import {bidWinGenerator} from './bid-win-generator'
import {toFront} from '../../utils'

import type {GameState, WaitingBidState, WaitingWinState} from './types'
import type {WIN_ACTION} from '../../actions/current-game'

/**
 * Handler for WIN action
 */
export function winHandler(state: WaitingBidState | WaitingWinState, action: WIN_ACTION): GameState {
  if (state.stage === GameStage.waitingBid) {
    return state
  }
  const win = action.win || state.win
  if (state.rounds === state.currentRound) {
    // Last round
    const newState: WaitingWinState = {
      ...state,
      scores: computeScores(state.bid, win, state.scores)
    }
    return toEndedState(newState, action.time)
  } else {
    const newState: WaitingBidState = {
      ...state,
      stage: GameStage.waitingBid,
      bid: bidWinGenerator(Object.keys(state.names)),
      currentRound: state.currentRound + 1,
      currentPlayerOrder: toFront(state.currentPlayerOrder, 1),
      scores: computeScores(state.bid, win, state.scores)
    }
    delete (newState: any).win
    return newState
  }
}<commit_msg>Fix flow error on reducer<commit_after>// @flow
import {GameStage} from '../../game-stage'
import {computeScores} from './compute-scores'
import {toEndedState} from './converter'
import {bidWinGenerator} from './bid-win-generator'
import {toFront} from '../../utils'

import type {GameState, WaitingBidState, WaitingWinState} from './types'
import type {WIN_ACTION} from '../../actions/current-game'

/**
 * Handler for WIN action
 */
export function winHandler(state: WaitingBidState | WaitingWinState, action: WIN_ACTION): GameState {
  if (state.stage === GameStage.waitingBid) {
    return state
  }
  const win = action.win || state.win
  if (state.rounds === state.currentRound) {
    // Last round
    const newState = toEndedState(state, action.time)
    return {
      ...newState,
      scores: computeScores(state.bid, win, state.scores)
    }
  } else {
    const newState: WaitingBidState = {
      ...state,
      stage: GameStage.waitingBid,
      bid: bidWinGenerator(Object.keys(state.names)),
      currentRound: state.currentRound + 1,
      currentPlayerOrder: toFront(state.currentPlayerOrder, 1),
      scores: computeScores(state.bid, win, state.scores)
    }
    delete (newState: any).win
    return newState
  }
}
{'fraction_non_alphanumeric': 0.13572291582762788, 'fraction_numerical': 0.0016109544905356424, 'mean_word_length': 3.419928825622776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1546138', 'n_tokens_mistral': 783, 'n_tokens_neox': 767, 'n_words': 193}