User Tools

Site Tools


user:mtaft4:projects:scripts:experience

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

user:mtaft4:projects:scripts:experience [2010/12/18 01:31] – created mtaft4user:mtaft4:projects:scripts:experience [2010/12/18 01:32] (current) mtaft4
Line 1: Line 1:
 +=====D&D Experience Calculations=====
  
 +This script uses bc to calculate experience in Dungeons and Dragons Edition 3.5 based on the Challenge Rating of the encounter and the average Character Level of the party.
 +<code bash>
 +#!/bin/bash
 +# xpscript - D&D script for calculating experience from enounters based on CR of
 +# the encounter and level of the party
 +
 +if [ $# == 0 ]
 + then
 + echo "Usage: $0 CR LV" | sed "s/\/.*\///g"
 + exit
 +fi
 +cr=$1
 +lv=$2
 +test1=`echo "($cr-$lv)%2" | bc`
 +if [ "$test1" == "0" ] #If CR-LV is even or 0
 + then
 + xp=`echo "scale=5; $lv*300*sqrt(2)^($cr-$lv)" | bc | sed -e "s/\(\.[0-9]\).*/\1/g"`
 + xp=`echo "($xp+0.1)/1" | bc`
 + echo "$xp"
 + else # CR-LV is odd
 + cr1=`echo "$cr+1" | bc`
 + cr2=`echo "$cr-1" | bc`
 + xp2=`echo "scale=5; $lv*300*sqrt(2)^($cr1-$lv)" | bc | sed -e "s/\(\.[0-9]\).*/\1/g"`
 + xp1=`echo "($xp1+0.1)/1" | bc`
 + xp2=`echo "scale=5; $lv*300*sqrt(2)^($cr2-$lv)" | bc | sed -e "s/\(\.[0-9]\).*/\1/g"`
 + xp2=`echo "($xp2+0.1)/1" | bc`
 + xp=`echo "($xp1+$xp2)/2" | bc`
 + echo $xp
 +fi
 +exit
 +</code>
 +This script uses a lot of command expansions to do the calculations and variable declarations before finally using bc to calculate the results of the formula for the encounter experience. Not really an important script but goes to further show that bash is a powerful utility that can be used to do many things.