kernel

package module
v0.0.0-...-239a5f2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileFromCode

func GetFileFromCode(code string) string

GetFileFromCode - 座標の符号の筋の部分を抜き出します

* `code` - 座標の符号。 Example: "A7" や "J13"

func GetFileFromX

func GetFileFromX(x int) string

GetFileFromX - GetXFromFile の逆関数

func GetRankFromCode

func GetRankFromCode(code string) string

GetRankFromCode - 座標の符号の段の部分を抜き出します

* `code` - 座標の符号。 Example: "A7" や "J13"

func GetRankFromY

func GetRankFromY(y int) string

GetRankFromY - GetYFromRank の逆関数

Parameters ---------- y : int

0 .. 98

Returns ------- rank : string

"1" .. "99"

func GetXFromFile

func GetXFromFile(file string) int

GetXFromFile - `A` ~ `Z` を 0 ~ 24 へ変換します。 国際囲碁連盟のルールに倣い、筋の符号に `I` は使いません

func GetYFromRank

func GetYFromRank(rank string) int

GetYFromRank - '1' ~ '99' を 0 ~ 98 へ変換します

Types

type Board

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

Board - 盤

func NewBoard

func NewBoard(gameRule GameRule, boardWidht int, boardHeight int) *Board

NewBoard - 新規作成

func (*Board) ForeachNeumannNeighborhood

func (b *Board) ForeachNeumannNeighborhood(here Point, setAdjacent func(Cell_4Directions, Point))

ForeachNeumannNeighborhood - [O13o__10o0] 隣接する4方向の定義

func (*Board) GetColorAt

func (b *Board) GetColorAt(i Point) Color

GetColorAt - 指定座標の石の色を取得

func (*Board) GetCoordinate

func (b *Board) GetCoordinate() *BoardCoordinate

GetCoordinate - 盤座標取得

func (*Board) GetGameRule

func (b *Board) GetGameRule() *GameRule

GetGameRule - ゲームルール取得

func (*Board) GetStoneAt

func (b *Board) GetStoneAt(i Point) Stone

GetStoneAt - 指定座標の石を取得

func (*Board) Init

func (b *Board) Init(width int, height int)

Init - 盤面初期化

func (*Board) IsMasonry

func (b *Board) IsMasonry(point Point) bool

IsMasonry - 石の上に石を置こうとしたか?

func (*Board) IsSpaceAt

func (b *Board) IsSpaceAt(point Point) bool

IsEmpty - 指定の交点は空点か?

func (*Board) SetGameRule

func (b *Board) SetGameRule(gameRule *GameRule)

SetGameRule - ゲームルール設定

func (*Board) SetStoneAt

func (b *Board) SetStoneAt(i Point, s Stone)

SetStoneAt - 指定座標の石を設定

type BoardCoordinate

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

BoardCoordinate - 盤座標

func (*BoardCoordinate) ForeachCellWithoutWall

func (bc *BoardCoordinate) ForeachCellWithoutWall(setPoint func(Point))

ForeachCellWithoutWall - 枠や改行を含めない各セルの番地

func (*BoardCoordinate) ForeachLikeText

func (bc *BoardCoordinate) ForeachLikeText(setPoint func(Point), doNewline func())

ForeachLikeText - 枠を含めた各セルの石

func (*BoardCoordinate) ForeachPayloadLocationOrderByYx

func (bc *BoardCoordinate) ForeachPayloadLocationOrderByYx(setLocation func(Point))

ForeachPayloadLocationOrderByYx - 枠や改行を含めない各セルの番地。筋、段の順

func (*BoardCoordinate) GetBoardArea

func (bc *BoardCoordinate) GetBoardArea() int

GetBoardArea - 枠無し盤の面積

func (*BoardCoordinate) GetEastOf

func (bc *BoardCoordinate) GetEastOf(point Point) Point

GetEastOf - 東

