take11

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: 20 Imported by: 0

README

take11

駒得評価関数は入れたしな(^~^)
きふわらべがどう評価しているか、infoも入れたし(^~^)
利きの差分表も 飛、角、香 を分けた(^~^)
テスト用のランダム局面を増やすために、シャッフルとプレイアウトも入れた(^~^)
王手回避のときに打をして、間駒もするはずだぜ(^~^)

玉は逃げてくれてるようだし、アルファベータ探索入れてみよかな(^~^)
探索中に盤面が元に戻ってないことがあるなあ(^~^)盤面2つに増やすかな(^~^)?

Test

# 強制終了した(^~^)
position startpos moves 1g1f 4a3b 1f1e 6a5b 2g2f 2c2d 3g3f 5a4b 3f3e 4c4d 4g4f 5b4c 5g5f 7c7d 5f5e 7d7e 6g6f 9c9d 6f6e 9d9e 8g8f 8c8d 2h4h 5c5d 1e1d 1c1d 3e3d 3c3d 5e5d 4c5d 6e6d 5d6d 4h6h 8d8e 2f2e 2d2e 4f4e 8e8f 4e4d 8f8g+ 4d4c 3b4c 7g7f 8g8h 7f7e 8h9i 7e7d 8b8i+ 7d7c N*5g 7c7b 2b7g+
# go btime 86000 wtime 83000 binc 2000 winc 2000
# Error: 59 square is empty
# quit

# 盤をコピー(^~^)
board copy 0 1

# 盤[1]を表示(^~^)
pos 1

# 盤[0], [1] の比較
posdiff 0 1

board diff

# 盤[2], [3] の比較
posdiff 2 3

# 盤[0], [1] の異なる箇所の数
error board 0 1 2 3

location 0
location 1

Test2

# 後手馬で先手飛を取って、アンドゥするテスト(^~^)
position sfen 4k4/9/9/9/9/9/2+b6/3R5/4K4 w - 1
pos
do 7g6h
pos
location 0
undo
pos
location 0

Test3

break文抜け修正(^~^)

position startpos moves 7g7f 3c3d
pos
location 0
do 8h2b
pos
location 0
undo
location 0

Test4

ソート入れて修正(^~^)

# position startpos moves 1g1f 4a3b 1f1e 6a5b 2g2f 2c2d 3g3f 5a4b 3f3e 4c4d 4g4f 5b4c 5g5f 7c7d 5f5e 7d7e 6g6f 9c9d 6f6e 9d9e 8g8f 8c8d 2h4h 5c5d 1e1d 1c1d
position startpos moves 1g1f 4a3b 1f1e 6a5b 2g2f 2c2d 3g3f 5a4b 3f3e 4c4d 4g4f 5b4c 5g5f 7c7d 5f5e 7d7e 6g6f 9c9d 6f6e 9d9e 8g8f 8c8d 2h4h 5c5d 1e1d 1c1d 1i1d

pos

location 0

do 1a1d

pos

location 0

# 強制終了(^~^)
# go

undo
# pawnが減ってない?
pos
location 0

# 後手香車で、先手香車を取ると不具合(^~^)?
# 探索をやっていると、位置が変わることがあるようだ(^~^)?
#
#  K   k      R          B          L
# +---+---+  +---+---+  +---+---+  +---+---+---+---+
# | 59| 42|  | 48| 82|  | 22| 88|  | 14| 11| 91| 99|
# +---+---+  +---+---+  +---+---+  +---+---+---+---+
#
#  K   k      R          B          L
# +---+---+  +---+---+  +---+---+  +---+---+---+---+
# | 59| 42|  | 48| 82|  | 22| 88|  | 11| 14| 91| 99|
# +---+---+  +---+---+  +---+---+  +---+---+---+---+

Test5

取った駒のアンドゥ時、フェーズ 0 を return してたんで、それを除去して修正(^~^)

