-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-row.scm
96 lines (80 loc) · 3.11 KB
/
make-row.scm
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(require (lib "racket/vector.ss"))
(define (make-row% row)
(new
(class object%
(init row-nr)
;Creates vector with positions that represents columns
(field (columns (make-vector 12)))
(super-new)
;This is the rows number counting from the top
(define current-row row-nr)
;Creates boards on the gameboard
(vector-set! columns 0 1)
(vector-set! columns 11 1)
;Stones------------------------------------------------------
;Gets info
;Sees if there is a stone on a column
(define/public (stone-in-col? col)
(if (eq? (vector-ref columns (- col 1)) 0)
#f
#t))
;Gets a stone from a given column in the row
(define/public (get-stone col)
(vector-ref columns (- col 1)))
;Gets all columns from the current-row
(define/public (all-columns)
columns)
;Sets info--------
;Adds a stone to a given column in the row
(define/public (add-stone! col stone)
(vector-set! columns (- col 1) stone))
;Removes a stone from a specific position
(define/public (remove-stone! stone col)
(if (eq? stone (send this get-stone col))
(vector-set! columns (- col 1) 0)))
;Fills row with only the number 1
(define/public (fill-row)
(define (fill-help col)
(cond
((= col 0) (vector-set! columns col 1))
(else (vector-set! columns col 1) (fill-help (- col 1)))))
(fill-help 11))
;Checks if this row is full
(define/public (full-row?)
(if (= (vector-count (lambda (n) (eq? n 0)) columns) 0)
#t
#f))
;Requests new stones from the row above
(define/public (request-new-stones)
(cond
((= current-row 1)
(set! columns (make-vector 12))
(vector-set! columns 0 1)
(vector-set! columns 11 1)
(send *gameboard* find-full-row))
(else (send (send *gameboard* get-row (- current-row 1)) send-stones-down))))
;Takes a new vector from the row above
(define/public (set-new-stones! vector)
(set! columns vector))
;Sends stones to the row below
(define/public (send-stones-down)
(cond
((= current-row 1) (send (send *gameboard* get-row (+ current-row 1)) set-new-stones! columns)
(set! columns (make-vector 12))
(vector-set! columns 0 1)
(vector-set! columns 11 1)
(send *gameboard* find-full-row))
(else (send (send *gameboard* get-row (+ current-row 1)) set-new-stones! columns)
(send (send *gameboard* get-row (- current-row 1)) send-stones-down))
))
;Sees if there is ANY stone in the row
(define/public (any-stone?)
(if (< (vector-count (lambda (n) (eq? n 0)) columns) 10)
#t
#f))
;Row-nr------------------------------------------------------
;Gets the current rows number
(define/public (get-row-nr)
current-row)
)
(row-nr row)))