func (*BoardCoordinate) GetGtpMoveFromPoint

func (bc *BoardCoordinate) GetGtpMoveFromPoint(point Point) string

GetGtpMoveFromPoint - `GetPointFromGtpMove` の逆関数

func (*BoardCoordinate) GetHeight

func (bc *BoardCoordinate) GetHeight() int

GetHeight - 枠無し盤の縦幅

func (*BoardCoordinate) GetMemoryArea

func (bc *BoardCoordinate) GetMemoryArea() int

GetMemoryArea - 枠付き盤の面積

func (*BoardCoordinate) GetMemoryHeight

func (bc *BoardCoordinate) GetMemoryHeight() int

GetMemoryWidth - 枠付きの盤の垂直一辺の交点数

func (*BoardCoordinate) GetMemoryWidth

func (bc *BoardCoordinate) GetMemoryWidth() int

GetMemoryWidth - 枠付きの盤の水平一辺の交点数

func (*BoardCoordinate) GetNorthEastOf

func (bc *BoardCoordinate) GetNorthEastOf(point Point) Point

GetNorthEastOf - 北東

func (*BoardCoordinate) GetNorthOf

func (bc *BoardCoordinate) GetNorthOf(point Point) Point

GetNorthOf - 北

func (*BoardCoordinate) GetNorthWestOf

func (bc *BoardCoordinate) GetNorthWestOf(point Point) Point

GetNorthWestOf - 北西

func (*BoardCoordinate) GetPointFromGtpMove

func (bc *BoardCoordinate) GetPointFromGtpMove(gtp_move string) Point

GetPointFromGtpMove - "A7" や "J13" といった符号を Point へ変換します

* `gtp_move` - 座標の符号。 Example: "A7" や "J13"

func (*BoardCoordinate) GetPointFromXy

func (bc *BoardCoordinate) GetPointFromXy(x int, y int) Point

GetPointFromXy - x,y 形式の座標を、 point (配列のインデックス)へ変換します。 point は枠を含む盤上での座標です

Parameters ---------- x : int 枠を含む盤での筋番号。 Example: 19路盤なら0~20 y : int 枠を含む盤での段番号。 Example: 19路盤なら0~20

Returns ------- point : Point 配列インデックス

func (*BoardCoordinate) GetRelativePointOf

func (bc *BoardCoordinate) GetRelativePointOf(dir4 Cell_4Directions) Point

GetRelativePointOf - 4方向(東、北、西、南)の先の番地

func (*BoardCoordinate) GetSouthEastOf

func (bc *BoardCoordinate) GetSouthEastOf(point Point) Point

GetSouthEastOf - 南東

func (*BoardCoordinate) GetSouthOf

func (bc *BoardCoordinate) GetSouthOf(point Point) Point

GetSouthOf - 南

func (*BoardCoordinate) GetSouthWestOf

func (bc *BoardCoordinate) GetSouthWestOf(point Point) Point

GetSouthWestOf - 南西

func (*BoardCoordinate) GetWestOf

func (bc *BoardCoordinate) GetWestOf(point Point) Point

GetWestOf - 西

func (*BoardCoordinate) GetWidth

func (bc *BoardCoordinate) GetWidth() int

GetWidth - 枠無し盤の横幅

func (*BoardCoordinate) GetXyFromPoint

func (bc *BoardCoordinate) GetXyFromPoint(point Point) (int, int)

GetXyFromPoint - `GetPointFromXy` の逆関数

type Cell_4Directions

type Cell_4Directions int

Cell_4Directions - 東、北、西、南を指す配列のインデックスに対応

const (
	Cell_East Cell_4Directions = iota
	Cell_North
	Cell_West
	Cell_South
)

東、北、西、南を指す配列のインデックスに対応

type CheckBoard

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

CheckBoard - チェック盤

func NewDirtyCheckBoard

func NewDirtyCheckBoard() *CheckBoard

