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

View File

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

View File

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

View File

@ -154,7 +154,8 @@ class StackTabber(Tabber):
token = self.get_token(y, i) token = self.get_token(y, i)
rtoken = self.get_next_right_token(y, i) rtoken = self.get_next_right_token(y, i)
if rtoken is None: 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: else:
level = rtoken.x level = rtoken.x
self._append(token.string, level) self._append(token.string, level)