]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/life/main.go
all: make copyright headers consistent with one space after period
[gostls13.git] / misc / cgo / life / main.go
1 // cmpout
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         "."
15         "flag"
16         "fmt"
17 )
18
19 const MAXDIM = 100
20
21 var dim = flag.Int("dim", 16, "board dimensions")
22 var gen = flag.Int("gen", 10, "generations")
23
24 func main() {
25         flag.Parse()
26
27         var a [MAXDIM * MAXDIM]int32
28         for i := 2; i < *dim; i += 8 {
29                 for j := 2; j < *dim-3; j += 8 {
30                         for y := 0; y < 3; y++ {
31                                 a[i**dim+j+y] = 1
32                         }
33                 }
34         }
35
36         life.Run(*gen, *dim, *dim, a[:])
37
38         for i := 0; i < *dim; i++ {
39                 for j := 0; j < *dim; j++ {
40                         if a[i**dim+j] == 0 {
41                                 fmt.Print(" ")
42                         } else {
43                                 fmt.Print("X")
44                         }
45                 }
46                 fmt.Print("\n")
47         }
48 }