NewDirtyCheckBoard - 新規作成するが、初期化されていない

* このメソッドを呼び出した後に Init 関数を呼び出してほしい

func (*CheckBoard) ClearAllBitsAt

func (cb *CheckBoard) ClearAllBitsAt(point Point)

ClearAllBitsAt - フラグを消す

func (*CheckBoard) Contains

func (cb *CheckBoard) Contains(point Point, mark Mark) bool

Contains - 含む

func (*CheckBoard) Erase

func (cb *CheckBoard) Erase(point Point, mark Mark)

Erase - 消す

func (*CheckBoard) GetAllBitsAt

func (cb *CheckBoard) GetAllBitsAt(point Point) Mark

GetAllBitsAt - 指定した交点の目印を取得

func (*CheckBoard) Init

func (cb *CheckBoard) Init(newBoardCoordinate BoardCoordinate)

Init - 初期化

func (*CheckBoard) IsZeroAt

func (cb *CheckBoard) IsZeroAt(point Point) bool

IsZeroAt - 指定した交点に目印は付いていないか?

func (*CheckBoard) Overwrite

func (cb *CheckBoard) Overwrite(point Point, mark Mark)

Overwrite - 上書き

func (*CheckBoard) SetAllBitsAt

func (cb *CheckBoard) SetAllBitsAt(point Point, mark Mark)

SetAllBitsAt - 指定した交点に目印を設定

type Color

type Color uint
const (
	Color_None Color = iota
	Color_Black
	Color_White
	Color_Mixed
)

func (Color) GetAdded

func (c1 Color) GetAdded(c2 Color) Color

GetAdded - 色の加算

func (Color) GetOpponent

func (c Color) GetOpponent() Color

GetOpponent - 色の反転

func (Color) String

func (c Color) String() string

String - 文字列化

type GameRule

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

GameRule - 対局ルール

func NewGameRule

func NewGameRule(komi KomiFloat, maxPositionNumber PositionNumberInt) *GameRule

NewGameRule - 新規作成

func (*GameRule) GetKomi

func (gr *GameRule) GetKomi() KomiFloat

GetKomi - コミ取得

func (*GameRule) GetMaxPositionNumber

func (gr *GameRule) GetMaxPositionNumber() PositionNumberInt

GetMaxPositionNumber - 上限手数

type Kernel

type Kernel struct {
	// Position - 局面
	Position *Position

	// Record - [O12o__11o_3o0] 棋譜
	Record Record
	// contains filtered or unexported fields
}

Kernel - カーネル

func NewDirtyKernel

func NewDirtyKernel(gameRule GameRule, boardWidht int, boardHeight int,

	maxPositionNumber PositionNumberInt, playFirst Stone) *Kernel

NewDirtyKernel - カーネルの新規作成 - 一部のメンバーは、初期化されていないので、別途初期化処理が要る

func (*Kernel) DoPlay

func (k *Kernel) DoPlay(command string, logg *Logger)

DoPlay - 打つ

* `command` - Example: `play black A19` ........................---- ----- --- ........................0 1 2

func (*Kernel) DoSetBoard

func (k *Kernel) DoSetBoard(command string, logg *Logger)

DoSetBoard - 盤面を設定する

コマンドラインの複数行入力は難しいので、ファイルから取ることにする * `command` - Example: `board_set file data/board1.txt` ........................--------- ---- --------------- ........................0 1 2

func (*Kernel) DoUndoPlay

func (k *Kernel) DoUndoPlay(command string, logg *Logger)

DoUndoPlay - 石を打ったのを戻す

* `command` - Example: `undo` ........................---- ........................0

func (*Kernel) Execute

func (k *Kernel) Execute(command string, logg *Logger) bool

Execute - 実行

Returns ------- isHandled : bool 正常終了またはエラーなら真、無視したら偽

func (*Kernel) FindAllRens

func (k *Kernel) FindAllRens()

