feeder

package
v0.0.0-...-3319774 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

1個1個のダイスの供給の仕方を定義するパッケージ。 このパッケージに含まれる構造体を利用することで、ダイスの値をランダムにするか、指定したものにするかを切り替えることができる。

ダイスの値をランダムにする場合は、MT19937を使用する。 ダイスの値を指定したものにする場合は、Queueを使用する。

Example (MT19937WithSeedFromTime)

ダイスをランダムに供給:現在時刻をシードとする場合の例。

// ダイスの値をランダムにする
dieFeeder := NewMT19937WithSeedFromTime()
// 6面ダイスを1個振る
d, _ := dieFeeder.Next(6)

return d
Output:

Example (MT19937WithSpecifiedSeed)

ダイスをランダムに供給:シードを指定する場合の例。

// ダイスの値をランダムにする
dieFeeder := NewMT19937(1)
// 6面ダイスを1個振る
d, _ := dieFeeder.Next(6)

return d
Output:

Example (Queue)

供給するダイスを指定する場合の例。

// 供給するダイスを指定する
dieFeeder := NewQueue([]dice.Die{{1, 6}, {3, 6}, {5, 6}})

// 6面ダイスを1個振る
d, err := dieFeeder.Next(6)
if err != nil {
	return
}

fmt.Println(d.String())
Output:

<Die 1/6>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DieFeeder

type DieFeeder interface {
	// Next はダイスを1つ供給する。
	//
	// sides: ダイスの面数
	Next(sides int) (dice.Die, error)

	// CanSpecifyDie は、供給されるダイスを指定できるかを返す。
	CanSpecifyDie() bool
}

DieFeeder は、ダイス供給機のインターフェース。

type MT19937

type MT19937 struct {
	// contains filtered or unexported fields
}

ランダムにダイスを取り出すダイス供給機の構造体。 Ruby版BCDiceと同様にメルセンヌ・ツイスタを使用する。

func NewMT19937

func NewMT19937(seed int64) *MT19937

NewMT19937 は、シードを指定したMT19937ダイス供給機を返す。

func NewMT19937WithSeedFromTime

func NewMT19937WithSeedFromTime() *MT19937

NewMT19937WithSeedFromTime は、現在の時刻をシードとしたMT19937ダイス供給機を返す。

func (*MT19937) CanSpecifyDie

func (f *MT19937) CanSpecifyDie() bool

CanSpecifyDie は、供給されるダイスを指定できるかを返す。 MT19937ダイス供給機ではfalseを返す。

func (*MT19937) Next

func (f *MT19937) Next(sides int) (dice.Die, error)

Next はランダムな値のダイスを1つ供給する。

sides: ダイスの面の数

func (*MT19937) Seed

func (f *MT19937) Seed() int64

Seed は設定されているシードを返す。

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

指定したダイスを取り出せる、キュー型ダイス供給機の構造体。

func NewEmptyQueue

func NewEmptyQueue() *Queue

NewEmptyQueue は、空のキュー型ダイス供給機を返す。

func NewQueue

func NewQueue(d []dice.Die) *Queue

NewQueue はキュー型ダイス供給機を返す。

d: 供給するダイスのスライス

func (*Queue) Append

func (f *Queue) Append(dice []dice.Die)

Append は複数のダイスをキューの末尾に追加する。

func (*Queue) CanSpecifyDie

func (f *Queue) CanSpecifyDie() bool

CanSpecifyDie は、供給されるダイスを指定できるかを返す。 キュー型ダイス供給機ではtrueを返す。

func (*Queue) Clear

func (f *Queue) Clear()

Clear はキューを空にする。

func (*Queue) Dice

func (f *Queue) Dice() []dice.Die

Dice は、現在のキューの内容をコピーして返す。

func (*Queue) IsEmpty

func (f *Queue) IsEmpty() bool

IsEmpty は、ダイスのキューが空ならばtrueを、空でなければfalseを返す。

func (*Queue) Next

func (f *Queue) Next(_ int) (dice.Die, error)

Next はキューからダイスを1つ取り出して供給する。 キューが空だった場合はエラーを返す。

func (*Queue) Push

func (f *Queue) Push(d dice.Die)

Push はダイスをキューに追加する。

func (*Queue) Remaining

func (f *Queue) Remaining() int

Remaining は残りのダイスの数を返す。

func (*Queue) Set

func (f *Queue) Set(d []dice.Die)

Set は指定されたダイスをキューに配置する。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL