-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighscore-random.go
49 lines (48 loc) · 924 Bytes
/
highscore-random.go
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
package main
/* Highscore example from Midtgaard-Nielson-Nielson:SAS16 implemented with const */
func main() {
ask := make(chan int);
hsc := make(chan int);
report := make(chan int);
myscore := make(chan int);
go func() { // server process
var highscore int;
var new int;
var cid int;
highscore = 0;
for {
select {
case cid = <- ask:
hsc <- highscore;
print(cid);
print(highscore)
case new = <- report:
if highscore < new { highscore = new } else {}
}
}
}()
go func () { // process for chosing arbitrary score (either 0 or max+2) via myscore channel
var max int;
max = 0;
for {
select {
case myscore <- 0:
case myscore <- max+2:
max = max + 2
}
}
}()
var id int; // client process
var best int;
var new int;
id = 0;
for {
ask <- id;
best = <- hsc;
new = <- myscore;
if best < new {
best = new;
report <- best
} else {}
}
}