FindAllRens - [O23o_2o1o0] 盤上の全ての連を見つけます * 見つけた連は、連データベースへ入れます

func (*Kernel) GetLiberty

func (k *Kernel) GetLiberty(arbitraryPoint Point) (*Ren, bool)

GetLiberty - 呼吸点の数え上げ。連の数え上げ。 `GetOneRen` とでもいう名前の方がふさわしいが、慣習に合わせた関数名にした

Parameters ---------- * `arbitraryPoint` - 連に含まれる任意の一点

Returns ------- - *Ren is ren or nil - bool is found

func (*Kernel) GetRenToCapture

func (k *Kernel) GetRenToCapture(placePlay Point) (bool, [4]*Ren)

GetRenToCapture - 現在、着手後の盤面とする。打ち上げられる石の連を返却

Returns ------- isExists : bool renToRemove : [4]*Ren 隣接する東、北、西、南にある石を含む連

func (*Kernel) LoadRenDb

func (k *Kernel) LoadRenDb(path string, onError func(error) bool) bool

LoadRenDb - [O12o__11o__10o5o__10o_10o0] 連データベースの外部ファイル読取

func (*Kernel) Play

func (k *Kernel) Play(stoneA Stone, placePlay Point, logg *Logger,

	onMasonry func() bool,

	onOpponentEye func() bool,

	onForbiddenMyEye func() bool,

	onKo func() bool) bool

Play - 石を打つ

Parameters ========== stoneA : Stone - placePlay : Point -

Returns ======= isOk : bool - 石を置けたら真、置けなかったら偽

func (*Kernel) RefreshRenToInternal

func (k *Kernel) RefreshRenToInternal(r *Ren) bool

RefreshRenToInternal - TODO 外部ファイルから入力された内容を内部状態に適用します

func (*Kernel) RemoveRen

func (k *Kernel) RemoveRen(ren *Ren)

RemoveRen - 石の連を打ち上げます

func (*Kernel) UndoPlay

func (k *Kernel) UndoPlay() bool

UndoPlay - 石を打ったのを戻す

Returns ------- isOk : bool

石を置けたら真、置けなかったら偽

type KomiFloat

type KomiFloat float64

KomiFloat - コミ。 6.5 といった数字を入れるだけ。実行速度優先で 64bitに

type LibertySearchAlgorithm

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

LibertySearchAlgorithm - 呼吸点探索アルゴリズム

func NewLibertySearchAlgorithm

func NewLibertySearchAlgorithm(board *Board, checkBoard *CheckBoard) *LibertySearchAlgorithm

NewLibertySearchAlgorithm - 新規作成

type Logger

type Logger struct {
	// C is sugared logger for Console
	C *zap.SugaredLogger
	// J is sugared logger as JSON
	J *zap.SugaredLogger
}

func NewSugaredLoggerForGame

func NewSugaredLoggerForGame(plainTextLogFile *os.File, jsonLogFile *os.File) *Logger

type Mark

type Mark uint8

Mark - 目印

const (
	Mark_BitAllZeros Mark = 0b00000000
	Mark_BitStone    Mark = 0b00000001
	Mark_BitLiberty  Mark = 0b00000010
)

type Point

type Point int

Point - 交点の座標。いわゆる配列のインデックス。枠を含む盤の左上を 0 とします

const Cell_Illegal Point = -1

IllegalZ - 石が置けない番地の目印として使用。例:UCT計算中に石が置けなかった

const Cell_Pass Point = 0

Cell_Pass - パス

type Position

type Position struct {
	// Board - 盤
	Board *Board

	// [O22o2o3o0]
	// CheckBoard - 呼吸点の探索時に使います
	CheckBoard *CheckBoard

	// CanNotPutOnMyEye - [O22o4o1o0] 自分の眼に石を置くことはできません
	CanNotPutOnMyEye bool
}

func NewDirtyPosition

