<commit_before>player = require './player'
express = require 'express'

analyzeHand = require './analyzeHand'

module.exports = ->
  app = express()

  app.use express.json()
  app.use express.urlencoded()

  app.all '/', (req, res, next) ->
    action = req.body?.action ? req.query?.action
    gameState = req.body?.game_state ? req.query?.game_state
    console.log '/', action, gameState
    if typeof gameState is 'string'
      try
        gameState = JSON.parse gameState
      catch err
        # return next err
        console.log err
        return res.send null, 0

    if action == 'bet_request'
      player.betRequest gameState, (err, bet) ->
        if err
          console.log err
          return res.send null, 0
        hand = analyzeHand gameState
        console.log [
          gameState
          hand.hole
          "betting #{bet}"
        ].join '\n'
        res.send 200, bet
    else if action == 'showdown'
      player.showdown gameState, (err) ->
        res.send 200, 'OK'
    else if action == 'version'<commit_msg>prettier logs<commit_after>player = require './player'
express = require 'express'

analyzeHand = require './analyzeHand'

module.exports = ->
  app = express()

  app.use express.json()
  app.use express.urlencoded()

  app.all '/', (req, res, next) ->
    action = req.body?.action ? req.query?.action
    gameState = req.body?.game_state ? req.query?.game_state
    console.log '/', action, gameState
    if typeof gameState is 'string'
      try
        gameState = JSON.parse gameState
      catch err
        # return next err
        console.log err
        return res.send null, 0

    if action == 'bet_request'
      player.betRequest gameState, (err, bet) ->
        if err
          console.log err
          return res.send null, 0
        hand = analyzeHand gameState
        logs = [
          gameState
          hand.hole
          "betting #{bet}"
        ].join '\n'
        console.log JSON.stringify logs, null, 2
        res.send 200, bet
    else if action == 'showdown'
      player.showdown gameState, (err) ->
        res.send 200, 'OK'
    else if action == 'version'
{'fraction_non_alphanumeric': 0.11380597014925373, 'fraction_numerical': 0.00792910447761194, 'mean_word_length': 2.033946251768034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7084656', 'n_tokens_mistral': 651, 'n_tokens_neox': 626, 'n_words': 187}