take17

package
v0.0.0-...-4b218a3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: MIT Imports: 22 Imported by: 0

README

take16

利きボードを使った 利き分布を利用した評価関数を作ってる途中だぜ(^~^)

次は深さ2を目指すかだぜ(^~^)
1手詰めも欲しいけど(^~^)
処理時間を計測したいぜ(^~^)
ベータカットも欲しいなあ(^~^)
moveのうち、移動先と成りだけの move_end を作って genmove で返そ(^~^)

Build

go build

Run

kifuwarabe-wcsc31 lesson16

計測

usi
position startpos

dev
playout
# depthEnd=2のとき 36.898604 seconds

Test

position startpos
pos
control layer 0
control layer 10

# 先手から見て
watercolor 0 10 26 27 28
control layer 26
control layer 28

# 後手から見て
watercolor 10 0 26 27 28
control layer 26
control layer 28

Documentation

Overview

駒の価値

利きのテスト

Index

Constants

View Source
const (
	// 先手用
	CONTROL_LAYER_SUM1             = ControlLayerT(0) // 先手の利きボード
	CONTROL_LAYER_DIFF1_ROOK_OFF   = ControlLayerT(1) // 飛の利き 負(差分)
	CONTROL_LAYER_DIFF1_BISHOP_OFF = ControlLayerT(2) // 角の利き 負(差分)
	CONTROL_LAYER_DIFF1_LANCE_OFF  = ControlLayerT(3) // 香の利き 負(差分)
	CONTROL_LAYER_DIFF1_LANCE_ON   = ControlLayerT(4) // 香の利き 正(差分)
	CONTROL_LAYER_DIFF1_BISHOP_ON  = ControlLayerT(5) // 角の利き 正(差分)
	CONTROL_LAYER_DIFF1_ROOK_ON    = ControlLayerT(6) // 飛の利き 正(差分)
	// 先手用/開発時のみ
	CONTROL_LAYER_DIFF1_PUT      = ControlLayerT(7) // 打とか指すとか
	CONTROL_LAYER_DIFF1_REMOVE   = ControlLayerT(8)
	CONTROL_LAYER_DIFF1_CAPTURED = ControlLayerT(9)
	// 後手用
	CONTROL_LAYER_SUM2             = ControlLayerT(10) // 後手の利きボード
	CONTROL_LAYER_DIFF2_ROOK_OFF   = ControlLayerT(11)
	CONTROL_LAYER_DIFF2_BISHOP_OFF = ControlLayerT(12)
	CONTROL_LAYER_DIFF2_LANCE_OFF  = ControlLayerT(13)
	CONTROL_LAYER_DIFF2_LANCE_ON   = ControlLayerT(14)
	CONTROL_LAYER_DIFF2_BISHOP_ON  = ControlLayerT(15)
	CONTROL_LAYER_DIFF2_ROOK_ON    = ControlLayerT(16)
	// 後手用/開発時のみ
	CONTROL_LAYER_DIFF2_PUT      = ControlLayerT(17) // 打とか指すとか
	CONTROL_LAYER_DIFF2_REMOVE   = ControlLayerT(18)
	CONTROL_LAYER_DIFF2_CAPTURED = ControlLayerT(19)
	// テスト(先手用)
	CONTROL_LAYER_TEST_COPY1          = ControlLayerT(20) // テスト用
	CONTROL_LAYER_TEST_ERROR1         = ControlLayerT(21) // テスト用
	CONTROL_LAYER_TEST_RECALCULATION1 = ControlLayerT(22) // テスト用 再計算
	// テスト(後手用)
	CONTROL_LAYER_TEST_COPY2          = ControlLayerT(23)
	CONTROL_LAYER_TEST_ERROR2         = ControlLayerT(24)
	CONTROL_LAYER_TEST_RECALCULATION2 = ControlLayerT(25)
	// 評価値用
	CONTROL_LAYER_EVAL1 = ControlLayerT(26) // 評価関数用
	CONTROL_LAYER_EVAL2 = ControlLayerT(27) // 評価関数用
	CONTROL_LAYER_EVAL3 = ControlLayerT(28) // 評価関数用
	// 計測
	CONTROL_LAYER_DIFF_TYPE_SIZE_RELEASE = ControlLayerT(6)
	CONTROL_LAYER_DIFF_TYPE_SIZE_DEV     = ControlLayerT(9)
	CONTROL_LAYER_DIFF1_START            = ControlLayerT(1)
	CONTROL_LAYER_DIFF1_END_RELEASE      = CONTROL_LAYER_DIFF1_START + CONTROL_LAYER_DIFF_TYPE_SIZE_RELEASE // この数を含まない。テスト用も含まない
	CONTROL_LAYER_DIFF1_END_DEV          = CONTROL_LAYER_DIFF1_START + CONTROL_LAYER_DIFF_TYPE_SIZE_DEV     // この数を含まない。テスト用も含まない
	CONTROL_LAYER_DIFF2_START            = ControlLayerT(11)
	CONTROL_LAYER_DIFF2_END_RELEASE      = CONTROL_LAYER_DIFF2_START + CONTROL_LAYER_DIFF_TYPE_SIZE_RELEASE // この数を含まない。テスト用も含まない
	CONTROL_LAYER_DIFF2_END_DEV          = CONTROL_LAYER_DIFF2_START + CONTROL_LAYER_DIFF_TYPE_SIZE_DEV     // この数を含まない。テスト用も含まない
	CONTROL_LAYER_ALL_SIZE               = ControlLayerT(29)                                                // この数を含まない
)
View Source
const (
	BUILD_DEV     = BuildT(0)
	BUILD_RELEASE = BuildT(1)
)
View Source
const (
	POS_LAYER_MAIN  = PosLayerT(0)
	POS_LAYER_COPY  = PosLayerT(1) // テスト用
	POS_LAYER_DIFF1 = PosLayerT(2) // テスト用
	POS_LAYER_DIFF2 = PosLayerT(3) // テスト用
	POS_LAYER_SIZE  = 4
)
View Source
const (
	// 特になし
	SEARCH_NONE = SearchType(0)
	// 駒の取り合い
	SEARCH_CAPTURE = SearchType(1)
)