func NewDirtyPosition(gameRule GameRule, boardWidht int, boardHeight int) *Position

NewDirtyKernel - カーネルの新規作成 - 一部のメンバーは、初期化されていないので、別途初期化処理が要る

type PositionNumberInt

type PositionNumberInt int

PositionNumberInt - 何手目

type Record

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

Record - 棋譜

func NewRecord

func NewRecord(maxPositionNumber PositionNumberInt, memoryBoardArea int, playFirst Stone) *Record

NewRecord - 新規作成

* maxPositionNumber - 手数上限。配列サイズ決定のための判断材料 * memoryBoardArea - メモリー盤サイズ。配列サイズ決定のための判断材料

func (*Record) ForeachItem

func (r *Record) ForeachItem(setItem func(PositionNumberInt, *RecordItem))

ForeachItem - 各要素

func (*Record) GetMaxPosNth

func (r *Record) GetMaxPosNth() int

GetMaxPosNth - 手数(序数)の最大値

func (*Record) GetMaxPosNthFigure

func (r *Record) GetMaxPosNthFigure() int

GetMaxPosNthFigure - 手数(序数)の最大値の桁数

func (*Record) GetPositionNumber

func (r *Record) GetPositionNumber() PositionNumberInt

GetPositionNumber - 何手目。基数

func (*Record) IsKo

func (r *Record) IsKo(placePlay Point) bool

IsKo - コウか?

func (*Record) Push

func (r *Record) Push(placePlay Point,

	ko Point)

Push - 末尾に追加

func (*Record) RemoveTail

func (r *Record) RemoveTail(placePlay Point)

RemoveTail - 末尾を削除

type RecordItem

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

RecordItem - 棋譜の一手分

func NewRecordItem

func NewRecordItem() *RecordItem

NewRecordItem - 棋譜の一手分

func (*RecordItem) Clear

func (ri *RecordItem) Clear()

Clear - 空っぽにします

type Ren

type Ren struct {
	// Sto - (外部ファイル向け)石
	Sto string `json:"stone"`
	// Loc - (外部ファイル向け)石の盤上の座標符号の空白区切りのリスト
	Loc string `json:"locate"`
	// LibLoc - (外部ファイル向け)呼吸点の盤上の座標符号の空白区切りのリスト
	LibLoc string `json:"liberty"`
	// contains filtered or unexported fields
}

Ren - 連,れん

func NewRen

func NewRen(stone Stone) *Ren

NewRen - 連を新規作成

Parameters ---------- color - 色

func (*Ren) AddLocation

func (r *Ren) AddLocation(location Point)

AddLocation - 場所の追加

func (*Ren) Dump

func (r *Ren) Dump() string

Dump - ダンプ

Example: `22 23 24 25`

func (*Ren) ForeachLocation

func (r *Ren) ForeachLocation(setLocation func(int, Point))

ForeachLocation - 場所毎に

func (*Ren) GetAdjacentColor

func (r *Ren) GetAdjacentColor() Color

GetAdjacentColor - 隣接する石の色

func (*Ren) GetArea

func (r *Ren) GetArea() int

GetArea - 面積。アゲハマの数

func (*Ren) GetLibertyArea

func (r *Ren) GetLibertyArea() int

GetLibertyArea - 呼吸点の面積

func (*Ren) GetMinimumLocation

func (r *Ren) GetMinimumLocation() Point

GetMinimumLocation - 最小の場所。Idとして利用することを想定

func (*Ren) GetStone

func (r *Ren) GetStone() Stone

GetStone - 石

func (*Ren) RefreshToExternalFile

func (r *Ren) RefreshToExternalFile(convertLocation func(Point) string)

RefreshToExternalFile - 外部ファイルに出力されてもいいように内部状態を整形します

type RenDb

type RenDb struct {
	// Header - ヘッダー
	Header RenDbDocHeader `json:"header"`

	// 要素
	Rens map[RenId]*Ren `json:"rens"`
}

