Craig Maloney

[Blog] Day 21/100: Slow progress

Craig Maloney at

(http://feedproxy.google.com/~r/CraigMaloney/~3/u15wYpPfznc/)

More progress on the Shut the Box program in Racket.

Still need to figure out how to get everything together, but at least it's starting to make some sense.

#lang racket

#| Init Block |#

(define tiles '())
(define die1 0)
(define die2 0)
(define turn-number 1)

(define (start-game)
(set! tiles '(1 2 3 4 5 6 7 8 9)))


(define (dice)
(+ 1 (random 6)))

(define (dice-roll)
(set! die1 (dice))
(set! die2 (dice)))

(define (sum-of-dice)
(+ die1 die2))

(define (sum-of-tiles tilelist)
(apply + tilelist))

(define (check-roll dice-sum tile-sum)
(= dice-sum tile-sum))

(define (shut-tiles tilelist)
(for ([i tilelist])
    (if (index-of tiles i)
        (set! tiles (remove i tiles))
        (print "Tile already shut"))))

(define (player-turn tilelist)
(if (check-roll (sum-of-dice) (sum-of-tiles tilelist))
    (shut-tiles tilelist)
    (print "Roll does not equal shut tiles. Try again.")))

(start-game)
(dice-roll)

(define (next-turn)
(set! turn-number (+ 1 turn-number))
(dice-roll)
(show-turn))

(define (show-turn)
(printf "Turn: ")
(println turn-number)
(println tiles)
(printf "Dice roll ~v ~v = ~v" die1 die2 (sum-of-dice) ))

clacke@libranet.de ❌, serpiente_negra, Ben Sturmfels likes this.

You're really making progress on your challenge. Ive enjoyed reading your updates. I just today found time to organize my thoughts around this. At this rate, I might not start until July 1st. Come to think of it, that might not be bad idea. :)

Charles Stanhope at 2017-06-22T04:06:10Z

Craig Maloney likes this.

Thank you. I just realized one silly thing though which is that if you select two tiles and the second is already shut it will still remove the first one.

Bugs. Gotta love 'em. :)

Craig Maloney at 2017-06-22T11:34:32Z

Charles Stanhope likes this.