make players into a struct so they can have GUI names
This commit is contained in:
parent
0584652a18
commit
8a98223d67
17
main.rkt
17
main.rkt
|
@ -21,6 +21,12 @@
|
|||
; scores is a list of numbers for the score of each player.
|
||||
(struct GameState (grid player scores) #:transparent)
|
||||
|
||||
; represents a player. func is a function with the signature:
|
||||
; Grid Number -> Line
|
||||
; where the grid is the current board state, the Number is if the player is player 1 or 2, and it returns the move it will play that turn.
|
||||
; name is the player's name.
|
||||
(struct player (name func))
|
||||
|
||||
; width and height of the playing grid.
|
||||
(define GRID-WIDTH 6)
|
||||
(define GRID-HEIGHT 6)
|
||||
|
@ -122,9 +128,12 @@
|
|||
; where the grid is the current board state, the Number is if the player is player 1 or 2, and it returns the move it will play that turn.
|
||||
|
||||
; a Player that plays random moves
|
||||
(define (random-player g n)
|
||||
(let ([m (car (random-sample (valid-moves g) 1))])
|
||||
(line (line-from m) (line-to m) n)))
|
||||
(define random-player
|
||||
(player
|
||||
"Random"
|
||||
(lambda (g n)
|
||||
(let ([m (car (random-sample (valid-moves g) 1))])
|
||||
(line (line-from m) (line-to m) n)))))
|
||||
|
||||
; Grid Line -> Grid
|
||||
; adds line to grid, if it is a valid move. Otherwise skips the move.
|
||||
|
@ -167,7 +176,7 @@
|
|||
(cond
|
||||
[(= (length (grid-lines g)) (length (grid-lines FULL-GRID))) s] ; end of the game
|
||||
[else
|
||||
(let* ([move ((list-ref players p) g p)]
|
||||
(let* ([move ((player-func (list-ref players p)) g p)]
|
||||
[new-grid (append-move g move)]
|
||||
[boxes (completes-boxes g move)]
|
||||
[box (not (= 0 boxes))]
|
||||
|
|
Loading…
Reference in New Issue