探索への指定

View Source
const (
	CuttingNone = CuttingType(0)
	// 玉を取った
	CuttingKingCapture = CuttingType(1)
)
View Source
const PHASE_ARRAY_SIZE = 2

[0], [1]

View Source
const RESIGN_MOVE_END = MoveEnd(0)

0 は 投了ということにするぜ(^~^)

View Source
const VALUE_INFINITE_1 = 1_000_001

最大限に使わなくても、十分に大きければ十分だが(^~^)

Variables

App - アプリケーション変数の宣言

Functions

func AddControlBishop

func AddControlBishop(pPos *l15.Position,
	pPh1_CB *ControlBoard, pPh2_CB *ControlBoard, sign int16, excludeFrom l03.Square)

AddControlBishop - 長い利きの駒の利きを調べて、利きの差分テーブルの値を増減させます

func AddControlLance

func AddControlLance(pPos *l15.Position,
	pPh1_CB *ControlBoard, pPh2_CB *ControlBoard, sign int16, excludeFrom l03.Square)

AddControlLance - 長い利きの駒の利きを調べて、利きの差分テーブルの値を増減させます

func AddControlRook

func AddControlRook(pPos *l15.Position,
	pPh1_CB *ControlBoard, pPh2_CB *ControlBoard, sign int16, excludeFrom l03.Square)

AddControlRook - 長い利きの駒の利きを調べて、利きの差分テーブルの値を増減させます

func CountAllPieces

func CountAllPieces(pPos *l15.Position) [8]int

CountAllPieces - 駒の数を確認するぜ(^~^)

func CountErrorCountLists

func CountErrorCountLists(countList1 [8]int, countList2 [8]int) int

CountErrorCountLists - 数えた駒の枚数を比較します

func EvalMaterial

func EvalMaterial(piece l03.Piece) l15.Value

EvalMaterial - 駒の価値。開発者のむずでょが勝手に決めた(^~^)

func FlipPhase

func FlipPhase(phase l03.Phase) l03.Phase

FlipPhase - 先後を反転します

func GenMoveList

func GenMoveList(pNerve *Nerve, pPos *l15.Position) []l03.Move

