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