Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
1
Indexable
Never
function convertHandHistory(handHistory) {
  const lines = handHistory.split("\n");
  const tableInfo = lines[0].split(" ");
  const tableName = tableInfo[2];
  const gameType = tableInfo[5];
  const sb = tableInfo[7];
  const bb = tableInfo[8];
  const date = lines[0].substring(lines[0].indexOf(":")+2);

  let result = `PokerStars Hand #${tableName}: ${gameType} (${sb}/${bb}) - ${date}\n`;

  for(let i = 2; i < lines.length; i++) {
    const line = lines[i];

    if(line.startsWith("Seat ")) {
      const seatInfo = line.split(" ");
      const seatNum = seatInfo[1].substring(0,1);
      const playerName = seatInfo[2];
      const stackSize = seatInfo[3].substring(1);
      result += `Seat ${seatNum}: ${playerName} (${stackSize} in chips)\n`;
    } else if(line.startsWith("** Hole cards")) {
      result += `Dealt to ${lines[i+1].split(" ")[2]} ${lines[i+1].split(" ")[3]}\n`;
    } else if(line.startsWith("** Flop") || line.startsWith("** Turn") || line.startsWith("** River")) {
      result += `${line.substring(3)}\n`;
    } else if(line.startsWith("***")) {
      result += `${line.substring(3)}\n`;
    }
  }

  const summaryLine = lines[lines.length-2];
  const summaryParts = summaryLine.split(" ");
  const totalPot = summaryParts[2];
  const rake = summaryParts[4];

  result += `Total pot ${totalPot} | Rake ${rake}\n`;

  for(let i = 2; i < lines.length; i++) {
    const line = lines[i];

    if(line.startsWith("Seat ")) {
      const seatInfo = line.split(" ");
      const seatNum = seatInfo[1].substring(0,1);
      const playerName = seatInfo[2];
      const action = lines[i+1].split(" ")[1];
      const amount = lines[i+1].split(" ")[2];
      const netResult = parseFloat(lines[lines.length-1].split(" ")[11+parseInt(seatNum)]);
      result += `Seat ${seatNum}: ${playerName} ${action} ${amount} | net result: ${netResult.toFixed(2)}\n`;
    }
  }

  return result;
}