GenMoveList - 現局面の指し手のリスト。合法手とは限らないし、全ての合法手を含むとも限らないぜ(^~^)

func GetManhattanDistance

func GetManhattanDistance(from l03.Square, to l03.Square) int

GetManhattanDistance - マンハッタン距離

func GetSqNorthOf

func GetSqNorthOf(turn l03.Phase, srcSq l03.Square) l03.Square

GetSqNorthOf - 自分から見て手前を南としたときの、1つ北のマス。無ければ空マス

func GetSqOfOpponentKnightFrom

func GetSqOfOpponentKnightFrom(turn l03.Phase, src l03.Square) [2]l03.Square

GetSqOfOpponentKnightFrom - 自分から見て手前を南としたときの、指定の升に利いている相手の桂馬の位置

func GetSqSouthOf

func GetSqSouthOf(turn l03.Phase, src l03.Square) l03.Square

GetSqSouthOf - 自分から見て手前を南としたときの、1つ南のマス。無ければ空マス

func GetSqWestSouthAndEastSouthOf

func GetSqWestSouthAndEastSouthOf(turn l03.Phase, src l03.Square) [2]l03.Square

GetSqWestSouthAndEastSouthOf - 自分から見て手前を南としたときの、1つ南西と南東のマス。無ければ空マス

func IsBadForm

func IsBadForm(pPos *l15.Position, pNerve *Nerve, move l03.Move) bool

IsBadForm - 悪形なら真

func IterativeDeepeningSearch

func IterativeDeepeningSearch(pNerve *Nerve, tokens []string) l03.Move

IterativeDeepeningSearch - 探索部(開始)

func MainLoop

func MainLoop()

MainLoop - 開始。

func MoveEndListToControlList

func MoveEndListToControlList(moveEndList []MoveEnd) []l03.Square

MoveEndListToControlList - 移動先、成りのリストを、移動先のリストに変換します

func NifuFirst

func NifuFirst(pPos *l15.Position, file l03.Square) bool

NifuFirst - 先手で二歩になるか筋調べ

func NifuSecond

func NifuSecond(pPos *l15.Position, file l03.Square) bool

NifuSecond - 後手で二歩になるか筋調べ

func ShowAllPiecesCount

func ShowAllPiecesCount(pPos *l15.Position)

ShowAllPiecesCount - 駒の枚数表示

func ShuffleBoard

func ShuffleBoard(pNerve *Nerve, pPos *l15.Position)

ShuffleBoard - 盤上の駒、持ち駒をシャッフルします ゲーム中にはできない動きをするので、利きの計算は無視します。 最後に利きは再計算します

func SprintBoard

func SprintBoard(pPos *l15.Position) string

Print - 局面出力(^q^)

func SprintBoardHeader

func SprintBoardHeader(pPos *l15.Position, phase l03.Phase, startMovesNum int, offsetMovesIndex int) string

Print - 局面出力(^q^)

func SumAbsControl

func SumAbsControl(pNerve *Nerve, ph1_c ControlLayerT, ph2_c ControlLayerT) [2]int

SumAbsControl - 利きテーブルの各マスを絶対値にし、その総和を返します

func TestControl

func TestControl(pNerve *Nerve, pPos *l15.Position) (bool, string)

TestControl

func ValidateSq

func ValidateSq(sq l03.Square)

マス番号が正常値でなければ強制終了させます

func ValidateThereArePieceIn

func ValidateThereArePieceIn(pPos *l15.Position, sq l03.Square)

func WaterColor

func WaterColor(pCB1 *ControlBoard, pCB2 *ControlBoard, pCB3 *ControlBoard, pCB4 *ControlBoard, pCB5 *ControlBoard)

WaterColor - 水で薄めたような評価値にします pCB3 = 0 pCB4 = 0 pCB5 = 0 pCB1 - pCB2 = pCB3 pCB3 - pCB4 = pCB5

Types

type BuildT

type BuildT int

開発 or リリース モード

type ControlBoard

type ControlBoard struct {
	// 表示用の名前
	Title string
	// マスへの利き数、または差分、さらには評価値が入っています
	Board1 [l03.BOARD_SIZE]int16
}

