main.go 827 B

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