branch : pmacs2
This commit is contained in:
moculus 2007-08-16 14:21:37 +00:00
parent 417ddb8bac
commit 4c84db1504
4 changed files with 55 additions and 51 deletions

View File

@ -1,71 +1,72 @@
; a helper function which prints each argument seperated by a space
(define output
(lambda (. things)
(cond
((null? things) (display #\newline))
(else
(display (car things))
(display #\space)
(apply output (cdr things))))))
(lambda (. things)
(cond
((null? things) (display #\newline))
(else
(display (car things))
(display #\space)
(apply output (cdr things))))))
; a helper function which shows arguments before calling them
(define explicit-apply
(lambda (f . args)
(let ((result (apply f args)))
(output f args result)
result)))
(lambda (f . args)
(let ((result (apply f args)))
(output f args result)
result)))
; determine whether or not a given attack roll will hit
(define is-hit?
(lambda (roll attack ac)
(or (= roll 20) (and (< 1 roll) (>= (+ roll attack) ac)))))
(lambda (roll attack ac)
(or (= roll 20) (and (< 1 roll) (>= (+ roll attack) ac)))))
; determine whether or not a given attack roll will crit
(define is-crit?
(lambda (roll attack ac threat)
(or (= roll 20) (and (is-hit? roll attack ac) (>= roll threat)))))
(lambda (roll attack ac threat)
(or (= roll 20) (and (is-hit? roll attack ac) (>= roll threat)))))
; determine the expected damage of a particular attack roll
(define roll-dmg
(lambda (roll attack ac dmg threat mult)
(cond
((is-crit? roll attack ac threat) (* dmg mult))
((is-hit? roll attack ac) dmg)
(else 0))))
(lambda (roll attack ac dmg threat mult)
(cond
((is-crit? roll attack ac threat) (* dmg mult))
((is-hit? roll attack ac) dmg)
(else 0))))
; determine the expected damage across all attack rolls
(define expected-dmg
(lambda (. args)
(define adder
(lambda (total roll)
(if (> roll 20)
total
(adder (+ total (apply roll-dmg roll args)) (+ roll 1)))))
(/ (adder 0 1) 20)))
(lambda (. args)
(define adder
(lambda (total roll)
(if (> roll 20)
total
(adder (+ total (apply roll-dmg roll args))
(+ roll 1)))))
(/ (adder 0 1) 20)))
; find the best power attack score (and expected damage) versus an AC
(define find-best-power
(lambda (power-max attack ac dmg threat mult)
(define checker
(lambda (power best-power best-dmg)
(if (> power power-max)
(list best-power best-dmg)
(let* ((a (- attack power))
(d (+ dmg power))
(ed (expected-dmg a ac d threat mult)))
(if (> ed best-dmg)
(checker (+ power 1) power ed)
(checker (+ power 1) best-power best-dmg))))))
(checker 0 0 0)))
(lambda (power-max attack ac dmg threat mult)
(define checker
(lambda (power best-power best-dmg)
(if (> power power-max)
(list best-power best-dmg)
(let* ((a (- attack power))
(d (+ dmg power))
(ed (expected-dmg a ac d threat mult)))
(if (> ed best-dmg)
(checker (+ power 1) power ed)
(checker (+ power 1) best-power best-dmg))))))
(checker 0 0 0)))
; iterate across a range of armor classes
(define iter
(let ((max-power 6)
(attack 6)
(dmg 5.5)
(threat 20)
(mult 3))
(lambda (ac max-ac)
(explicit-apply find-best-power max-power attack ac dmg threat mult)
(if (> ac max-ac) #f (iter (+ ac 1) max-ac)))))
(let ((max-power 6)
(attack 6)
(dmg 5.5)
(threat 20)
(mult 3))
(lambda (ac max-ac)
(explicit-apply find-best-power max-power attack ac dmg threat mult)
(if (> ac max-ac) #f (iter (+ ac 1) max-ac)))))
(iter 10 30)

View File

@ -24,20 +24,21 @@ class LispTabber(tab2.StackTabber):
if rtoken is not None and rtoken.string != '(':
rtoken = self.get_next_right_token(y, i + 1)
if rtoken is None:
level = self.get_curr_level() + 4
level = self.get_curr_level() + self.mode.tabwidth
else:
level = rtoken.x
self._append(token.string, level)
return currlvl
class Lisp(mode2.Fundamental):
tabwidth = 2
tabbercls = LispTabber
grammar = LispGrammar
opentokens = ('delimiter',)
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
colors = {
'comment': ('red', 'default'),
'string.start': ('green', 'default'),
'string.null': ('green', 'default'),

View File

@ -26,13 +26,14 @@ class SchemeGrammar(Grammar):
]
class Scheme(mode2.Fundamental):
tabwidth = 2
tabbercls = mode.lisp.LispTabber
grammar = SchemeGrammar
opentokens = ('delimiter',)
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
colors = {
'comment': ('red', 'default'),
'keyword': ('cyan', 'default'),

View File

@ -154,7 +154,8 @@ class StackTabber(Tabber):
token = self.get_token(y, i)
rtoken = self.get_next_right_token(y, i)
if rtoken is None:
level = self.get_curr_level() + 4
#level = self.get_curr_level() + 4
level = self.get_curr_level() + self.mode.tabwidth
else:
level = rtoken.x
self._append(token.string, level)