take8

package
v0.0.0-...-f2ec8e9 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 11 Imported by: 0

README

take8

玉が利きに飛び込むの止めてほしいなあ(^~^)
利きを調べるかな(^~^)
利きテーブル作るか~(^~^)
まず、簡単な指し手は生成したぜ(^~^)

Test

position startpos moves 3i3h 4a3b 5i6h 6a5b 4g4f 5a4b 5g5f 4c4d 6g6f 5b4c 6h5i 1c1d 4i3i 2b1c 1g1f 1c4f 3i4h 5c5d 3g3f 4f2h+ 6i7h
pos

[1 -> 22 moves / Second / ? repeats]

  r  b  g  s  n  l  p
+--+--+--+--+--+--+--+
| 1| 0| 0| 0| 0| 0| 1|
+--+--+--+--+--+--+--+

  9  8  7  6  5  4  3  2  1
+--+--+--+--+--+--+--+--+--+
| l| n| s|  |  |  | s| n| l| a
+--+--+--+--+--+--+--+--+--+
|  | r|  |  |  | k| g|  |  | b
+--+--+--+--+--+--+--+--+--+
| p| p| p| p|  | g| p| p|  | c
+--+--+--+--+--+--+--+--+--+
|  |  |  |  | p| p|  |  | p| d
+--+--+--+--+--+--+--+--+--+
|  |  |  |  |  |  |  |  |  | e
+--+--+--+--+--+--+--+--+--+
|  |  |  | P| P|  | P|  | P| f
+--+--+--+--+--+--+--+--+--+
| P| P| P|  |  |  |  | P|  | g
+--+--+--+--+--+--+--+--+--+
|  | B| G|  |  | G| S| b|  | h
+--+--+--+--+--+--+--+--+--+
| L| N| S|  | K|  |  | N| L| i
+--+--+--+--+--+--+--+--+--+

        R  B  G  S  N  L  P
      +--+--+--+--+--+--+--+
      | 0| 0| 0| 0| 0| 0| 0|
      +--+--+--+--+--+--+--+

# 28 にある駒の利きを調べようとするが、そこに駒は無いぜ(^~^)
position startpos moves 3i3h 4a3b 5i6h 6a5b 4g4f 5a4b 5g5f 4c4d 6g6f 5b4c 6h5i 1c1d 4i3i 2b1c 1g1f 1c4f 3i4h 5c5d 3g3f 4f2h+ 6i7h 2h1i
go btime 71000 wtime 71000 binc 2000 winc 2000

# 長い利きの駒である 馬 が 1i に動いたとき、角と馬を同一視できてない(^~^)?
# PieceType の B には RB は含んでないしな(^~^)

Test2

# 平手初期局面を sfen で指定(^~^)
position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1
pos
control
control diff

# 玉と歩だけ(^~^)
position sfen 4k4/9/ppppppppp/9/9/9/PPPPPPPPP/9/4K4 b - 1
pos
control
control diff

# 玉と歩と飛だけ(^~^)
position sfen 4k4/1r7/ppppppppp/9/9/9/PPPPPPPPP/7R1/4K4 b - 1
pos
control
control diff

# 玉だけ(^~^)
position sfen 4k4/9/9/9/9/9/9/9/4K4 b - 1
pos
control
control diff

# 香を1個にして利きの様子を見たろ(^~^)
position sfen 4k4/9/9/9/9/9/9/9/4K3L b - 1
pos
control diff

# 歩を置いたろ(^~^)
position sfen 4k4/9/9/9/9/9/8P/9/4K3L b - 1
pos
control diff

# 飛車の利きをテストするとき(^~^)
position sfen 4k4/9/9/5R3/2P3P2/9/9/9/4K4 b - 1
pos
control diff
do 4d4e

Test3

# 歩が成られたところで、強制終了した(^~^) --> dropのとこ直した
position startpos moves 2g2f 1c1d 6i7h 9a9b 5i6h 4a3b 4i5h 5c5d 6g6f 7a6b 5h6g 6a7b 2f2e 2a1c 2e2d 7c7d 2d2c+

# 飛打で王手されたところで、強制終了した(^~^)
# 王手回避を考えてるときに、盤のUndoがちゃんとできてないようだぜ(^~^)
position startpos moves 7g7f 4a5b 6i7h 6a6b 7i6h 5b4b 6h7g 4b5b 5i6h 5a4a 4i5h 2c2d 6g6f 7c7d 5h6g 3a3b 9g9f 6b7c 8i9g 7a6b 6f6e 5c5d 9g8e 5b4b 8e7c+ 2d2e 7c8b 1c1d R*6a

