0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

目指せ!第14回UEC杯コンピューター囲碁大会<本編> Step [O13o_1o0] 盤表示

Last updated at Posted at 2022-10-12

目指せ!第14回UEC杯コンピューター囲碁大会<本編> Step [O13o_1o0] 盤表示

連載の目次

📖 目指せ!第14回UEC杯コンピューター囲碁大会<本編>

Step [O13o_1o0] 盤表示 - board コマンド

Step [O13o0] コマンド実装 - kernel.go ファイル

👇 以下の既存ファイルを編集してほしい

  	📂 kifuwarabe-uec14
	├── 📂 kernel
  	│	├── 📄 board_area.go
  	│	├── 📄 o12o__11o1o0_board.go
	│	├── 📄 go.mod
👉 	│	├── 📄 kernel.go
 	│	├── 📄 logger.go
 	│	└── 📄 stone.go
    ├── 📄 .gitignore
 	├── 📄 engine_config.go
  	├── 📄 engine.toml
    ├── 📄 go.mod
  	├── 📄 go.work
	└── 📄 main.go

👇 がんばって、 Execute メソッドに挿入してほしい

	// ...略...
	// この下にコマンドを挟んでいく
	// -------------------------

	case "board": // [O13o0]
		// 人間向けの出力
		{
			// 25列まで対応
			const fileSimbols = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
			// 25行まで対応
			var rankSimbols = strings.Split("  , 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25", ",")

			var filesMax = int(math.Min(25, float64(k.Position.Board.coordinate.GetWidth())))
			var rowsMax = int(math.Min(25, float64(k.Position.Board.coordinate.GetHeight())))
			var filesLabel = fileSimbols[:filesMax]

			var sb strings.Builder
			// 枠の上辺
			sb.WriteString(fmt.Sprintf(`= board:'''
.     %s
.    `, filesLabel))

			var rowNumber = 1
			var setPoint = func(point Point) {
				var stone = k.Position.Board.cells[point]
				sb.WriteString(fmt.Sprintf("%v", stone))
			}
			var doNewline = func() {
				var rankLabel string
				if rowNumber <= rowsMax {
					rankLabel = rankSimbols[rowNumber]
				} else {
					rankLabel = ""
				}

				sb.WriteString(fmt.Sprintf("\n. %2s ", rankLabel))
				rowNumber++
			}
			k.Position.Board.GetCoordinate().ForeachLikeText(setPoint, doNewline)
			sb.WriteString("\n. '''\n")
			logg.C.Info(sb.String())
		}
		// コンピューター向けの出力
		{
			var sb strings.Builder

			var setPoint = func(point Point) {
				var stone = k.Position.Board.cells[point]
				sb.WriteString(fmt.Sprintf("%v", stone))
			}
			var doNewline = func() {
				// pass
			}
			k.Position.Board.GetCoordinate().ForeachLikeText(setPoint, doNewline)
			logg.J.Infow("output", "board", sb.String())
		}
		return true

	// この上にコマンドを挟んでいく
	// -------------------------
	// ...略...

Step [O14o0] 動作確認

👇 以下のコマンドをコピーして、ターミナルに貼り付けてほしい

Input:

go run .

これで、思考エンジン内の入力待機ループに入った

👇 以下のコマンドをコピーして、ターミナルに貼り付けてほしい

Input:

board

Output > Console:

[2022-09-19 15:50:11]   # board
[2022-09-19 15:50:11]   = board:'''
.     ABCDEFGHJKLMNOPQRST
.    +++++++++++++++++++++
.  1 +...................+
.  2 +...................+
.  3 +...................+
.  4 +...................+
.  5 +...................+
.  6 +...................+
.  7 +...................+
.  8 +...................+
.  9 +...................+
. 10 +...................+
. 11 +...................+
. 12 +...................+
. 13 +...................+
. 14 +...................+
. 15 +...................+
. 16 +...................+
. 17 +...................+
. 18 +...................+
. 19 +...................+
.    +++++++++++++++++++++
. '''

👇 以下のファイルが自動生成された

  	📂 kifuwarabe-uec14
	├── 📂 kernel
  	│	├── 📄 board_area.go
  	│	├── 📄 o12o__11o1o0_board.go
	│	├── 📄 go.mod
 	│	├── 📄 kernel.go
 	│	├── 📄 logger.go
 	│	└── 📄 stone.go
    ├── 📄 .gitignore
 	├── 📄 engine_config.go
  	├── 📄 engine.toml
    ├── 📄 go.mod
  	├── 📄 go.work
👉 	├── 📄 kifuwarabe-uec14-json.log
👉 	├── 📄 kifuwarabe-uec14.log
  	└── 📄 main.go

👇 📄 kifuwarabe-uec14-json.log

{"level":"info","ts":"2022-09-11T19:04:58.192+0900","caller":"kifuwarabe-uec14/main.go:57","msg":"input","command":"board"}
{"level":"info","ts":"2022-09-11T19:04:58.195+0900","caller":"kifuwarabe-uec14/main.go:81","msg":"output","board":"++++++++++++++++++++++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++...................++++++++++++++++++++++"}

👇 📄 kifuwarabe-uec14.log

2022-09-11T19:04:58.157+0900	# board
2022-09-11T19:04:58.192+0900	= board:'''
. +++++++++++++++++++++
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +...................+
. +++++++++++++++++++++
. '''

quit コマンドで 思考エンジンを終了してほしい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?