summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hintz <t@thintz.com>2020-04-29 07:33:08 -0700
committerThomas Hintz <t@thintz.com>2020-04-29 07:33:08 -0700
commit9160fdc92a7581cb9de48c80f99feac9701dddd1 (patch)
tree1da473c9c4625ad6c2a23d62740f31dc85ff044f
parent802a0efcbb399e16bec6d791d33d6e81e1b072c0 (diff)
downloadfarm-9160fdc92a7581cb9de48c80f99feac9701dddd1.tar.gz
AI improvements.
-rw-r--r--src/server/farm.scm31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/server/farm.scm b/src/server/farm.scm
index 103632e..62a8299 100644
--- a/src/server/farm.scm
+++ b/src/server/farm.scm
@@ -1629,12 +1629,20 @@
(define (round-down-1000 val)
(- 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)
(print "ai attempting to buy")
- (let ((room (+ (- (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))))
+ (let* ((net-worth (player-net-worth player))
+ (pct-complete (pct-complete net-worth game))
+ (room (if (< pct-complete 0.7)
+ 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 "crops: " crops))
(let ((to-buy
@@ -1650,7 +1658,8 @@
(= (player-asset 'harvester player) 0))
'(harvester 1 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))
((and (member 'ridge4 crops) (>= room 50000)
(not (find (lambda (p)
@@ -1676,11 +1685,15 @@
(print "to buy: " to-buy)
(if to-buy
(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))
(first to-buy)
(second to-buy)
- (min (third to-buy) (round-down-1000 (player-cash player)))
+ (third to-buy)
player
game)
#t)
@@ -1741,7 +1754,9 @@
(process-message player game "loan" `((amount . ,(/ (+ (abs (player-cash player))
(remainder (abs (player-cash player)) 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")
(process-message player game "loan" `((amount . ,(* (/ (- (player-cash player)
(remainder (player-cash player) 1000))