# 逃げなかった(^~^)
position startpos moves 7g7f 3c3d 8h5e 2b5e 7i7h 5e9i+ 3i4h L*7d 7f7e 7d7e 4i5h B*9h 5h6h 7e7h+ 1i1h 7h6i

Test4

# 王手されている局面(タダの頭金)
position sfen 4k4/9/9/9/9/9/9/4g4/4K4 b - 1
movelist
MoveList
--------
(0) 5i5h

# 詰んでいる局面(頭金)
position sfen 4k4/9/9/9/9/9/4p4/4g4/4K4 b - 1
movelist
# 指し手なし

# 王手されている局面(頭金、逃げ場所あり)
position sfen 4k4/9/9/9/9/4p4/4g4/4K4/9 b - 1
movelist
MoveList
--------
(0) 5h5i
(1) 5h6i
(2) 5h4i

# 長い利きで王手(1間、逃げ場所あり)
position sfen 4k4/9/9/9/9/4l4/9/4K4/9 b - 1
movelist
MoveList
--------
(0) 5h6g
(1) 5h4g
(2) 5h6i
(3) 5h4i
(4) 5h6h
(5) 5h4h
# 5i に逃げれないことが分かっていればOK

# 長い利きで王手(1間打、逃げ場所あり)
position sfen 4k4/9/9/9/9/9/9/4K4/9 w l 1 moves L*5f
movelist

# 桂馬で王手(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/3n5/9/4K4/9/7R1 b - 1
movelist

# 桂打で王手(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/9/9/4K4/9/7R1 w - 1 moves N*6e
movelist

# 杏が寄ってきているが王手ではない(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/9/9/9/2+lS5/5K3 w - 1 moves 7h6i
movelist

# 杏が寄ってきているが王手ではない(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/9/9/9/2+l1S4/5K3 w - 1 moves 7h6i
movelist

# 杏が寄ってきて王手(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/9/9/9/2+l2G3/4K4 w - 1 moves 7h6i
movelist

# 杏が寄ってきて王手(逃げ場所あり、他の自駒あり)
# なぜか玉が逃げない(^~^)
position sfen 4k4/9/9/9/9/9/9/2+lS5/4K4 w - 1 moves 7h6i
movelist

# 杏が寄ってきて王手(逃げ場所あり、他の自駒あり)
position sfen 4k4/9/9/9/9/9/9/2+lS1G3/4K4 w - 1 moves 7h6i
movelist

Documentation

Index

Constants

View Source
const (
	// 持ち駒を打つ 100~113
	// 先手飛打
	HAND_R1        = Square(100)
	HAND_B1        = Square(101)
	HAND_G1        = Square(102)
	HAND_S1        = Square(103)
	HAND_N1        = Square(104)
	HAND_L1        = Square(105)
	HAND_P1        = Square(106)
	HAND_R2        = Square(107)
	HAND_B2        = Square(108)
	HAND_G2        = Square(109)
	HAND_S2        = Square(110)
	HAND_N2        = Square(111)
	HAND_L2        = Square(112)
	HAND_P2        = Square(113)
	HAND_ORIGIN    = HAND_R1
	HAND_TYPE_SIZE = HAND_P1 - HAND_ORIGIN + 1
)
View Source
const (
	PIECE_TYPE_EMPTY = PieceType(0) // 空マス
	PIECE_TYPE_K     = PieceType(1)
	PIECE_TYPE_R     = PieceType(2)
	PIECE_TYPE_B     = PieceType(3)
	PIECE_TYPE_G     = PieceType(4)
	PIECE_TYPE_S     = PieceType(5)
	PIECE_TYPE_N     = PieceType(6)
	PIECE_TYPE_L     = PieceType(7)
	PIECE_TYPE_P     = PieceType(8)
	PIECE_TYPE_PR    = PieceType(9)
	PIECE_TYPE_PB    = PieceType(10)
	PIECE_TYPE_PS    = PieceType(11)
	PIECE_TYPE_PN    = PieceType(12)
	PIECE_TYPE_PL    = PieceType(13)
	PIECE_TYPE_PP    = PieceType(14)
)
View Source
const (
	// 空マス
	ZEROTH = Phase(0)
	// 先手
	FIRST = Phase(1)
	// 後手
	SECOND = Phase(2)
)
View Source
const (
	PIECE_EMPTY = ""
	PIECE_K1    = "K"
	PIECE_R1    = "R"
	PIECE_B1    = "B"
	PIECE_G1    = "G"
	PIECE_S1    = "S"
	PIECE_N1    = "N"
	PIECE_L1    = "L"
	PIECE_P1    = "P"
	PIECE_PR1   = "+R"
	PIECE_PB1   = "+B"
	PIECE_PS1   = "+S"
	PIECE_PN1   = "+N"
	PIECE_PL1   = "+L"
	PIECE_PP1   = "+P"
	PIECE_K2    = "k"
	PIECE_R2    = "r"
	PIECE_B2    = "b"
	PIECE_G2    = "g"
	PIECE_S2    = "s"
	PIECE_N2    = "n"
	PIECE_L2    = "l"
	PIECE_P2    = "p"
	PIECE_PR2   = "+r"
	PIECE_PB2   = "+b"
	PIECE_PS2   = "+s"
	PIECE_PN2   = "+n"
	PIECE_PL2   = "+l"
	PIECE_PP2   = "+p"
)