ControlBoard - 利きボード

func ControllBoardFromPhase

func ControllBoardFromPhase(
	phase l03.Phase, pPh1_CB *ControlBoard, pPh2_CB *ControlBoard) *ControlBoard

func NewControlBoard

func NewControlBoard(title string) *ControlBoard

NewControlBoard - 利きボード生成

func (*ControlBoard) AddControl

func (pCB *ControlBoard) AddControl(sq_list []l03.Square, from l03.Square, sign int16)

AddControl - 盤上のマスを指定することで、そこにある駒の利きを調べて、利きの差分テーブルの値を増減させます

func (*ControlBoard) Clear

func (pCB *ControlBoard) Clear()

Clear - 利きボードのクリアー

type ControlBoardSystem

type ControlBoardSystem struct {
	// マスへの利き数、または差分が入っています。デバッグ目的で無駄に分けてるんだけどな(^~^)
	PBoards [CONTROL_LAYER_ALL_SIZE]*ControlBoard
}

ControlBoardSystem - 利きボード・システム TODO 自玉が王手されてるか調べてほしい(^~^)

func NewControlBoardSystem

func NewControlBoardSystem() *ControlBoardSystem

func (*ControlBoardSystem) ClearControlDiff

func (pCtrlBrdSys *ControlBoardSystem) ClearControlDiff(buildType BuildT)

ClearControlDiff - 利きの差分テーブルをクリアーするぜ(^~^)

func (*ControlBoardSystem) ClearControlLayer1

func (pCtrlBrdSys *ControlBoardSystem) ClearControlLayer1(ph1_c ControlLayerT, ph2_c ControlLayerT)

ClearControlLayer - 利きボードのクリアー

func (*ControlBoardSystem) DiffControl

func (pCtrlBrdSys *ControlBoardSystem) DiffControl(c1 ControlLayerT, c2 ControlLayerT, c3 ControlLayerT)

DiffControl - 利きテーブルの差分計算

func (*ControlBoardSystem) MergeControlDiff

func (pCtrlBrdSys *ControlBoardSystem) MergeControlDiff(buildType BuildT)

MergeControlDiff - 利きの差分を解消するぜ(^~^)

func (*ControlBoardSystem) RecalculateControl

func (pCtrlBrdSys *ControlBoardSystem) RecalculateControl(
	pPos *l15.Position, ph1_c1 ControlLayerT, ph2_c1 ControlLayerT)

RecalculateControl - 利きの再計算

func (*ControlBoardSystem) SprintControl

func (pCtrlBrdSys *ControlBoardSystem) SprintControl(c ControlLayerT) string

SprintControl - 利き数ボード出力(^q^)

Parameters ---------- * `c` - 利き数ボードのレイヤー番号(^~^)

type ControlLayerT

type ControlLayerT int

利きテーブル・インデックス型

type CuttingType

type CuttingType int

type DifferenceRecord

type DifferenceRecord struct {
	// 開始局面の時点で何手目か(^~^)これは表示のための飾りのようなものだぜ(^~^)
	StartMovesNum int
	// 開始局面から数えて何手目か(^~^)0から始まるぜ(^~^)
	OffsetMovesIndex int
	// 指し手のリスト(^~^)
	// 1手目は[0]へ、512手目は[511]へ入れろだぜ(^~^)
	Moves [l02.MOVES_SIZE]l03.Move
	// 取った駒のリスト(^~^)アンドゥ ムーブするときに使うだけ(^~^)指し手のリストと同じ添え字を使うぜ(^~^)
	CapturedList [l02.MOVES_SIZE]l03.Piece
}

差分での連続局面記録。つまり、ふつうの棋譜(^~^)

func NewDifferenceRecord

func NewDifferenceRecord() *DifferenceRecord

func (*DifferenceRecord) ResetDifferenceRecord

func (pRecord *DifferenceRecord) ResetDifferenceRecord()

type MoveEnd

type MoveEnd uint8

MoveEnd - 移動先と成り

pddd dddd

1~7bit: 移動先(0~127) 8bit: 成(0~1)

func GenMoveEnd

func GenMoveEnd(pPos *l15.Position, from l03.Square) []MoveEnd

