]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/life/testdata/main.go
cc2ca7c74237458cc0eae4f4bb3022aebef8caa9
[gostls13.git] / misc / cgo / life / testdata / main.go
1 // run -tags=use_go_run
2
3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // +build test_run
8
9 // Run the game of life in C using Go for parallelization.
10
11 package main
12
13 import (
14         "flag"
15         "fmt"
16
17         "cgolife"
18 )
19
20 const MAXDIM = 100
21
22 var dim = flag.Int("dim", 16, "board dimensions")
23 var gen = flag.Int("gen", 10, "generations")
24
25 func main() {
26         flag.Parse()
27
28         var a [MAXDIM * MAXDIM]int32
29         for i := 2; i < *dim; i += 8 {
30                 for j := 2; j < *dim-3; j += 8 {
31                         for y := 0; y < 3; y++ {
32                                 a[i**dim+j+y] = 1
33                         }
34                 }
35         }
36
37         cgolife.Run(*gen, *dim, *dim, a[:])
38
39         for i := 0; i < *dim; i++ {
40                 for j := 0; j < *dim; j++ {
41                         if a[i**dim+j] == 0 {
42                                 fmt.Print(" ")
43                         } else {
44                                 fmt.Print("X")
45                         }
46                 }
47                 fmt.Print("\n")
48         }
49 }