RenDb - 連データベース

func NewRenDb

func NewRenDb(boardWidth int, boardHeight int) *RenDb

NewRenDb - 連データベースを新規作成

func (*RenDb) Dump

func (db *RenDb) Dump() string

Dump - ダンプ

func (*RenDb) GetRen

func (db *RenDb) GetRen(renId RenId) (*Ren, bool)

FindRen - 連を取得

func (*RenDb) Init

func (db *RenDb) Init(boardWidth int, boardHeight int)

Init - 初期化

func (*RenDb) RefreshToExternalFile

func (db *RenDb) RefreshToExternalFile(convertLocation func(Point) string)

RefreshToExternalFile - 外部ファイルに出力されてもいいように内部状態を整形します

func (*RenDb) RegisterRen

func (db *RenDb) RegisterRen(positionNthFigure int, positionNumber PositionNumberInt, ren *Ren)

RegisterRen - 連を登録 * すでに Id が登録されているなら、上書きしない

func (*RenDb) Save

func (db *RenDb) Save(path string, convertLocation func(Point) string, onError func(error) bool) bool

Save - 連データベースの外部ファイル書込

type RenDbDocHeader

type RenDbDocHeader struct {
	// BoardWidth - 盤の横幅
	BoardWidth int `json:"boardWidth"`
	// BoardHeight - 盤の縦幅
	BoardHeight int `json:"boardHeight"`
}

RenDbDocHeader - ヘッダー

func (*RenDbDocHeader) GetBoardMemoryArea

func (h *RenDbDocHeader) GetBoardMemoryArea() int

GetBoardMemoryArea - 枠付き盤の面積

func (*RenDbDocHeader) GetBoardMemoryHeight

func (h *RenDbDocHeader) GetBoardMemoryHeight() int

GetBoardMemoryHeight - 枠付き盤の縦幅

func (*RenDbDocHeader) GetBoardMemoryWidth

func (h *RenDbDocHeader) GetBoardMemoryWidth() int

GetBoardMemoryWidth - 枠付き盤の横幅

func (*RenDbDocHeader) Init

func (h *RenDbDocHeader) Init(boardWidth int, boardHeight int)

Init - 初期化

type RenId

type RenId string

RenId - 連データベースに格納される連のId - 外部ファイルの可読性を優先して数値型ではなく文字列 - 昇順に並ぶように前ゼロを付ける

func GetRenId

func GetRenId(boardMemoryWidth int, positionNthFigure int, positionNumber PositionNumberInt, minimumLocation Point) RenId

GetRenId - 連のIdを取得

type Stone

type Stone uint

Stone - 石の色

const (
	// Stone_Space - 空点
	Stone_Space Stone = iota
	// Stone_Black - 黒石
	Stone_Black
	// Stone_White - 白石
	Stone_White
	// Stone_Wall - 枠
	Stone_Wall
)

func GetStoneFromChar

func GetStoneFromChar(stoneChar string, getDefaultStone func() (bool, Stone)) (bool, Stone)

GetStoneFromChar - 1文字与えると、Stone値を返します

Returns ------- isOk : bool stone : Stone

func GetStoneFromName

func GetStoneFromName(stoneName string, getDefaultStone func() (bool, Stone)) (bool, Stone)

GetStoneFromName - 文字列の名前を与えると、Stone値を返します

Returns ------- isOk : bool stone : Stone

func GetStoneOrDefaultFromTurn

func GetStoneOrDefaultFromTurn(stoneName string, getDefaultStone func() Stone) Stone

GetStoneOrDefaultFromTurn - black または white を与えると、Stone値を返します

Returns ------- stone : Stone

func (Stone) GetColor

func (s Stone) GetColor() Color

GetColor - 色の取得

func (Stone) String

func (s Stone) String() string

String - 文字列化

Jump to

Keyboard shortcuts

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