GenMoveEnd - 利いているマスの一覧を返します。動けるマスではありません。 成らないと移動できないが、成れば移動できるマスがあるので、移動先と成りの2つセットで返します。

func NewMoveEnd

func NewMoveEnd(to l03.Square, promotion bool) MoveEnd

NewMoveEnd - 移動先マス、成りの有無 を指定してください

func (MoveEnd) Destructure

func (moveEnd MoveEnd) Destructure() (l03.Square, bool)

Destructure

移動先マス 0111 1111 (Mask) 0x7f pddd dddd

成 1000 0000 (Mask) 0x80 pddd dddd

func (MoveEnd) ToString

func (moveEnd MoveEnd) ToString() string

ToString - 確認用の文字列

type Nerve

type Nerve struct {
	// 開発モードフラグ。デフォルト値:真。 'usi' コマンドで解除
	BuildType BuildT
	// 局面システム
	PPosSys *PositionSystem
	// 利きボード・システム
	PCtrlBrdSys *ControlBoardSystem
	// 差分での連続局面記録。つまり、ふつうの棋譜(^~^)
	PRecord *DifferenceRecord
	// 時間管理用
	OneMoveSec int
	// 時間管理用
	IsStopSearch bool
	// 時間管理用
	PStopwatchSearch *Stopwatch
	// エンジン・オプション
	MaxDepth int
}

Nerve - 局面システムと、利き盤システムの2つを持つもの

func NewNerve

func NewNerve() *Nerve

func (*Nerve) ClearBySearchEntry

func (pNerve *Nerve) ClearBySearchEntry()

func (*Nerve) DoMove

func (pNerve *Nerve) DoMove(pPos *l15.Position, move l03.Move)

DoMove - 一手指すぜ(^~^)

func (*Nerve) Dump

func (pNerve *Nerve) Dump() string

Dump - 内部状態を全部出力しようぜ(^~^)?

func (*Nerve) IsCheckmate

func (pNerve *Nerve) IsCheckmate(phase l03.Phase) bool

長い利きの駒から王手を受けていないかチェック(^~^)

func (*Nerve) ReadPosition

func (pNerve *Nerve) ReadPosition(pPos *l15.Position, command string)

ReadPosition - 局面を読み取ります。マルチバイト文字は含まれていないぜ(^q^)

func (*Nerve) SprintBoardFooter

func (pNerve *Nerve) SprintBoardFooter() string

SprintBoardFooter - 局面出力(^q^)

func (*Nerve) UndoMove

func (pNerve *Nerve) UndoMove(pPos *l15.Position)

UndoMove - 棋譜を頼りに1手戻すぜ(^~^)

type PosLayerT

type PosLayerT int

盤レイヤー・インデックス型

type PositionSystem

type PositionSystem struct {
	// 局面
	PPosition [POS_LAYER_SIZE]*l15.Position
	// contains filtered or unexported fields
}

PositionSystem - 局面にいろいろな機能を付けたもの

func NewPositionSystem

func NewPositionSystem() *PositionSystem

func (*PositionSystem) FlipPhase

func (pPosSys *PositionSystem) FlipPhase()

FlipPhase - フェーズをひっくり返すぜ(^~^)

func (*PositionSystem) GetPhase

func (pPosSys *PositionSystem) GetPhase() l03.Phase

GetPhase - フェーズ

func (*PositionSystem) ResetPosition

func (pPosSys *PositionSystem) ResetPosition()

ResetToStartpos - 駒を置いていな状態でリセットします

type SearchType

type SearchType uint8

type Stopwatch

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

func NewStopwatch

func NewStopwatch() *Stopwatch

/ NewStopwatch - ストップウォッチ生成

func (*Stopwatch) Elapsed

func (pStopwatch *Stopwatch) Elapsed() time.Duration

/ Elapsed - 経過時間取得

func (*Stopwatch) ElapsedSeconds

func (pStopwatch *Stopwatch) ElapsedSeconds() float64

/ ElapsedSeconds - 経過時間取得(秒)

func (*Stopwatch) StartStopwatch

func (pStopwatch *Stopwatch) StartStopwatch()

/ StartStopwatch - 計測開始

Jump to

Keyboard shortcuts

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