position startpos moves 7g7f 7a6b 6i7h 5c5d 7i6h 6a7a 6h7g 4a4b 5i6h 8b9b 4i5h 1c1d 3i3h 2b1c 1g1f 9c9d 1f1e 1d1e 1i1e 5d5e 1e1c 2a1c P*1d 1c2e 2g2f L*6a 2f2e P*1e N*5d 4b4a 5d6b+ 5a6b 1d1c+ 1a1c B*3e 4c4d 3e1c+ 3a3b 1c4f 9b8b 4f5e N*9e 5e4d P*5c P*1b

pos

# 強制終了(玉を取ってしまうらしい)
go

position sfen 4k4/9/9/9/9/9/9/4p4/4K4 w - 1
pos
location 0
# らいおんきゃっち(相手玉を取ったから自分の駒台に玉が乗る)
do 5h5i
pos
location 0
record
undo
# 玉が戻ってない
pos
location 0

Test6

position startpos moves 5i5h 4a3b 8g8f 6a5b 2g2f 5a4b 6g6f 3c3d 5h4h 2b6f

# 強制終了(^~^) 後手玉の位置が、先手玉の位置になってる(^~^)
go

position sfen 4k4/4P4/9/9/9/9/9/9/4K4 b - 1
pos
do 5b5a
location 0
pos
undo
pos
location 0

Test7

position startpos moves 7g7f 9c9d 6i7h 9d9e 7i6h 9e9f 9g9f 1c1d 9f9e 8b5b 3i4h 7a7b 9e9d 4a4b 5i6i 5b6b 6h7g 2a1c 4i5h 3c3d 3g3f 2b5e 4h3g 1d1e 1g1f 6a7a 1f1e 6b5b 5g5f 5e2b 2g2f 2b4d 1e1d 6c6d 1d1c+ 2c2d P*1b 7b6a 1b1a+ 4d1a N*2c

pos
location 0
record
count
movelist

# >2:go btime 81000 wtime 58000 binc 2000 winc 2000

Documentation

Overview

駒の価値

利きボード

利きのテスト

Index

Constants

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 (
	CONTROL_LAYER_SUM                = ControlLayerT(0)
	CONTROL_LAYER_DIFF_ROOK_OFF      = ControlLayerT(1)
	CONTROL_LAYER_DIFF_BISHOP_OFF    = ControlLayerT(2)
	CONTROL_LAYER_DIFF_LANCE_OFF     = ControlLayerT(3)
	CONTROL_LAYER_DIFF_PUT           = ControlLayerT(4) // 打とか指すとか
	CONTROL_LAYER_DIFF_REMOVE        = ControlLayerT(5)
	CONTROL_LAYER_DIFF_CAPTURED      = ControlLayerT(6)
	CONTROL_LAYER_DIFF_LANCE_ON      = ControlLayerT(7)
	CONTROL_LAYER_DIFF_BISHOP_ON     = ControlLayerT(8)
	CONTROL_LAYER_DIFF_ROOK_ON       = ControlLayerT(9)
	CONTROL_LAYER_TEST_COPY          = ControlLayerT(10) // テスト用
	CONTROL_LAYER_TEST_ERROR         = ControlLayerT(11) // テスト用
	CONTROL_LAYER_TEST_RECALCULATION = ControlLayerT(12) // テスト用 再計算
	CONTROL_LAYER_DIFF_START         = ControlLayerT(1)
	CONTROL_LAYER_DIFF_END           = ControlLayerT(10) // この数を含まない。テスト用も含まない
	CONTROL_LAYER_ALL_SIZE           = 13                // この数を含まない
)
View Source
const MAX_VALUE = 32767
View Source
const PHASE_ARRAY_SIZE = 2

[0], [1]

View Source
const RESIGN_MOVE_END = MoveEnd(0)

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

View Source
const RESIGN_VALUE = -32768

Variables

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

View Source
var OneDigitNumbers = [10]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}

position sfen の盤のスペース数に使われますN

Functions

func CountAllPieces