View Source
const (
	// Author - 囲碁思考エンジンの作者名だぜ☆(^~^)
	Author = "Satoshi Takahashi"
)
View Source
const BOARD_SIZE = 100

00~99

View Source
const MOVES_SIZE = 512

電竜戦が一番長いだろ(^~^)

View Source
const ResignMove = Move(0)

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

View Source
const SQUARE_EMPTY = Square(0)

マス番号を指定しないことを意味するマス番号

Variables

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

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

Functions

func Demote

func Demote(piece string) string

Demote - 成っている駒を、成っていない駒に戻します

func MainLoop

func MainLoop()

MainLoop - 開始。

func NifuFirst

func NifuFirst(pPos *Position, file Square) bool

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

func NifuSecond

func NifuSecond(pPos *Position, file Square) bool

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

func OnBoard

func OnBoard(sq Square) bool

盤上なら真。ラベルのとこを指定しても場所によっては真だがめんどくさいんでOKで(^~^)

func Promote

func Promote(piece string) string

Promote - 成ります

Types

type EngineConf

type EngineConf struct {
	Profile Profile
}

EngineConf - Tomlファイル。

func LoadEngineConf

func LoadEngineConf(path string) (*EngineConf, error)

LoadEngineConf - ゲーム設定ファイルを読み込みます。

type Move

type Move uint16

Move - 指し手

15bit で表せるはず(^~^) .pdd dddd dsss ssss

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

func GenMoveList

func GenMoveList(pPos *Position) []Move

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

func NewMoveValue

func NewMoveValue() Move

func NewMoveValue2

func NewMoveValue2(src_sq Square, dst_sq Square) Move

NewMoveValue2 - 初期値として 移動元マス、移動先マスを指定してください TODO 成、不成も欲しいぜ(^~^)

func ParseMove

func ParseMove(command string, i *int, phase Phase) (Move, error)

ParseMove - 指し手コマンドを解析

func Search(pPos *Position) Move

Search - 探索部

func (Move) GetDestination

func (move Move) GetDestination() Square

GetDestination - 移動元マス 0011 1111 1000 0000 (Mask) 0x3f80 .pdd dddd dsss ssss

func (Move) GetPromotion

func (move Move) GetPromotion() bool

GetPromotion - 成 0100 0000 0000 0000 (Mask) 0x4000 .pdd dddd dsss ssss

func (Move) GetSource

func (move Move) GetSource() Square

GetSource - 移動元マス 0000 0000 0111 1111 (Mask) 0x007f .pdd dddd dsss ssss

func (Move) ReplaceDestination

func (move Move) ReplaceDestination(sq Square) Move

ReplaceDestination - 移動先マス 1100 0000 0111 1111 (Clear) 0xc07f .pdd dddd dsss ssss

func (Move) ReplacePromotion

func (move Move) ReplacePromotion(promotion bool) Move

ReplacePromotion - 成 0100 0000 0000 0000 (Stand) 0x4000 1011 1111 1111 1111 (Clear) 0xbfff .pdd dddd dsss ssss

func (Move) ReplaceSource

func (move Move) ReplaceSource(sq Square) Move

ReplaceSource - 移動元マス 1111 1111 1000 0000 (Clear) 0xff80 .pdd dddd dsss ssss

func (Move) ToCode

func (move Move) ToCode() string

ToCode - SFEN の moves の後に続く指し手に使える文字列を返します

type Phase

type Phase byte

1:先手 2:後手

func FlipPhase

func FlipPhase(phase Phase) Phase

FlipPhase - 先後を反転します

func Who

func Who(piece string) Phase

Who - 駒が先手か後手か空升かを返します

type PieceType

type PieceType byte

先後のない駒種類

func What

func What(piece string) PieceType

What - 先後のない駒種類を返します。

