12
14

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 5 years have passed since last update.

コンピュータ囲碁の作成

Last updated at Posted at 2016-05-03

#コンピュータ囲碁
コンピュータ囲碁の作成メモ。
今回は碁盤の作成のみ

#結果画像
スクリーンショット 2016-05-04 03.56.39.png

#ソースコード

# -*- coding:utf-8 -*-
# データ構造
KOMI = 6.5
BOARD_SIZE = 9				# 碁盤の大きさ
WIDTH_SIZE = BOARD_SIZE + 2 # 盤外を含めた碁盤の横幅 11
BOARD_MAX  = WIDTH_SIZE * WIDTH_SIZE # 121

WALL = 3	# 盤外

# 碁盤

board = [
		3,3,3,3,3,3,3,3,3,3,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,2,0,0,0,0,3,
		3,0,0,0,0,0,0,0,1,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,0,0,0,0,0,0,0,0,0,3,
		3,3,3,3,3,3,3,3,3,3,3,
		]

# board = [0 for i in range(0,BOARD_MAX)]
# 一行目を盤外にする
for i in range(0,WIDTH_SIZE):
	u_wall = i
	b_wall = BOARD_MAX - WIDTH_SIZE + i
	board[u_wall] = WALL
	board[b_wall] = WALL
for i in range(1,WIDTH_SIZE):
	l_wall = i*WIDTH_SIZE
	r_wall = l_wall+BOARD_SIZE+1
	board[l_wall] = WALL
	board[r_wall] = WALL


dir4 = {-1,1,+WIDTH_SIZE,-WIDTH_SIZE} # 右左上下への移動
hama = [0,0]
kifu = [0 for i in range(0,1000)]
ko_z = 0
all_playouts = 0

# (x,y)を1次元配列表記に変換 ただしx,y:0〜8
def get_z(x,y):
	return (x+1) + (y+1)*WIDTH_SIZE
# 上の逆
def get_x_y(z):
	return (z%WIDTH_SIZE,z/WIDTH_SIZE)

# 一次元配列を(x,y)に変換
def get81(z):
	if z==0:
		return 0
	y = z/WIDTH_SIZE
	x = z- y*WIDTH_SIZE
	return x*10+y

def flip_color(col):
	clo = 3 - col

storn = ["","🔴 ","⚪️ "]
def print_board():
	print " ",
	for x in range(1,BOARD_SIZE+1):
		print "%d " %x,
	print ""
	for y in range(0,BOARD_SIZE):
		print y+1,
		for x in range(0,BOARD_SIZE):
			print storn[board[get_z(x,y)]],
		print ""

print_board()

##github
https://github.com/Tsunehiko511/python_Go_origin

#参考図書
コンピュータ囲碁 ―モンテカルロ法の理論と実践―

12
14
3

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
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?