This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
/
ds-armor.rkt
83 lines (72 loc) · 2.78 KB
/
ds-armor.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#lang racket/base
(require racket/list
racket/match
2htdp/batch-io)
;; Data is available at http://darksoulswiki.wikispaces.com/Armor
(define positions '("Torso" "Legs" "Arms" "Head"))
(define option-row->option
(match-lambda
[(list name durability weight phys str sls prc mag fir lit poise bleed poison curse have)
(define vals (map string->number (list weight phys poise)))
(and (andmap number? vals)
#;(string=? "1" have)
#;(not (regexp-match (regexp-quote "+") name))
(list* name vals))]))
(define options
(for/list ([p (in-list positions)])
(define pth (format "/home/jay/Downloads/Dark Souls Armor - ~a.csv" p))
(define choices
(cons (list (format "Bare ~a" p) 0 0 0)
(filter-map option-row->option (read-csv-file pth))))
(for/fold ([ht (hash)])
([c (in-list choices)])
(match-define (list* name weight phys _) c)
(hash-update ht weight
(λ (old)
(match-define (list* _ _ old-phys _) old)
(if (> old-phys phys)
old
c))
c))))
(printf "option structure: ~v\n" (map hash-count options))
(printf "~v options\n" (apply * (map hash-count options)))
(define (branch-and-bound target-weight current-value options)
(match options
[(list)
(values current-value empty)]
[(list* option options)
(for/fold ([best-so-far -inf.0]
[best-so-far-choice #f])
([(weight choice) (in-hash option)]
#:when (<= weight target-weight))
(match-define (list* _ weight phys _) choice)
(define new-weight (- target-weight weight))
(define new-value (+ current-value phys))
(define-values (this-value sub-choice) (branch-and-bound new-weight new-value options))
(cond
[(> this-value best-so-far)
(values this-value (list* choice sub-choice))]
[else
(values best-so-far best-so-far-choice)]))]))
(define target-weight/darkwood+iaito+crest
(- (/ 80 2)
#;6 5
3 #;3.5))
(define target-weight/havels-ring+darkwood+hammer+eagle
(- (/ 120 2)
6 6))
(define target-weight
target-weight/havels-ring+darkwood+hammer+eagle)
(printf "\n")
(printf "Target weight: ~a\n" target-weight)
(define-values (_ choices)
(branch-and-bound target-weight/havels-ring+darkwood+hammer+eagle 0 options))
(printf "Best choices:\n")
(match-define (and totals (list weight-used phys poise))
(for/fold ([tots (list 0 0 0)])
([c (in-list choices)])
(match-define (list* name vals) c)
(printf " ~a ~a\n" vals name)
(map + tots vals)))
(printf "Total ~a\n" totals)
(printf "Weight left: ~a\n" (- target-weight weight-used))