Source file src/cmd/cgo/internal/testlife/testdata/main.go

     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  
     9  package main
    10  
    11  import (
    12  	"flag"
    13  	"fmt"
    14  
    15  	"cgolife"
    16  )
    17  
    18  const MAXDIM = 100
    19  
    20  var dim = flag.Int("dim", 16, "board dimensions")
    21  var gen = flag.Int("gen", 10, "generations")
    22  
    23  func 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  

View as plain text