func WhatHand

func WhatHand(hand Square) PieceType

WhatHand - 持ち駒のマス番号から、先後なしの駒種類を返します

type Position

type Position struct {
	// Go言語で列挙型めんどくさいんで文字列で(^~^)
	// [19] は 1九、 [91] は 9一(^~^)反時計回りに90°回転した将棋盤の状態で入ってるぜ(^~^)想像しろだぜ(^~^)
	Board [BOARD_SIZE]string
	// [0]先手 [1]後手
	KingLocations [2]Square
	// 飛車の場所。長い利きを消すために必要(^~^)
	RookLocations [2]Square
	// 角の場所。長い利きを消すために必要(^~^)
	BishopLocations [2]Square
	// 香の場所。長い利きを消すために必要(^~^)
	LanceLocations [4]Square
	// 利きテーブル [0]先手 [1]後手
	// マスへの利き数が入っています
	ControlBoards [2][BOARD_SIZE]int8
	// マスへの利き数の差分が入っています。デバッグ目的で無駄に分けてるんだけどな(^~^)
	// プレイヤー1つにつき、5レイヤーあるぜ(^~^)
	ControlBoardsDiff [2][5][BOARD_SIZE]int8

	// 持ち駒の数だぜ(^~^) R, B, G, S, N, L, P, r, b, g, s, n, l, p
	Hands []int
	// 先手が1、後手が2(^~^)
	Phase Phase
	// 開始局面の時点で何手目か(^~^)これは表示のための飾りのようなものだぜ(^~^)
	StartMovesNum int
	// 開始局面から数えて何手目か(^~^)0から始まるぜ(^~^)
	OffsetMovesIndex int
	// 指し手のリスト(^~^)
	// 1手目は[0]へ、512手目は[511]へ入れろだぜ(^~^)
	Moves [MOVES_SIZE]Move
	// 取った駒のリスト(^~^)アンドゥ ムーブするときに使うだけ(^~^)指し手のリストと同じ添え字を使うぜ(^~^)
	CapturedList [MOVES_SIZE]string
}

Position - 局面

func NewPosition

func NewPosition() *Position

func (*Position) AddControlDiff

func (pPos *Position) AddControlDiff(layer int, from Square, sign int8)

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

func (*Position) AddControlDiffAllSlidingPiece

func (pPos *Position) AddControlDiffAllSlidingPiece(layer int, sign int8, excludeFrom Square)

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

func (*Position) ClearControlDiff

func (pPos *Position) ClearControlDiff()

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

func (*Position) DoMove

func (pPos *Position) DoMove(move Move)

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

func (*Position) Hetero

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

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

func (*Position) Homo

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

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

func (*Position) IsEmptySq

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

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

func (*Position) MergeControlDiff

func (pPos *Position) MergeControlDiff()

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

func (*Position) ReadPosition

func (pPos *Position) ReadPosition(command string)

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

func (*Position) Sprint

func (pPos *Position) Sprint() string

Print - 局面出力(^q^)

func (*Position) SprintControl

func (pPos *Position) SprintControl(phase Phase, flag int) string

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

Parameters ---------- * `flag` - 0: 利き数ボード, 1-5:利き数の差分ボードのレイヤー[0]~[4]

func (*Position) SprintLocation

func (pPos *Position) SprintLocation() string

SprintLocation - あの駒どこにいんの?を表示

func (*Position) SprintRecord

func (pPos *Position) SprintRecord() string

SprintRecord - 棋譜表示(^~^)

func (*Position) SprintSfen

func (pPos *Position) SprintSfen() string

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

func (*Position) UndoMove

func (pPos *Position) UndoMove()

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

type Profile

type Profile struct {
	Name   string
	Author string
}

Profile - Profile 区画。

type Square

type Square uint32

マス番号 00~99,100~113

func File

func File(sq Square) Square

File - マス番号から筋(列)を取り出します

func GenControl

func GenControl(pPos *Position, from Square) []Square

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

func Rank

func Rank(sq Square) Square

Rank - マス番号から段(行)を取り出します

func SquareFrom

func SquareFrom(file Square, rank Square) Square

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

type Variables

type Variables struct {
	// Log - ロガー。
	Log l.Logger
	// Chat - チャッター。 標準出力とロガーを一緒にしただけです。
	Chat l.Chatter
	// StderrChat - チャッター。 標準エラー出力とロガーを一緒にしただけです。
	StderrChat l.StderrChatter
}

Variables - グローバル変数。

var G Variables

G - グローバル変数。思い切った名前。

Jump to

Keyboard shortcuts

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