func CountAllPieces(pPos *Position) [8]int

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

func CountErrorCountLists

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

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

func EvalMaterial

func EvalMaterial(piece l03.Piece) int16

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

func FlipPhase

func FlipPhase(phase l03.Phase) l03.Phase

FlipPhase - 先後を反転します

func GenMoveList

func GenMoveList(pPosSys *PositionSystem, pPos *Position) []l03.Move

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

func GetControlLayerName

func GetControlLayerName(c ControlLayerT) string

GetControlLayerName - 利きボードのレイヤーの名前

func MainLoop

func MainLoop()

MainLoop - 開始。

func NifuFirst

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

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

func NifuSecond

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

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

func OnBoard

func OnBoard(sq l03.Square) bool

OnBoard - 盤上なら真

func OnHands

func OnHands(sq l03.Square) bool

OnHands - 持ち駒なら真

func Search(pPosSys *PositionSystem) l03.Move

Search - 探索部

func ShowAllPiecesCount

func ShowAllPiecesCount(pPos *Position)

ShowAllPiecesCount - 駒の枚数表示

func ShuffleBoard

func ShuffleBoard(pPosSys *PositionSystem, pPos *Position)

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

func SprintBoard

func SprintBoard(pPos *Position, phase l03.Phase, startMovesNum int, offsetMovesIndex int, moves_text string) string

Print - 局面出力(^q^)

func SquareFrom

func SquareFrom(file l03.Square, rank l03.Square) l03.Square

From - 筋と段からマス番号を作成します

func SumAbsControl

func SumAbsControl(pPosSys *PositionSystem, layer1 int) [2]int

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

func TestControl

func TestControl(pPosSys *PositionSystem, pPos *Position) (bool, string)

TestControl

func ValidateSq

func ValidateSq(sq l03.Square)

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

Types

type ControlLayerT

type ControlLayerT int

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

type MoveEnd

type MoveEnd uint8

MoveEnd - 移動先と成り

pddd dddd

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

func GenMoveEnd

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

GenMoveEnd - 利いているマスの一覧を返します。動けるマスではありません。

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 PosLayerT

type PosLayerT int

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

type Position

type Position struct {
	// Go言語で列挙型めんどくさいんで文字列で(^~^)
	// [19] は 1九、 [91] は 9一(^~^)反時計回りに90°回転した将棋盤の状態で入ってるぜ(^~^)想像しろだぜ(^~^)
	Board [l03.BOARD_SIZE]l03.Piece
	// 玉と長い利きの駒の場所。長い利きを消すのに使う
	// [0]先手玉 [1]後手玉 [2:3]飛 [4:5]角 [6:9]香
	PieceLocations [l07.PCLOC_SIZE]l03.Square
	// 持ち駒の数だぜ(^~^)玉もある(^~^) K, R, B, G, S, N, L, P, k, r, b, g, s, n, l, p
	Hands1 [l03.HAND_SIZE]int
}

Position - 局面 TODO 利きボードも含めたい

func NewPosition

func NewPosition() *Position

func (*Position) GetLocationOfLongPiece

func (pPos *Position) GetLocationOfLongPiece(index int) l03.Square

GetLongPiece - 長い利きの駒の場所を取得

func (*Position) GetPieceLocation

func (pPos *Position) GetPieceLocation(index int) l03.Square

func (*Position) Hetero

func (pPos *Position) Hetero(from l03.Square, to l03.Square) bool

Hetero - 移動元と移動先の駒を持つプレイヤーが異なれば真。移動先が空マスでも真 持ち駒は指定してはいけません。 Homo の逆だぜ(^~^)片方ありゃいいんだけど(^~^)

func (*Position) Homo

func (pPos *Position) Homo(from l03.Square, to l03.Square) bool

Homo - 移動元と移動先の駒を持つプレイヤーが等しければ真。移動先が空なら偽 持ち駒は指定してはいけません。

func (*Position) IsEmptySq

func (pPos *Position) IsEmptySq(sq l03.Square) bool

