0
0

More than 1 year has passed since last update.

目指せ!第14回UEC杯コンピューター囲碁大会<本編> Step [O11o_5o0] 石定義

Last updated at Posted at 2022-10-12

目指せ!第14回UEC杯コンピューター囲碁大会<本編> Step [O11o_5o0] 石定義

連載の目次

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

Step [O11o_5o0] 石定義

Step [O11o0] ファイル作成 - stone.go ファイル

👇 以下のファイルを新規作成してほしい

  	📂 kifuwarabe-uec14
	├── 📂 kernel
	│	├── 📄 go.mod
 	│	├── 📄 kernel.go
 	│	├── 📄 logger.go
👉 	│	└── 📄 stone.go
    ├── 📄 .gitignore
 	├── 📄 engine_config.go
  	├── 📄 engine.toml
    ├── 📄 go.mod
  	├── 📄 go.work
 	└── 📄 main.go
// BOF [O11o0]

package kernel

import "fmt"

// Stone - 石の色
type Stone uint

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

// GetStoneFromName - 文字列の名前を与えると、Stone値を返します
//
// Returns
// -------
// isOk : bool
// stone : Stone
func GetStoneFromName(stoneName string, getDefaultStone func() (bool, Stone)) (bool, Stone) {
	switch stoneName {
	case "space":
		return true, Stone_Space
	case "black":
		return true, Stone_Black
	case "white":
		return true, Stone_White
	case "wall":
		return true, Stone_Wall
	default:
		return getDefaultStone()
	}
}

// GetStoneOrDefaultFromTurn - black または white を与えると、Stone値を返します
//
// Returns
// -------
// stone : Stone
func GetStoneOrDefaultFromTurn(stoneName string, getDefaultStone func() Stone) Stone {
	switch stoneName {
	case "black":
		return Stone_Black
	case "white":
		return Stone_White
	default:
		return getDefaultStone()
	}
}

// GetStoneFromChar - 1文字与えると、Stone値を返します
//
// Returns
// -------
// isOk : bool
// stone : Stone
func GetStoneFromChar(stoneChar string, getDefaultStone func() (bool, Stone)) (bool, Stone) {
	switch stoneChar {
	case ".":
		return true, Stone_Space
	case "x":
		return true, Stone_Black
	case "o":
		return true, Stone_White
	case "+":
		return true, Stone_Wall
	default:
		return getDefaultStone()
	}
}

// String - 文字列化
func (s Stone) String() string {
	switch s {
	case Stone_Space:
		return "."
	case Stone_Black:
		return "x"
	case Stone_White:
		return "o"
	case Stone_Wall:
		return "+"
	default:
		panic(fmt.Sprintf("%d", int(s)))
	}
}

// GetColor - 色の取得
func (s Stone) GetColor() Color {
	switch s {
	case Stone_Space:
		return Color_None
	case Stone_Black:
		return Color_Black
	case Stone_White:
		return Color_White
	case Stone_Wall:
		return Color_None
	default:
		panic(fmt.Sprintf("%d", int(s)))
	}
}

// EOF [O11o0]

Step [O11o1o0] リモートリポジトリにプッシュ

がんばって git などを使い、 github.com/muzudho/kifuwarabe-uec14/kernel モジュールの各パッケージのソースを
リモートリポジトリにプッシュしてほしい

Step [O11o2o0] カレントディレクトリーを移動

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

cd kernel

Step [O11o3o0] tidy

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

Input:

go get -u
go mod tidy

Step [O11o4o0] カレントディレクトリーを戻す

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

cd ..

Step [O11o5o0] tidy

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

Input:

go mod tidy
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