-
Notifications
You must be signed in to change notification settings - Fork 1
/
strategy-intf.rkt
71 lines (59 loc) · 3.29 KB
/
strategy-intf.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
#lang racket
;; ---------------------------------------------------------------------------------------------------
;; an interface specification for an Acquire game strategy, assuming a
;; player that delegates all turn information at once and expects a
;; complete decision in return
(require "basics.rkt" "board.rkt" "protocols.rkt" "Lib/auxiliaries.rkt" "Lib/contract.rkt")
(interface strategy&
[ordered-s
;; places the tile closest to A1 (in terms of tile<=?) that can be placed
;; and that buys as many shares as possible in alphabetical order
(make-strategy/c tile<?)]
[random-s
;; places a random tile from the player's available tiles, buys a random number of random shares
strategy/c]
[largest-alpha
;; 1. choose to place the LARGEST tile according to to tile<=? in the possession of the player
;; that can be placed on the current board, and
;; 2. choose to buy as many shares as possible in ALPHABETICAL order
(make-strategy/c tile>?)]
[smallest-anti
;; 1. choose to place the SMALLEST tile according to to tile<=? in the possession of the player
;; that can be placed on the current board, and
;; 2. choose to buy as many shares as possible in ANTI-ALPHABETICAL order, but sort those on return
(make-strategy/c tile<?)])
(provide strategy/c)
;; ---------------------------------------------------------------------------------------------------
;; auxiliary notions
;; [Tile Tile -> Tile] -> Contract
;; a contract for strategies
;; compare placement to all tiles t in player-s-tiles that pass (cmp t tile)
(define (make-strategy/c cmp)
;; given: the current board, the player's tiles, the player's cash,
;; the remaining shares for sale, and the remaining hotel labels
(->i ((turn (instanceof/c turn-player/c)))
;; compute: the tile to be placed (if the player can place one)
;; the hotel involved in the placement
;; the shares to be bought and their price
(values (tile (turn) (and/c (maybe/c tile?) (good-placement turn) (unique-tile turn cmp)))
(hotel (tile turn) (and/c (maybe/c hotel?) (good-hotel-for-placement turn tile)))
(buy-order (tile hotel turn) (and/c (listof hotel?) (good-shares turn tile hotel))))))
;; this is the minimal requirement for a strategy
(define strategy/c (make-strategy/c (lambda (s t) #f)))
;; ---------------------------------------------------------------------------------------------------
;; AUXILIARIES:
;; no tile closer to A1 than tile (in the sense of cmp) can be placed
;; examples:
;; (check-true ((others-not-placable (board) (list (ctile A 1)) tile<?) (ctile A 1)))
;; (check-false ((others-not-placable (board) (list (ctile A 1)) tile<?) (ctile A 2)))
;; (check-true ((others-not-placable (board) (list (ctile A 1)) tile>?) (ctile A 1)))
;; (check-false ((others-not-placable (board) (list (ctile A 3)) tile>?) (ctile A 2)))
(define/contract (unique-tile turn cmp)
(-> (instanceof/c turn-player/c) (-> tile? tile? any) (-> (maybe/c tile?) any))
(lambda (tile)
(define board (get-field board turn))
(define player-s-tiles (get-field tiles turn))
(or (boolean? tile)
(and tile
(for/and ((t (filter (lambda (t) (cmp t tile)) player-s-tiles)))
(eq? (what-kind-of-spot board t) IMPOSSIBLE))))))