IsEmptySq - 空きマスなら真。持ち駒は偽

type PositionSystem

type PositionSystem struct {
	// 局面
	PPosition [POS_LAYER_SIZE]*Position

	// マスへの利き数、または差分が入っています。デバッグ目的で無駄に分けてるんだけどな(^~^)
	// 利きテーブル [0]先手 [1]後手
	// [0] 利き
	// [1] 飛の利き引く(差分)
	// [2] 角の利き引く(差分)
	// [3] 香の利き引く(差分)
	// [4] ムーブ用(差分)
	// [5] ムーブ用(差分)
	// [6] ムーブ用(差分)
	// [7] 香の利き戻す(差分)
	// [8] 角の利き戻す(差分)
	// [9] 飛の利き戻す(差分)
	// [10] テスト用
	// [11] テスト用
	// [12] テスト用(再計算)
	ControlBoards [2][CONTROL_LAYER_ALL_SIZE][l03.BOARD_SIZE]int8

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

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

func NewPositionSystem

func NewPositionSystem() *PositionSystem

func (*PositionSystem) AddControlBishop

func (pPosSys *PositionSystem) AddControlBishop(pPos *Position, c ControlLayerT, sign int8, excludeFrom l03.Square)

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

func (*PositionSystem) AddControlDiff

func (pPosSys *PositionSystem) AddControlDiff(pPos *Position, c ControlLayerT, from l03.Square, sign int8)

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

func (*PositionSystem) AddControlLance

func (pPosSys *PositionSystem) AddControlLance(pPos *Position, c ControlLayerT, sign int8, excludeFrom l03.Square)

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

func (*PositionSystem) AddControlRook

func (pPosSys *PositionSystem) AddControlRook(pPos *Position, c ControlLayerT, sign int8, excludeFrom l03.Square)

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

func (*PositionSystem) ClearControlDiff

func (pPosSys *PositionSystem) ClearControlDiff()

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

func (*PositionSystem) ClearControlLayer

func (pPosSys *PositionSystem) ClearControlLayer(c ControlLayerT)

func (*PositionSystem) DiffControl

func (pPosSys *PositionSystem) DiffControl(c1 ControlLayerT, c2 ControlLayerT, c3 ControlLayerT)

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

func (*PositionSystem) DoMove

func (pPosSys *PositionSystem) DoMove(pPos *Position, move l03.Move)

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

func (*PositionSystem) Dump

func (pPosSys *PositionSystem) Dump() string

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

func (*PositionSystem) FlipPhase

func (pPosSys *PositionSystem) FlipPhase()

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

func (*PositionSystem) GetPhase

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

GetPhase - フェーズ

func (*PositionSystem) MergeControlDiff

func (pPosSys *PositionSystem) MergeControlDiff()

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

func (*PositionSystem) ReadPosition

func (pPosSys *PositionSystem) ReadPosition(pPos *Position, command string)

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

func (*PositionSystem) RecalculateControl

func (pPosSys *PositionSystem) RecalculateControl(pPos *Position, c1 ControlLayerT)

RecalculateControl - 利きの再計算

func (*PositionSystem) SprintControl

func (pPosSys *PositionSystem) SprintControl(phase l03.Phase, c ControlLayerT) string

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

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

func (*PositionSystem) SprintDiff

func (pPosSys *PositionSystem) SprintDiff(b1 PosLayerT, b2 PosLayerT) string

Print - 2局面の比較用画面出力(^q^)

func (*PositionSystem) SprintRecord

func (pPosSys *PositionSystem) SprintRecord() string

SprintRecord - 棋譜表示(^~^)

func (*PositionSystem) SprintSfen

func (pPosSys *PositionSystem) SprintSfen(pPos *Position) string

SprintSfen - SFEN文字列返せよ(^~^)

func (*PositionSystem) UndoMove

func (pPosSys *PositionSystem) UndoMove(pPos *Position)

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

Jump to

Keyboard shortcuts

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