AI improvements.

master
Thomas Hintz 5 years ago
parent 802a0efcbb
commit 9160fdc92a

@ -1629,12 +1629,20 @@
(define (round-down-1000 val) (define (round-down-1000 val)
(- val (remainder val 1000))) (- val (remainder val 1000)))
(define (pct-complete net-worth game)
(/ (min net-worth (game-setting 'audit-threshold game))
(game-setting 'audit-threshold game)))
(define (ai-buy player game) (define (ai-buy player game)
(print "ai attempting to buy") (print "ai attempting to buy")
(let ((room (+ (- (game-setting 'max-debt game) (player-debt player)) (round-down-1000 (player-cash player)))) (let* ((net-worth (player-net-worth player))
(crops (map (lambda (card) (pct-complete (pct-complete net-worth game))
(string->symbol (alist-ref 'crop card))) (room (if (< pct-complete 0.7)
(player-otbs player)))) 1000000 ;; basically infinite
(+ (- (game-setting 'max-debt game) (player-debt player)) (round-down-1000 (player-cash player)))))
(crops (map (lambda (card)
(string->symbol (alist-ref 'crop card)))
(player-otbs player))))
(print (conc "room: " room)) (print (conc "room: " room))
(print (conc "crops: " crops)) (print (conc "crops: " crops))
(let ((to-buy (let ((to-buy
@ -1650,7 +1658,8 @@
(= (player-asset 'harvester player) 0)) (= (player-asset 'harvester player) 0))
'(harvester 1 10000)) '(harvester 1 10000))
((and (member 'tractor crops) (>= room 10000) ((and (member 'tractor crops) (>= room 10000)
(= (player-asset 'tractor player) 0)) (= (player-asset 'tractor player) 0)
(<= (player-asset 'cows player) 40))
'(tractor 1 10000)) '(tractor 1 10000))
((and (member 'ridge4 crops) (>= room 50000) ((and (member 'ridge4 crops) (>= room 50000)
(not (find (lambda (p) (not (find (lambda (p)
@ -1676,11 +1685,15 @@
(print "to buy: " to-buy) (print "to buy: " to-buy)
(if to-buy (if to-buy
(begin (begin
(print (conc "buying crop: " (first to-buy))) (print (conc "buying crop: " (first to-buy)))
(when (< (round-down-1000 (player-cash player)) (third to-buy))
(process-message player game "loan" `((amount . ,(/ (- (third to-buy)
(round-down-1000 (player-cash player)))
1000)))))
(if (eq? (buy-crop (normalize-crop (first to-buy)) (if (eq? (buy-crop (normalize-crop (first to-buy))
(first to-buy) (first to-buy)
(second to-buy) (second to-buy)
(min (third to-buy) (round-down-1000 (player-cash player))) (third to-buy)
player player
game) game)
#t) #t)
@ -1741,7 +1754,9 @@
(process-message player game "loan" `((amount . ,(/ (+ (abs (player-cash player)) (process-message player game "loan" `((amount . ,(/ (+ (abs (player-cash player))
(remainder (abs (player-cash player)) 1000)) (remainder (abs (player-cash player)) 1000))
1000))))) 1000)))))
(when (>= (player-cash player) 1000) (when (and (>= (player-cash player) 1000)
(or (<= (player-debt player) 40000)
(>= (player-cash player) 75000)))
(print "repaying loan") (print "repaying loan")
(process-message player game "loan" `((amount . ,(* (/ (- (player-cash player) (process-message player game "loan" `((amount . ,(* (/ (- (player-cash player)
(remainder (player-cash player) 1000)) (remainder (player-cash player) 1000))

Loading…
Cancel
Save