Пример #1
0
func (x *Imp) Rand() {
	//
	x.surname.Copy(NN[rand.Natural(N)])
	n := rand.Natural(N)
	x.firstName.Copy(VN[n])
	x.fm.Set(n < N/2)
	x.bd.Randomize()
}
Пример #2
0
func changeRand(c *Colour) {
	//
	const (
		N  = 32
		N2 = N / 2
	)
	n := byte(rand.Natural(N))
	if n < N2 {
		if c.R >= n {
			c.R -= n
		} else {
			c.R = 0
		}
	} else { // n >= N2
		n -= N2
		if c.R+n <= m1 {
			c.R += n
		} else {
			c.R = light
		}
	}
	n = byte(rand.Natural(N))
	if n < N2 {
		if c.G >= n {
			c.G -= n
		} else {
			c.G = 0
		}
	} else {
		n -= N2
		if c.G+n <= m1 {
			c.G += n
		} else {
			c.G = light
		}
	}
	n = byte(rand.Natural(N))
	if n < N2 {
		if c.B >= n {
			c.B -= n
		} else {
			c.B = 0
		}
	} else {
		n -= N2
		if c.B+n <= m1 {
			c.B += n
		} else {
			c.B = light
		}
	}
}
Пример #3
0
func (x *Imp) Permute() {
	//
	switch x.size {
	case 1:
		return
	case 2:
		if rand.Natural(rand.Natural(1000))%2 == 1 {
			x.p[0], x.p[1] = x.p[1], x.p[0]
		}
	default:
		for i := uint(0); i < 3*x.size+rand.Natural(x.size); i++ {
			j, k := rand.Natural(x.size), rand.Natural(x.size)
			if j != k {
				x.p[j], x.p[k] = x.p[k], x.p[j]
			}
		}
	}
}
Пример #4
0
func (x *Imp) Generate() {
	//
	b := make([]byte, x.length)
	b[0] = upper[rand.Natural(uint(len(upper)))]
	for i := uint(1); i < x.length; i++ {
		b[i] = lower[rand.Natural(uint(len(lower)))]
	}
	x.content = string(b)
	z.ToHellWithUTF8(&x.content)
	/*
	     n:= 3 + rand.Natural (x.length - 2)
	     if n >= x.length {
	       n = x.length - 1
	     }
	     b:= rand.Natural (2) % 2 == 1
	     s:= x.length
	     for i:= 0; i < int(n); i++ {
	       if (i % 2 == 1) == b {
	         B[i] = randomkonsonant ()
	         if B[i] == 's' && i + 2 < int(n) {
	           s = uint(i)
	         }
	       } else {
	         B[i] = randomvokal ()
	       }
	       if i == 0 {
	   //      B[i] = CAP (B[i])
	       }
	     }
	     if s < x.length {
	       B[s + 1] = 'c'
	       B[s + 2] = 'h'
	     }
	     for i:= n; i <= x.length; i++ {
	   //    B[i] = 0C
	     }
	*/
}
Пример #5
0
func (D *Imp) Randomize() {
	//
	const n = uint16(14976) // Code of 1.1.1921
	D.Decode(Encode(n + uint16(rand.Natural(uint(todayCode+uint16(1)-n)))))
}
Пример #6
0
func (x *Imp) Eulerian() bool {
	//
	if !x.TotallyConnected() {
		return false // TODO Fleury's algorithm
	}
	p := x.postactual
	a := x.actual
	x.postactual = x.nodeAnchor
	x.actual = x.nodeAnchor
	e := uint(0)
	n := x.nodeAnchor.nextN
	for n != x.nodeAnchor {
		// Prüfung auf Existenz von Eulerkreisen (genau dann, falls Graph
		// ungerichtet:
		//   wenn jede Ecke eine gerade Nachbarzahl hat,
		// gerichtet:
		//   wenn an jeder Ecke die Anzahl der forwarden edge mit der der ankommenden übereinstimmt)
		// oder von Eulerwegen (genau dann, falls Graph
		// ungerichtet:
		//   wenn es genau zwei Ecken mit ungerader Nachbarzahl gibt,
		// gerichtet:
		//   wenn genau eine Ecke eine abgehende Kanten mehr als ankommende
		//   und genau eine Ecke eine ankommende Kante mehr als abgehende hat)
		z := uint(0)
		z1 := uint(0)
		nb := n.nbPtr.nextNb
		for nb != n.nbPtr {
			if nb.forward {
				z++
			} else {
				z1++
			}
			nb = nb.nextNb
		}
		if x.directed {
			if z == z1+1 {
				if x.postactual == x.nodeAnchor {
					x.postactual = n
					e++
				} else {
					x.postactual = p
					x.actual = a
					return false
				}
			} else if z1 == z+1 {
				if x.actual == x.nodeAnchor {
					x.actual = n
					e++
				} else {
					x.postactual = p
					x.actual = a
					return false
				}
			}
		} else { // ! x.directed
			if z%2 == 1 {
				if x.postactual == x.nodeAnchor {
					x.postactual = n
				} else if x.actual == x.nodeAnchor {
					x.actual = n
				} else {
					x.postactual = p
					x.actual = a
					return false
				}
				e++
			}
		}
		n = n.nextN
	}
	switch e {
	case 0: // Euler cycle with random starting node
		x.postactual = x.nodeAnchor.nextN
		n := rand.Natural(x.nNodes)
		for n > 0 {
			x.postactual = x.postactual.nextN
			n--
		}
		x.actual = x.postactual
	case 1:
		x.postactual = p
		x.actual = a
		return false
	case 2: // Euler way from postactual to actual node

	default:
		ker.Stop(pack, 100+e)
	}
	x.clearSubgraph()
	x.eulerPath = nil
	x.postactual.inSubgraph = true
	n = x.postactual
	n.inSubgraph = true
	//  for j:= 0; j <= 9; j** { for a:= false TO true { write (E.content, a); ker.Msleep (100) } }
	// attempt, to find an Euler way/cycle "by good luck":
	var nb *neighbour
	for {
		nb = undurchlaufenerNachbar(n)
		if nb == nil {
			ker.Stop(pack, 11)
		}
		// write3 (N.edgePtr.attrib, E.content, N.to.content, true)
		//  for j:= 0; j <= 9; j++ { for a:= false TO true { write (N.to.content, a); ker.Msleep (100) } } };
		nb.edgePtr.inSubgraph = true
		n = nb.to
		n.inSubgraph = true
		x.eulerPath = append(x.eulerPath, nb)
		if n == x.actual {
			break
		}
	}
	// errh.Error ("erster Wegabschnitt gefunden", 0);
	// as long there are undurchlaufene edges,
	// den bisherigen Teil des Eulerwegs auf Ecken durchsuchen,
	// von denen undurchlaufene Kanten abgehen,
	// und von ihnen aus weitere Kreise finden und
	// in den bisher gefundenen Teil des Eulerwegs einfügen:
	for {
		nb, ok := existsnb(x.eulerPath, undurchlaufen)
		if !ok {
			break
		}
		// for j:= 0; j <= 9; j++ { for a:= false; a <= true; a++ { // nonsense
		//   x.write3 (nb.edgePtr.attrib, nb.edgePtr.nbPtr0.from.content, nb.edgePtr.nbPtr1.from.content, a); ker.Msleep (100) } }
		n = nb.from
		n1 := n
		for {
			nb = undurchlaufenerNachbar(n)
			if nb == nil {
				ker.Stop(pack, 12)
			}
			// write3 (N.edgePtr.attrib, E.content, N.to.content, true)
			// for j:= 0 TO 9 { for a:= false TO true { write (N.to.content, a); ker.Msleep (100) } }
			nb.edgePtr.inSubgraph = true
			n = nb.to
			n.inSubgraph = true
			x.eulerPath = append(x.eulerPath, nb)
			if n == n1 {
				break
			} // zusätzlicher Kreis gefunden
			// errh.Error ("weiterer Teil eines Eulerwegs gefunden", 0)
		}
	}
	if x.demo[Euler] {
		x.write(x.postactual.content, true)
		wait()
		for i := uint(0); i < uint(len(x.eulerPath)); i++ {
			nb = x.eulerPath[i]
			x.write3(nb.edgePtr.attrib, nb.edgePtr.nbPtr0.from.content, nb.edgePtr.nbPtr1.from.content, true)
			if nb.edgePtr.nbPtr0 == nb {
				x.write(nb.edgePtr.nbPtr1.from.content, true)
			} else {
				x.write(nb.edgePtr.nbPtr0.from.content, true)
			}
			if i+1 < uint(len(x.eulerPath)) {
				wait()
			}
		}
	}
	return true
}
Пример #7
0
func colourRand() Colour {
	//
	var c Colour
	c.R, c.G, c.B = byte(rand.Natural(m)), byte(rand.Natural(m)), byte(rand.Natural(m))
	return c
}
Пример #8
0
func wait(t uint) {
	//
	ker.Sleep(1 + (rand.Natural(3)))
}
Пример #9
0
func main() {
	//
	/*
	   h:= [...]string {
	     "     <              Rücktaste <--                      ",
	     " <<    >>           Pfeiltaste auf-/abwärts            ",
	     "|<<    >>|          Pos1-Taste/Endetaste               ",
	     "    2 .. 12         F2 .. F12-Taste                    ",
	     "   13 .. 24         Umschalt- + F1 .. F12-Taste        ",
	     "               oder Mausklick auf entsprechende Zeile  ",
	     " Zufallsstück       Rollen-Taste                       ",
	     "                                                       ",
	     "  <  1 sek >        Bildtaste auf-/abwärts             ",
	     " << 10 sek >>       Umschalt- + Bildtaste auf-/abwärts ",
	     "<<<  1 min >>>      Alt- + Bildtaste auf-/abwärts      ",
	     "                                                       ",
	     "  Lautstärke        Pfeiltaste Links/Rechts und        ",
	     "                    Umschalt- + Pfeiltaste Links/Rechts",
	     "               oder mit Maus auf entsprechende Anzeige ",
	     "   Balance          Alt- + Pfeiltaste Links/Rechts     ",
	     "               oder mit Maus auf entsprechende Anzeige ",
	     "                                                       ",
	     " Pause/weiter       Pause-Taste                        ",
	     " Ende/CD raus       Abbruch-/Entfernungstaste          " }
	   Help:= make ([]string, len(h))
	   for i:= 0; i < len(h); i++ { str.Set (&Help[i], h[i]) }
	*/
	errh.WriteHeadline(program, version, author, col.LightWhite, col.DarkBlue)
	f := model.Soundfile()
	if f == nil {
		model.Term1()
		errh.Error("kein Zugriff auf CD", 0)
		ker.Terminate()
		return
	}
	view.WriteMask()
	var (
		help, stop bool
	)
	quit := make(chan bool)
	go func() {
		for !stop {
			ker.Sleep(1)
			if !help {
				view.Write()
			}
		}
		quit <- true
	}()
	model.PlayTrack(0)
loop:
	for {
		c, t := kbd.Command()
		help = false
		scr.MouseCursor(true)
		switch c {
		case kbd.Esc:
			if t == 0 {
				model.Term()
			} else {
				model.Term1()
			}
			stop = true
			break loop
		case kbd.Enter:
			if t == 0 {
				model.PlayTrack1(true)
			} else {
				model.PlayTrack(model.NTracks() - 1)
			}
		case kbd.Back:
			switch t {
			case 0:
				model.PlayTrack0()
			case 1:
				model.PlayTrack1(false)
			default:
				model.PlayTrack(0)
			}
		case kbd.Left, kbd.Right:
			switch t {
			case 0:
				model.Ctrl1(model.All, c == kbd.Right)
			case 1:
				_ = uint(model.Volume(model.All))
				for j := 0; j < 8; j++ {
					model.Ctrl1(model.All, c == kbd.Right)
				}
			default:
				model.Ctrl1(model.Balance, c == kbd.Left)
			}
		case kbd.Pos1:
			model.PlayTrack(0)
		case kbd.End:
			model.PlayTrack(model.NTracks() - 1)
		case kbd.Up, kbd.Down:
			switch t {
			case 0, 1:
				model.PlayTrack1(c == kbd.Down)
			case 2:
				model.PosTime1(c == kbd.Down, 1)
			case 3:
				model.PosTime1(c == kbd.Down, 10)
			default:
				model.PosTime1(c == kbd.Down, 60)
			}
		case kbd.Tab:
			model.PlayTrack1(t == 0)
		case kbd.Del:
			model.Term1()
			return
		case kbd.Help, kbd.LookFor, kbd.Act, kbd.Cfg,
			kbd.Mark, kbd.Demark, kbd.Deposit, kbd.Paste,
			kbd.Black, kbd.Red, kbd.Green, kbd.Blue:
			if t == 0 {
				if c == kbd.Help {
					//          help = true
					//          errh.WriteHelp (Help)
				} else {
					model.PlayTrack(uint8(c - kbd.Help))
				}
			} else {
				model.PlayTrack(10 + uint8(c-kbd.Help))
			}
		case kbd.Roll:
			model.PlayTrack(uint8(rand.Natural(uint(model.NTracks()))))
		case kbd.Pause:
			model.Switch()
		case kbd.Here, kbd.Pull:
			var ctrl model.Controller
			if track, b := view.TrackUnderMouse(); b {
				if c == kbd.Here {
					model.PlayTrack(track)
				}
			} else if ls, c := view.ControlUnderMouse(&ctrl); c {
				model.Ctrl(ctrl, uint8(ls))
			} else if b, sek, c := view.TimeUnderMouse(); c {
				model.PosTime(b, sek)
			}
		case kbd.Navigate:
			/*
			   var mov, rot space.Gridcoordinate
			   &mov, &rot = mouse3d.Read()
			   model.Ctrl1 (model.All, mov [space.Top] < 0)
			   model.Ctrl1 (model.All, rot [space.Right] < 0)
			   model.Ctrl1 (model.Balance, rot [space.Front] < 0)
			*/
		}
	}
	<-quit
	_ = f.Close()
	ker.Terminate()
}
Пример #10
0
func randomkonsonant() byte {
	//
	return Konsonanten[rand.Natural(20)]
}
Пример #11
0
func randomvokal() byte {
	//
	return Vokale[rand.Natural(6)]
}